org.apache.ode.utils
Class HierarchicalProperties
java.lang.Object
org.apache.ode.utils.HierarchicalProperties
public class HierarchicalProperties
- extends java.lang.Object
This class load a regular property file in Properties
instance. 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:
timeout=40000
film-service.port-of-cannes.ode.timeout=50000
max-redirects=30
brel-service.ode.max-redirects=40
brel-service.port-of-amsterdam.ode.max-redirects=60
The following values may be expected:
getProperty("max-redirects") => 30
getProperty("brel-service", "max-redirects") => 40
getProperty("brel-service", "port-of-amsterdam", "max-redirects") => 60
getProperty("film-service", "timeout") => 40000
getProperty("film-service", "port-of-cannes", "timeout") => 50000
getProperty("brel-service", "port-of-amsterdam", "timeout") => 40000
Values may contain some environment variables. For instance, message=You're using ${java.version}.
This class is not thread-safe.
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()
|
void |
loadFile()
Clear all existing content, 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 |
ODE_PREFFIX
public static final java.lang.String ODE_PREFFIX
- See Also:
- Constant Field Values
HierarchicalProperties
public HierarchicalProperties(java.io.File file,
java.lang.String prefix)
throws java.io.IOException
- Parameters:
file
- 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 file)
throws java.io.IOException
- Throws:
java.io.IOException
loadFile
public void loadFile()
throws java.io.IOException
- Clear all existing content, 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
clear
public void clear()
- Clear all content. If
loadFile()
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()