Java Doc for DefaultExpressionEngine.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » tree » 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 » Library » Apache commons configuration 1.4 src » org.apache.commons.configuration.tree 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.configuration.tree.DefaultExpressionEngine

DefaultExpressionEngine
public class DefaultExpressionEngine implements ExpressionEngine(Code)

A default implementation of the ExpressionEngine interface providing the "native"e; expression language for hierarchical configurations.

This class implements a rather simple expression language for navigating through a hierarchy of configuration nodes. It supports the following operations:

  • Navigating from a node to one of its children using the child node delimiter, which is by the default a dot (".").
  • Navigating from a node to one of its attributes using the attribute node delimiter, which by default follows the XPATH like syntax [@<attributeName>].
  • If there are multiple child or attribute nodes with the same name, a specific node can be selected using a numerical index. By default indices are written in paranthesis.

As an example consider the following XML document:

 <database>
 <tables>
 <table type="system">
 <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 hierarchical configuration object, 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. The key tables.table(0)[@type] would select the type attribute of the first table.

This example works with the default values for delimiters and index markers. It is also possible to set custom values for these properties so that you can adapt a DefaultExpressionEngine to your personal needs.


since:
   1.3
author:
   Oliver Heger
version:
   $Id: DefaultExpressionEngine.java 439648 2006-09-02 20:42:10Z oheger $


Field Summary
final public static  StringDEFAULT_ATTRIBUTE_END
     Constant for the default attribute end marker.
final public static  StringDEFAULT_ATTRIBUTE_START
     Constant for the default attribute start marker.
final public static  StringDEFAULT_ESCAPED_DELIMITER
     Constant for the default escaped property delimiter.
final public static  StringDEFAULT_INDEX_END
     Constant for the default index end marker.
final public static  StringDEFAULT_INDEX_START
     Constant for the default index start marker.
final public static  StringDEFAULT_PROPERTY_DELIMITER
     Constant for the default property delimiter.


Method Summary
protected  ConfigurationNodefindLastPathNode(DefaultConfigurationKey.KeyIterator keyIt, ConfigurationNode node)
     Finds the last existing node for an add operation.
protected  voidfindNodesForKey(DefaultConfigurationKey.KeyIterator keyPart, ConfigurationNode node, Collection nodes)
     Recursive helper method for evaluating a key.
public  StringgetAttributeEnd()
     Sets the attribute end marker.
public  StringgetAttributeStart()
     Returns the attribute start marker.
public  StringgetEscapedDelimiter()
     Returns the escaped property delimiter string.
public  StringgetIndexEnd()
     Returns the index end marker.
public  StringgetIndexStart()
     Returns the index start marker.
public  StringgetPropertyDelimiter()
     Returns the property delimiter.
public  StringnodeKey(ConfigurationNode node, String parentKey)
     Determines the key of the passed in node.
public  NodeAddDataprepareAdd(ConfigurationNode root, String key)
    

Prepares Adding the property with the specified key.

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

public  Listquery(ConfigurationNode root, String key)
     Evaluates the given key and returns all matching nodes.
public  voidsetAttributeEnd(String attributeEnd)
     Sets the attribute end marker.
public  voidsetAttributeStart(String attributeStart)
     Sets the attribute start marker.
public  voidsetEscapedDelimiter(String escapedDelimiter)
     Sets the escaped property delimiter string.
public  voidsetIndexEnd(String indexEnd)
     Sets the index end marker.
public  voidsetIndexStart(String indexStart)
     Sets the index start marker.
public  voidsetPropertyDelimiter(String propertyDelimiter)
     Sets the property delmiter.

Field Detail
DEFAULT_ATTRIBUTE_END
final public static String DEFAULT_ATTRIBUTE_END(Code)
Constant for the default attribute end marker.



DEFAULT_ATTRIBUTE_START
final public static String DEFAULT_ATTRIBUTE_START(Code)
Constant for the default attribute start marker.



DEFAULT_ESCAPED_DELIMITER
final public static String DEFAULT_ESCAPED_DELIMITER(Code)
Constant for the default escaped property delimiter.



DEFAULT_INDEX_END
final public static String DEFAULT_INDEX_END(Code)
Constant for the default index end marker.



DEFAULT_INDEX_START
final public static String DEFAULT_INDEX_START(Code)
Constant for the default index start marker.



DEFAULT_PROPERTY_DELIMITER
final public static String DEFAULT_PROPERTY_DELIMITER(Code)
Constant for the default property delimiter.





Method Detail
findLastPathNode
protected ConfigurationNode findLastPathNode(DefaultConfigurationKey.KeyIterator keyIt, ConfigurationNode node)(Code)
Finds the last existing node for an add operation. This method traverses the configuration node 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



findNodesForKey
protected void findNodesForKey(DefaultConfigurationKey.KeyIterator keyPart, ConfigurationNode node, Collection nodes)(Code)
Recursive helper method for evaluating a key. 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:
  nodes - here the found nodes are stored



getAttributeEnd
public String getAttributeEnd()(Code)
Sets the attribute end marker. the attribute end marker



getAttributeStart
public String getAttributeStart()(Code)
Returns the attribute start marker. the attribute start marker



getEscapedDelimiter
public String getEscapedDelimiter()(Code)
Returns the escaped property delimiter string. the escaped property delimiter



getIndexEnd
public String getIndexEnd()(Code)
Returns the index end marker. the index end marker



getIndexStart
public String getIndexStart()(Code)
Returns the index start marker. the index start marker



getPropertyDelimiter
public String getPropertyDelimiter()(Code)
Returns the property delimiter. the property delimiter



nodeKey
public String nodeKey(ConfigurationNode node, String parentKey)(Code)
Determines the key of the passed in node. This implementation takes the given parent key, adds a property delimiter, and then adds the node's name. (For attribute nodes the attribute delimiters are used instead.) The name of the root node is a blanc string. Note that no indices will be returned.
Parameters:
  node - the node whose key is to be determined
Parameters:
  parentKey - the key of this node's parent the key for the given node



prepareAdd
public NodeAddData prepareAdd(ConfigurationNode root, String key)(Code)

Prepares Adding the property with the specified key.

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

 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:
  root - the root node of the nodes hierarchy
Parameters:
  key - the key of the new property a data object with information needed for the add operation



query
public List query(ConfigurationNode root, String key)(Code)
Evaluates the given key and returns all matching nodes. This method supports the syntax as described in the class comment.
Parameters:
  root - the root node
Parameters:
  key - the key a list with the matching nodes



setAttributeEnd
public void setAttributeEnd(String attributeEnd)(Code)
Sets the attribute end marker.
Parameters:
  attributeEnd - the attribute end marker; can be null if noend marker is needed



setAttributeStart
public void setAttributeStart(String attributeStart)(Code)
Sets the attribute start marker. Attribute start and end marker are used together to detect attributes in a property key.
Parameters:
  attributeStart - the attribute start marker



setEscapedDelimiter
public void setEscapedDelimiter(String escapedDelimiter)(Code)
Sets the escaped property delimiter string. With this string a delimiter that belongs to the key of a property can be escaped. If for instance "." is used as property delimiter, you can set the escaped delimiter to "\." and can then escape the delimiter with a back slash.
Parameters:
  escapedDelimiter - the escaped delimiter string



setIndexEnd
public void setIndexEnd(String indexEnd)(Code)
Sets the index end marker.
Parameters:
  indexEnd - the index end marker



setIndexStart
public void setIndexStart(String indexStart)(Code)
Sets the index start marker. Index start and end marker are used together to detect indices in a property key.
Parameters:
  indexStart - the index start marker



setPropertyDelimiter
public void setPropertyDelimiter(String propertyDelimiter)(Code)
Sets the property delmiter. This string is used to split the parts of a property key.
Parameters:
  propertyDelimiter - the property delimiter



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.