org.jpu.patterns.factory
Class PropertyFactoryConfigStrategy

java.lang.Object
  extended byorg.jpu.patterns.factory.PropertyFactoryConfigStrategy
All Implemented Interfaces:
IPrototypeFactory.IConfigStrategy

public class PropertyFactoryConfigStrategy
extends java.lang.Object
implements IPrototypeFactory.IConfigStrategy

Implementation of IPrototypeFactory.IConfigStrategy for property-file-based configuration. A prototype list should comply with the following syntax:

    <protolist> = [<protospec>{;<protospec>}*]
    <protospec> = [<name1>[,<name2>[,<name3>[,<nameN>]]]=<classname>]
 
where <name1> ... <nameN> are the names under which the prototype is keyed and <classname> is the full name of the prototype implementation class, or of the IPrototypeFactory.IInstantiator to which instantiation should be delegated. Every class listed must have an accessible no-arg constructor.

The source of the <protospec> is by default a System property named "<factoryClassName>.prototypes" where <factoryClassName> is the full class name of the factory being configured; but in the vast majority of cases the subclass will override the following method

 
     protected String fetchPrototypeSpec();
 
 
and have it return the <protospec> from whichever configuration source the application employs.

To specify a delimeter to use instead of ";", override the following method:

 
     protected String getPrototypeDeclarationSeparator();
 
 


Constructor Summary
protected PropertyFactoryConfigStrategy(IPrototypeFactory fact)
           
 
Method Summary
protected  java.lang.Object classNameToInstance(java.lang.String className)
          Returns a new instance of the prototype whose name is passed.
 void configure()
           
protected  java.lang.String fetchPrototypeSpec()
          This method fetches the factory's prototype list from the configuration source.
protected  java.lang.String getAssignmentString()
          Returns the string that acts as a separator between the list of prototype names and the name of the prototype class.
 IPrototypeFactory getFactory()
           
protected  java.lang.String getFallbackPrototypeSpec()
          Returns the prototype spec that is used if none is found in the configuration database.
protected  java.lang.String getPrototypeDeclarationSeparator()
          Returns the string that acts as a separator between <protospec>'s.
protected  java.lang.String getPrototypeNameSeparator()
          Returns the string that acts as a separator between successive prototype names.
protected  java.lang.String getPrototypeSpec()
           
protected  boolean logErrorIfConfigurationUnavailable()
          Returns whether an error is logged if the default configuration value is unavailable and the fallback is used in its place.
protected  void processOneConfigProtoDef(java.lang.String protoDef)
          Processes a single prototype declaration.
 void reconfigureIfNecessary()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyFactoryConfigStrategy

protected PropertyFactoryConfigStrategy(IPrototypeFactory fact)
Method Detail

getFactory

public IPrototypeFactory getFactory()
Specified by:
getFactory in interface IPrototypeFactory.IConfigStrategy

reconfigureIfNecessary

public void reconfigureIfNecessary()
Specified by:
reconfigureIfNecessary in interface IPrototypeFactory.IConfigStrategy

configure

public void configure()
Specified by:
configure in interface IPrototypeFactory.IConfigStrategy

logErrorIfConfigurationUnavailable

protected boolean logErrorIfConfigurationUnavailable()
Returns whether an error is logged if the default configuration value is unavailable and the fallback is used in its place. Default is true, but subclasses are free to override.

Returns:
true if an error should be logged, false otherwise.

getFallbackPrototypeSpec

protected java.lang.String getFallbackPrototypeSpec()
Returns the prototype spec that is used if none is found in the configuration database. Default is null, but subclasses are free to override.

Returns:
The fallback configuration (null by default).

getPrototypeDeclarationSeparator

protected java.lang.String getPrototypeDeclarationSeparator()
Returns the string that acts as a separator between <protospec>'s. Default is ";", but subclasses are free to override.


getPrototypeNameSeparator

protected java.lang.String getPrototypeNameSeparator()
Returns the string that acts as a separator between successive prototype names. Default is ",", but subclasses are free to override.


getAssignmentString

protected java.lang.String getAssignmentString()
Returns the string that acts as a separator between the list of prototype names and the name of the prototype class. Default is "=", but subclasses are free to override.


processOneConfigProtoDef

protected void processOneConfigProtoDef(java.lang.String protoDef)
Processes a single prototype declaration. Adds prototypes to the factory as necessary.


classNameToInstance

protected java.lang.Object classNameToInstance(java.lang.String className)
                                        throws java.lang.Throwable
Returns a new instance of the prototype whose name is passed. Default implementation is essentially "Thread.currentThread().getContextClassLoader().loadClass(className).newInstance()", but subclasses are free to override.

Throws:
java.lang.Throwable

getPrototypeSpec

protected java.lang.String getPrototypeSpec()

fetchPrototypeSpec

protected java.lang.String fetchPrototypeSpec()
This method fetches the factory's prototype list from the configuration source. The default implementation is as follows:
 
     return System.getProperty( getFactory().getClass().getName() + ".prototypes", "" );
 
 
However, in the majority of cases the subclass will override this to hook into whichever configuration source the application uses.



Copyright (c) 2001-2003 - Apache Software Foundation