org.activemath.abstractcontent
Class SubconfImpl.PropertiesConfig

java.lang.Object
  extended by org.activemath.abstractcontent.SubconfImpl.AbstractSubconfiguration
      extended by org.activemath.abstractcontent.SubconfImpl.PropertiesConfig
All Implemented Interfaces:
Subconfiguration
Enclosing class:
SubconfImpl

public static class SubconfImpl.PropertiesConfig
extends SubconfImpl.AbstractSubconfiguration

This class provides the subconfiguration facilities provided by a property file and to create services on a property-file based configuration.

It does so by assuming the following properties in the property file:

This class is not (yet) mutliple-threads aware. Special care should be taken in service initialization with respect to multiple-threads.


Nested Class Summary
static class SubconfImpl.PropertiesConfig.CyclicServiceInitException
          An exception denoting the imposibility to initialize services as an infite loop would result instead.
 
Field Summary
protected  Map services
          This map has, as keys, the interfaceName (as used in getService(java.lang.String)) and as values either the created service or a String object, the property child-name that defines the service, or this same name followed by " BEING INITTED" if it is being constructed, or a Throwable is the initialization of the service went wrong (it is attempted only once).
 
Constructor Summary
SubconfImpl.PropertiesConfig(Map props, SubconfImpl.PathResolver resolver)
          Creates a subconfiguration from an existing properties object and with the the indicated SubconfImpl.PathResolver.
SubconfImpl.PropertiesConfig(Map props, SubconfImpl.PathResolver resolver, Map services)
          Creates a subconfiguration from an existing properties object and with the the indicated SubconfImpl.PathResolver.
SubconfImpl.PropertiesConfig(URL url)
          Reads the property-file in memory and initializes the possibility to start the services but does not create them.
 
Method Summary
protected  void createService(String serviceInterfaceName)
          Constructs the service according to the indicated specifications.
 Collection getChildrenNames(String prefix)
          Returns the next step completion given the named prefix.
 URL getPath(String name)
          Returns a file constructed relative to the path of the url provided in the sole constructor.
 String getProperty(String name)
          Returns the values for the given name or null if there's none.
 Iterator getPropertyNames()
          Returns an enumeration of all the property names.
 Object getService(String serviceInterfaceName)
          This is the way to provide named services to users of the subconfiguation.
 URL getURL(String keyName)
          Returns the URL relative to the baseURL provided at construction time provided by the property-value whose key is the given name, or null if there is no such key.
 URL pathFromString(String pathString)
          Computes the path for the obtained property value.
 void refreshServices()
          Commodity method to request the configurator to re-read the services from whichever source it was given.
 void setDefaultProperties(Map defaultProps)
          Expects a map with keys and values as Strings.
 void unload()
          Unloads the probably expensive storage of the properties.
 
Methods inherited from class org.activemath.abstractcontent.SubconfImpl.AbstractSubconfiguration
getBoolean, getInt, getSubconfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

services

protected final Map services
This map has, as keys, the interfaceName (as used in getService(java.lang.String)) and as values either the created service or a String object, the property child-name that defines the service, or this same name followed by " BEING INITTED" if it is being constructed, or a Throwable is the initialization of the service went wrong (it is attempted only once).

Constructor Detail

SubconfImpl.PropertiesConfig

public SubconfImpl.PropertiesConfig(URL url)
                             throws IOException
Reads the property-file in memory and initializes the possibility to start the services but does not create them.

Throws:
IOException

SubconfImpl.PropertiesConfig

public SubconfImpl.PropertiesConfig(Map props,
                                    SubconfImpl.PathResolver resolver)
Creates a subconfiguration from an existing properties object and with the the indicated SubconfImpl.PathResolver. Services are created using the same approach.

See Also:
SubconfImpl.Util.makeBasedPathResolver(java.net.URL)

SubconfImpl.PropertiesConfig

public SubconfImpl.PropertiesConfig(Map props,
                                    SubconfImpl.PathResolver resolver,
                                    Map services)
Creates a subconfiguration from an existing properties object and with the the indicated SubconfImpl.PathResolver. Services are created using the same approach except if they are already defined in the services parameter where they will be simply fetched (and not checked). Do note that a service (i.e. a value in the services table) is not allowed to be a String object.

See Also:
SubconfImpl.Util.makeBasedPathResolver(java.net.URL)
Method Detail

getURL

public URL getURL(String keyName)
Returns the URL relative to the baseURL provided at construction time provided by the property-value whose key is the given name, or null if there is no such key.


refreshServices

public void refreshServices()
Description copied from interface: Subconfiguration
Commodity method to request the configurator to re-read the services from whichever source it was given. Useful for services created, e.g., from system-properties after a preference update. Implementations are not required to provide this service but should not fail if they don't.

Specified by:
refreshServices in interface Subconfiguration

createService

protected void createService(String serviceInterfaceName)
Constructs the service according to the indicated specifications. Note that, a service being constructed with a Subconfiguration may request another service which may give rise to cycles. In this case, a SubconfImpl.PropertiesConfig.CyclicServiceInitException will be thrown.


getService

public Object getService(String serviceInterfaceName)
Description copied from interface: Subconfiguration
This is the way to provide named services to users of the subconfiguation. Implementations using the Subconfiguraiton interface should document the class-name of the interfaces expected to be called using this method thereby documenting the necessary services.

Note that implementations of the Subconfiguration interface should only accept, as argument of this method, the class of a java-interface.

The service returned is not supposed to be twiddled or adjusted by the user of this service as such a service will presumably be shared by several users in a normal deployment.

Examples of such services could be an implementation of the JAXP's TransformerFactory interface, or an implementation of the MBaseRef interface.

Child-subconfigurations obtained through Subconfiguration.getSubconfiguration(java.lang.String) should, so as to enforce the inversion-of-control pattern, restrict the amount of services provided to the strict needed parts.

Specified by:
getService in interface Subconfiguration
Returns:
an object of a class implementing the service-interface-class.
See Also:
SubconfImpl.PropertiesConfig

getProperty

public String getProperty(String name)
Description copied from interface: Subconfiguration
Returns the values for the given name or null if there's none.

Specified by:
getProperty in interface Subconfiguration
Specified by:
getProperty in class SubconfImpl.AbstractSubconfiguration

setDefaultProperties

public void setDefaultProperties(Map defaultProps)
Expects a map with keys and values as Strings.

Specified by:
setDefaultProperties in interface Subconfiguration
Specified by:
setDefaultProperties in class SubconfImpl.AbstractSubconfiguration

getPropertyNames

public Iterator getPropertyNames()
Description copied from interface: Subconfiguration
Returns an enumeration of all the property names.

Specified by:
getPropertyNames in interface Subconfiguration
Specified by:
getPropertyNames in class SubconfImpl.AbstractSubconfiguration

getChildrenNames

public Collection getChildrenNames(String prefix)
Description copied from interface: Subconfiguration
Returns the next step completion given the named prefix.

As an example, given

    i.a.blop.c = val1
i.b.blip = val2

This method, called with "i", would return the enumeration made of the string "a" and the string "b".

Specified by:
getChildrenNames in interface Subconfiguration
Specified by:
getChildrenNames in class SubconfImpl.AbstractSubconfiguration
Parameters:
prefix - the prefix string, without the trailing "." or null if the root property names is wished.

unload

public void unload()
Unloads the probably expensive storage of the properties. Any further call to other methods of this class will result in a NullPointerException.


getPath

public URL getPath(String name)
Returns a file constructed relative to the path of the url provided in the sole constructor. Note that, in the case of a remote-host URL (e.g. an http URL), most of the methods of this File object will make no-sense.

For this reason, it is preferable, in a setting where remote communication at configuration time may happen to call getURL(java.lang.String).

Specified by:
getPath in interface Subconfiguration
Specified by:
getPath in class SubconfImpl.AbstractSubconfiguration
See Also:
Manager.getPath(java.lang.String)

pathFromString

public URL pathFromString(String pathString)
Description copied from interface: Subconfiguration
Computes the path for the obtained property value.