org.apache.ode.utils
Class HierarchicalProperties

java.lang.Object
  extended by org.apache.ode.utils.HierarchicalProperties

public class HierarchicalProperties
extends java.lang.Object

This class load a list of regular property files (order matters). The main feature is that property can be chained in three levels. Then when querying for a property, if it's not found in the deepest level, the parent will be queryed and so on.

A prefix must be defined to discriminate the property name and the level-1, level-2 names. The default prefix is ODE_PREFFIX.

Properties must respect the following pattern: [level1.[level2.]prefix.]property

A concrete use case could be the definition of properties for wsdl services and ports.
Level 0 would be: values common to all services and ports.
Level 1: values common to a given service.
Level 2: values common to a given port.

For instance, if the property file looks like this:

alias.foo_ns=http://foo.com

 timeout=40000
 a_namespace_with_no_alias_defined.film-service.port-of-cannes.ode.timeout=50000
 

max-redirects=30 foo_ns.brel-service.ode.max-redirects=40 foo_ns.brel-service.port-of-amsterdam.ode.max-redirects=60

The following values may be expected:
 getProperty("max-redirects")                                                         => 30
 getProperty("http://foo.com", "brel-service", "max-redirects")                       => 40
 getProperty("http://foo.com", "brel-service", "port-of-amsterdam", "max-redirects")  => 60
 

getProperty("a_namespace_with_no_alias_defined", "film-service", "timeout") => 40000 getProperty("a_namespace_with_no_alias_defined", "film-service", "port-of-cannes", "timeout") => 50000 getProperty("http://foo.com", "port-of-amsterdam", "timeout") => 40000

Values may contain some environment variables. For instance, message=You're using ${java.version}.

If a property name ends with ".file" or ".path", the assumption is made that the associated value is a path and as such is resolved against the path of the file it was loaded from.

This class is not thread-safe.


Field Summary
static java.lang.String ODE_PREFFIX
           
 
Constructor Summary
HierarchicalProperties(java.io.File file)
           
HierarchicalProperties(java.io.File[] files)
           
HierarchicalProperties(java.io.File[] files, java.lang.String prefix)
           
HierarchicalProperties(java.io.File file, java.lang.String prefix)
           
HierarchicalProperties(java.util.List<java.io.File> propFiles)
           
 
Method Summary
 void clear()
          Clear all content.
 java.lang.String getPrefix()
           
 java.util.Map getProperties(javax.xml.namespace.QName service)
           
 java.util.Map getProperties(javax.xml.namespace.QName service, java.lang.String port)
          Return a map containing all the properties for the given port.
 java.util.Map getProperties(java.lang.String serviceNamespaceURI, java.lang.String serviceLocalPart)
           
 java.util.Map getProperties(java.lang.String serviceNamespaceURI, java.lang.String serviceLocalPart, java.lang.String port)
           
 java.lang.String getProperty(javax.xml.namespace.QName service, java.lang.String property)
           
 java.lang.String getProperty(javax.xml.namespace.QName service, java.lang.String port, java.lang.String property)
           
 java.lang.String getProperty(java.lang.String property)
           
 java.lang.String getProperty(java.lang.String serviceNamespaceURI, java.lang.String serviceLocalPart, java.lang.String property)
           
 java.lang.String getProperty(java.lang.String serviceNamespaceURI, java.lang.String serviceLocalPart, java.lang.String port, java.lang.String property)
           
protected  org.apache.ode.utils.HierarchicalProperties.ChainedMap getRootMap()
           
protected  void loadFile(java.io.File file)
           
 void loadFiles()
          Clear all existing content, then read the file and parse each property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ODE_PREFFIX

public static final java.lang.String ODE_PREFFIX
See Also:
Constant Field Values
Constructor Detail

HierarchicalProperties

public HierarchicalProperties(java.io.File[] files,
                              java.lang.String prefix)
                       throws java.io.IOException
Parameters:
files - the property file to be loaded. The file may not exist. But if the file exists it has to be a file (not a directory), otherwhise an IOException is thrown.
prefix - the property prefix
Throws:
java.io.IOException

HierarchicalProperties

public HierarchicalProperties(java.io.File[] files)
                       throws java.io.IOException
Throws:
java.io.IOException

HierarchicalProperties

public HierarchicalProperties(java.io.File file,
                              java.lang.String prefix)
                       throws java.io.IOException
Throws:
java.io.IOException

HierarchicalProperties

public HierarchicalProperties(java.io.File file)
                       throws java.io.IOException
Throws:
java.io.IOException

HierarchicalProperties

public HierarchicalProperties(java.util.List<java.io.File> propFiles)
                       throws java.io.IOException
Throws:
java.io.IOException
Method Detail

loadFiles

public void loadFiles()
               throws java.io.IOException
Clear all existing content, then read the file and parse each property. Simply logs a message and returns if the file does not exist.

Throws:
java.io.IOException - if the file is a Directory

loadFile

protected void loadFile(java.io.File file)
                 throws java.io.IOException
Throws:
java.io.IOException

clear

public void clear()
Clear all content. If loadFiles() is not invoked later, all returned values will be null.


getRootMap

protected org.apache.ode.utils.HierarchicalProperties.ChainedMap getRootMap()

getProperties

public java.util.Map getProperties(java.lang.String serviceNamespaceURI,
                                   java.lang.String serviceLocalPart)

getProperties

public java.util.Map getProperties(javax.xml.namespace.QName service)
Parameters:
service -
Returns:
a map containing all the properties for the given service.
See Also:
getProperties(String, String)

getProperties

public java.util.Map getProperties(java.lang.String serviceNamespaceURI,
                                   java.lang.String serviceLocalPart,
                                   java.lang.String port)

getProperties

public java.util.Map getProperties(javax.xml.namespace.QName service,
                                   java.lang.String port)
Return a map containing all the properties for the given port. The map is an immutable snapshot of the properties. Meaning that futur changes to the properties will NOT be reflected in the returned map.

Parameters:
service -
port -
Returns:
a map containing all the properties for the given port

getProperty

public java.lang.String getProperty(java.lang.String property)

getProperty

public java.lang.String getProperty(java.lang.String serviceNamespaceURI,
                                    java.lang.String serviceLocalPart,
                                    java.lang.String property)

getProperty

public java.lang.String getProperty(javax.xml.namespace.QName service,
                                    java.lang.String property)

getProperty

public java.lang.String getProperty(java.lang.String serviceNamespaceURI,
                                    java.lang.String serviceLocalPart,
                                    java.lang.String port,
                                    java.lang.String property)

getProperty

public java.lang.String getProperty(javax.xml.namespace.QName service,
                                    java.lang.String port,
                                    java.lang.String property)

getPrefix

public java.lang.String getPrefix()