Supported Data Types


Having shown how JXPath can be used to navigate complex hierarchies (as represented by JavaBeans), it is useful to note that JXPath can be used with a wide array of potential object types. These include:

JavaBeans

Arrays

Collections

Maps (with String keys only)

DOM & JDOM

DynaBeans (see Chapter 7 for more information on DynaBeans)

XML Documents (via a built-in JXPath Container)

Perhaps most interestingly, it's possible to mix these different object types as you traverse an object graph. For example, your JavaBean may make reference to an array of JDOM objectswhich could be accessed with a single XPath query.

Performance and JXPath

Any specialized solution for a specific data type is likely to beat the performance of JXPath because JXPath is designed to work flexibly with a variety of heterogeneous object graphs (e.g., XML, DOM, JavaBeans, etc.). For example, if you wish to focus on XML only, you will likely see better performance using a technology such as Xalan's CachedXPathAPI, http://xml.apache.org/xalan-j/. Similarly, although an XPath query may be much more terse than the same Java code, the JXPath implementation needs to use Java reflection and other technologies to obtain information at run-time that would otherwise be added by the compiler.

If performance is a concern (for example, if you are working with a large server application), you may want to consider a strategy in which you cache compiled expressions (see http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/CompiledExpression.html). Note that the default implementation of JXPath does perform some minimal compiled expression caching.




    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net