Java Doc for HierarchicalConfiguration.java in  » Forum » mvnforum-1.1 » net » myvietnam » mvncore » configuration » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Forum » mvnforum 1.1 » net.myvietnam.mvncore.configuration 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.myvietnam.mvncore.configuration.AbstractConfiguration
      net.myvietnam.mvncore.configuration.HierarchicalConfiguration

All known Subclasses:   net.myvietnam.mvncore.configuration.HierarchicalDOM4JConfiguration,
HierarchicalConfiguration
public class HierarchicalConfiguration extends AbstractConfiguration (Code)

A specialized configuration class that extends its base class by the ability of keeping more structure in the stored properties.

There are some sources of configuration data that cannot be stored very well in a BaseConfiguration object because then their structure is lost. This is especially true for XML documents. This class can deal with such structured configuration sources by storing the properties in a tree-like organization.

The internal used storage form allows for a more sophisticated access to single properties. As an example consider the following XML document:

 <database>
 <tables>
 <table>
 <name>users</name>
 <fields>
 <field>
 <name>lid</name>
 <type>long</name>
 </field>
 <field>
 <name>usrName</name>
 <type>java.lang.String</type>
 </field>
 ...
 </fields>
 </table>
 <table>
 <name>documents</name>
 <fields>
 <field>
 <name>docid</name>
 <type>long</type>
 </field>
 ...
 </fields>
 </table>
 ...
 </tables>
 </database>
 

If this document is parsed and stored in a HierarchicalConfiguration object (which can be done by one of the sub classes), there are enhanced possibilities of accessing properties. The keys for querying information can contain indices that select a certain element if there are multiple hits.

For instance the key tables.table(0).name can be used to find out the name of the first table. In opposite tables.table.name would return a collection with the names of all available tables. Similarily the key tables.table(1).fields.field.name returns a collection with the names of all fields of the second table. If another index is added after the field element, a single field can be accessed: tables.table(1).fields.field(0).name.

There is a getMaxIndex() method that returns the maximum allowed index that can be added to a given property key. This method can be used to iterate over all values defined for a certain property.


author:
   Oliver Heger
version:
   $Id: HierarchicalConfiguration.java,v 1.3 2006/10/26 08:30:35 minhnn Exp $

Inner Class :public static class Node implements Serializable,Cloneable
Inner Class :public static class NodeVisitor
Inner Class :static class DefinedVisitor extends NodeVisitor
Inner Class :static class DefinedKeysVisitor extends NodeVisitor
Inner Class :static class CloneVisitor extends NodeVisitor


Constructor Summary
public  HierarchicalConfiguration()
     Creates a new instance of HierarchicalConfiguration.
public  HierarchicalConfiguration(Configuration defaults)
     Creates a new instance of HierarchicalConfiguration and initializes it with default properties.

Method Summary
public  voidaddNodes(String key, Collection nodes)
     Adds a collection of nodes at the specified position of the configuration tree.
protected  voidaddPropertyDirect(String key, Object obj)
    

Adds the property with the specified key.

To be able to deal with the structure supported by this configuration implementation the passed in key is of importance, especially the indices it might contain.

public  voidclearProperty(String key)
     Removes all values of the property with the given name.
public  booleancontainsKey(String key)
     Checks if the specified key is contained in this configuration. Note that for this configuration the term "contained" means that the key has an associated value.
protected  NodecreateAddPath(ConfigurationKey.KeyIterator keyIt, Node root)
     Creates the missing nodes for adding a new property.
protected  NodefetchAddNode(ConfigurationKey.KeyIterator keyIt, Node startNode)
     Returns a reference to the parent node of an add operation.
protected  ListfetchNodeList(String key)
     Helper method for fetching a list of all nodes that are addressed by the specified key.
protected  NodefindLastPathNode(ConfigurationKey.KeyIterator keyIt, Node node)
     Finds the last existing node for an add operation.
protected  voidfindPropertyNodes(ConfigurationKey.KeyIterator keyPart, Node node, Collection data)
     Recursive helper method for fetching a property.
public  IteratorgetKeys()
    

Returns an iterator with all keys defined in this configuration.

Note that the keys returned by this method will not contain any indices.

public  intgetMaxIndex(String key)
     Returns the maximum defined index for the given key.
protected  ObjectgetPropertyDirect(String key)
     Fetches the specified property.
public  NodegetRoot()
     Returns the root node of this hierarchical configuration.
public  booleanisEmpty()
     Checks if this configuration is empty.
protected  booleannodeDefined(Node node)
     Checks if the specified node is defined.
protected  voidremoveNode(Node node)
     Removes the specified node from this configuration.
public  voidsetRoot(Node node)
     Sets the root node of this hierarchical configuration.
public  Configurationsubset(String prefix)
     Creates a new Configuration object containing all keys that start with the specified prefix.


Constructor Detail
HierarchicalConfiguration
public HierarchicalConfiguration()(Code)
Creates a new instance of HierarchicalConfiguration.



HierarchicalConfiguration
public HierarchicalConfiguration(Configuration defaults)(Code)
Creates a new instance of HierarchicalConfiguration and initializes it with default properties.
Parameters:
  defaults - default properties to be used




Method Detail
addNodes
public void addNodes(String key, Collection nodes)(Code)
Adds a collection of nodes at the specified position of the configuration tree. This method works similar to addProperty(), but instead of a single property a whole collection of nodes can be added - and thus complete configuration sub trees. E.g. with this method it is possible to add parts of another HierarchicalConfiguration object to this object.
Parameters:
  key - the key where the nodes are to be added; can be null,then they are added to the root node
Parameters:
  nodes - a collection with the Node objects to beadded



addPropertyDirect
protected void addPropertyDirect(String key, Object obj)(Code)

Adds the property with the specified key.

To be able to deal with the structure supported by this configuration implementation the passed in key is of importance, especially the indices it might contain. The following example should clearify this: Suppose the actual configuration contains the following elements:

 tables
 +-- table
 +-- name = user
 +-- fields
 +-- field
 +-- name = uid
 +-- field
 +-- name = firstName
 ...
 +-- table
 +-- name = documents
 +-- fields
 ...
 

In this example a database structure is defined, e.g. all fields of the first table could be accessed using the key tables.table(0).fields.field.name. If now properties are to be added, it must be exactly specified at which position in the hierarchy the new property is to be inserted. So to add a new field name to a table it is not enough to say just

 config.addProperty("tables.table.fields.field.name", "newField");
 

The statement given above contains some ambiguity. For instance it is not clear, to which table the new field should be added. If this method finds such an ambiguity, it is resolved by following the last valid path. Here this would be the last table. The same is true for the field; because there are multiple fields and no explicit index is provided, a new name property would be added to the last field - which is propably not what was desired.

To make things clear explicit indices should be provided whenever possible. In the example above the exact table could be specified by providing an index for the table element as in tables.table(1).fields. By specifying an index it can also be expressed that at a given position in the configuration tree a new branch should be added. In the example above we did not want to add an additional name element to the last field of the table, but we want a complete new field element. This can be achieved by specifying an invalid index (like -1) after the element where a new branch should be created. Given this our example would run:

 config.addProperty("tables.table(1).fields.field(-1).name", "newField");
 

With this notation it is possible to add new branches everywhere. We could for instance create a new table element by specifying

 config.addProperty("tables.table(-1).fields.field.name", "newField2");
 

(Note that because after the table element a new branch is created indices in following elements are not relevant; the branch is new so there cannot be any ambiguities.)


Parameters:
  key - the key of the new property
Parameters:
  obj - the value of the new property



clearProperty
public void clearProperty(String key)(Code)
Removes all values of the property with the given name.
Parameters:
  key - the key of the property to be removed



containsKey
public boolean containsKey(String key)(Code)
Checks if the specified key is contained in this configuration. Note that for this configuration the term "contained" means that the key has an associated value. If there is a node for this key that has no value but children (either defined or undefined), this method will still return false.
Parameters:
  key - the key to be chekced a flag if this key is contained in this configuration



createAddPath
protected Node createAddPath(ConfigurationKey.KeyIterator keyIt, Node root)(Code)
Creates the missing nodes for adding a new property. This method ensures that there are corresponding nodes for all components of the specified configuration key.
Parameters:
  keyIt - the key iterator
Parameters:
  root - the base node of the path to be created the last node of the path



fetchAddNode
protected Node fetchAddNode(ConfigurationKey.KeyIterator keyIt, Node startNode)(Code)
Returns a reference to the parent node of an add operation. Nodes for new properties can be added as children of this node. If the path for the specified key does not exist so far, it is created now.
Parameters:
  keyIt - the iterator for the key of the new property
Parameters:
  startNode - the node to start the search with the parent node for the add operation



fetchNodeList
protected List fetchNodeList(String key)(Code)
Helper method for fetching a list of all nodes that are addressed by the specified key.
Parameters:
  key - the key a list with all affected nodes (never null)



findLastPathNode
protected Node findLastPathNode(ConfigurationKey.KeyIterator keyIt, Node node)(Code)
Finds the last existing node for an add operation. This method traverses the configuration tree along the specified key. The last existing node on this path is returned.
Parameters:
  keyIt - the key iterator
Parameters:
  node - the actual node the last existing node on the given path



findPropertyNodes
protected void findPropertyNodes(ConfigurationKey.KeyIterator keyPart, Node node, Collection data)(Code)
Recursive helper method for fetching a property. This method processes all facets of a configuration key, traverses the tree of properties and fetches the the nodes of all matching properties.
Parameters:
  keyPart - the configuration key iterator
Parameters:
  node - the actual node
Parameters:
  data - here the found nodes are stored



getKeys
public Iterator getKeys()(Code)

Returns an iterator with all keys defined in this configuration.

Note that the keys returned by this method will not contain any indices. This means that some structure will be lost.

an iterator with the defined keys in this configuration



getMaxIndex
public int getMaxIndex(String key)(Code)
Returns the maximum defined index for the given key. This is useful if there are multiple values for this key. They can then be addressed separately by specifying indices from 0 to the return value of this method.
Parameters:
  key - the key to be checked the maximum defined index for this key



getPropertyDirect
protected Object getPropertyDirect(String key)(Code)
Fetches the specified property. Performs a recursive lookup in the tree with the configuration properties.
Parameters:
  key - the key to be looked up the found value



getRoot
public Node getRoot()(Code)
Returns the root node of this hierarchical configuration. the root node



isEmpty
public boolean isEmpty()(Code)
Checks if this configuration is empty. Empty means that there are no keys with any values, though there can be some (empty) nodes. a flag if this configuration is empty



nodeDefined
protected boolean nodeDefined(Node node)(Code)
Checks if the specified node is defined.
Parameters:
  node - the node to be checked a flag if this node is defined



removeNode
protected void removeNode(Node node)(Code)
Removes the specified node from this configuration. This method ensures that parent nodes that become undefined by this operation are also removed.
Parameters:
  node - the node to be removed



setRoot
public void setRoot(Node node)(Code)
Sets the root node of this hierarchical configuration.
Parameters:
  node - the root node



subset
public Configuration subset(String prefix)(Code)
Creates a new Configuration object containing all keys that start with the specified prefix. This implementation will return a HierarchicalConfiguration object so that the structure of the keys will be saved.
Parameters:
  prefix - the prefix of the keys for the subset a new configuration object representing the selected subset



Fields inherited from net.myvietnam.mvncore.configuration.AbstractConfiguration
final protected static String END_TOKEN(Code)(Java Doc)
final protected static String START_TOKEN(Code)(Java Doc)
protected Configuration defaults(Code)(Java Doc)

Methods inherited from net.myvietnam.mvncore.configuration.AbstractConfiguration
public void addProperty(String key, Object token)(Code)(Java Doc)
abstract protected void addPropertyDirect(String key, Object obj)(Code)(Java Doc)
abstract public void clearProperty(String key)(Code)(Java Doc)
abstract public boolean containsKey(String key)(Code)(Java Doc)
public boolean getBoolean(String key)(Code)(Java Doc)
public boolean getBoolean(String key, boolean defaultValue)(Code)(Java Doc)
public Boolean getBoolean(String key, Boolean defaultValue)(Code)(Java Doc)
public byte getByte(String key)(Code)(Java Doc)
public byte getByte(String key, byte defaultValue)(Code)(Java Doc)
public Byte getByte(String key, Byte defaultValue)(Code)(Java Doc)
public double getDouble(String key)(Code)(Java Doc)
public double getDouble(String key, double defaultValue)(Code)(Java Doc)
public Double getDouble(String key, Double defaultValue)(Code)(Java Doc)
public float getFloat(String key)(Code)(Java Doc)
public float getFloat(String key, float defaultValue)(Code)(Java Doc)
public Float getFloat(String key, Float defaultValue)(Code)(Java Doc)
public int getInt(String key)(Code)(Java Doc)
public int getInt(String key, int defaultValue)(Code)(Java Doc)
public Integer getInteger(String key, Integer defaultValue)(Code)(Java Doc)
abstract public Iterator getKeys()(Code)(Java Doc)
public Iterator getKeys(String prefix)(Code)(Java Doc)
public long getLong(String key)(Code)(Java Doc)
public long getLong(String key, long defaultValue)(Code)(Java Doc)
public Long getLong(String key, Long defaultValue)(Code)(Java Doc)
public Properties getProperties(String key)(Code)(Java Doc)
public Properties getProperties(String key, Properties defaults)(Code)(Java Doc)
public Object getProperty(String key)(Code)(Java Doc)
abstract protected Object getPropertyDirect(String key)(Code)(Java Doc)
public short getShort(String key)(Code)(Java Doc)
public short getShort(String key, short defaultValue)(Code)(Java Doc)
public Short getShort(String key, Short defaultValue)(Code)(Java Doc)
public String getString(String key)(Code)(Java Doc)
public String getString(String key, String defaultValue)(Code)(Java Doc)
public String[] getStringArray(String key)(Code)(Java Doc)
public Vector getVector(String key)(Code)(Java Doc)
public Vector getVector(String key, Vector defaultValue)(Code)(Java Doc)
protected String interpolate(String base)(Code)(Java Doc)
protected String interpolateHelper(String base, List priorVariables)(Code)(Java Doc)
abstract public boolean isEmpty()(Code)(Java Doc)
protected List processString(String token)(Code)(Java Doc)
public void setProperty(String key, Object value)(Code)(Java Doc)
public Configuration subset(String prefix)(Code)(Java Doc)
final protected Boolean testBoolean(String value)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.