commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anand Narasimhan" <ana...@cisco.com>
Subject RE: New to JXPath. Please help
Date Fri, 22 Apr 2005 17:30:21 GMT

Hi Dmitri,

Thanks for replying. I apologize that my example is not very clear.
I am attaching some sample code that shows my tree model. 

So far from the documentation, I understand that JXPath can be used to apply
XPath expressions on JavaBean type object graph, DOM tree, Maps etc. 

My model is not a JavaBean object graph or DOM. It is a custom tree model
where
each node contains an Object that not necessarily a JavaBean. Not all of
them
have explicit setters and getters. These classes were written by various
developers and not all of them implement explicit setters and getters.

So I will not be able to use of the reference implementation provided by
JXPath.
I need to implement custom NodePointer and NodePointerFactory to navigate
nodes
in my tree model. Is that a correct assesment? Further, how can I use JXPath

to select nodes in my model where the attributes matches some pattern. 

For eg, in the tree model contained in the attached TestMain.java file, I
want
to select all nodes in the tree that has device interface names starting
with
"Serial". Something like /Device/Interface[starts-with(@InterfaceName,
'Serial')]

I am sorry, I am not able to explain my problem/questions more clearly. Any 
help would be appreciated. I guess I am looking for some
information/examples
that either explains or shows what classes I need to implement to be able to
use JXPath with my object model.

Thanks
Anand 

> -----Original Message-----
> From: Dmitri Plotnikov [mailto:dmitri@apache.org] 
> Sent: Friday, April 22, 2005 4:55 AM
> To: Jakarta Commons Users List
> Subject: Re: New to JXPath. Please help
> 
> Anand,
>  
> First of all, it's not clear from your example that your 
> object model does not follow the JavaBean specification.  If 
> you have explicit getters for all properties you need to 
> access with JXPath, you should be able to use JXPath as is.
>  
> However, if some of the properties are not covered by get/set 
> methods, you will need to extend JXPath a little bit.  The 
> easiest method would be to create a DynamicPropertyHandler 
> and register it.  See documentation.
>  
> As far as license is concerned, you are ok bundling JXPath 
> with a commercial product.  That's the beauty of the Apache license.
>  
> I hope this helps.
>  
> - Dmitri
> 
> Anand Narasimhan <anandn@cisco.com> wrote:
> Hi,
> 
> I am new to JXPath. I just read the user guide briefly. I 
> have a few questions. Please help.
> 
> The user guide says "JXPath applies XPath expressions to 
> graphs of objects of all kinds: JavaBeans, Maps, Servlet 
> contexts, DOM etc, including mixtures thereof. "
> 
> 1. Can I use JXPath to select nodes from a tree containing 
> arbitrary data by applying XPath expressions. If so what do I 
> need to do, what classes do I need to extend. Or my 
> understanding of JXPath is completely wrong and JXPath cannot 
> be used for this purpose?
> 2. If I want to package JXPath binaries with a commercial 
> product, are there any licensing restrictions. What are they?
> 
> A bit more information on my tree model. My tree mode is very 
> much similar to the javax.swing.tree.DefaultTreeModel and the 
> nodes are similar to javax.swing.tree.DefaultMutableTreeNode. 
> 
> public class Tree
> {
> Node root;
> 
> public Node getRoot();
> ...
> }
> 
> public class Node
> {
> String nodeName;
> Node parent;
> List children;
> MyClass userData;
> }
> 
> 
> Implementation of MyClass does not follow the Java Bean 
> conventions. It
> basically contains a hash map of attribute/value pairs and 
> has setAttribute
> and getAttribute method. It also has a setter and getter for 
> each attribute.
> 
> 
> For eg.
> 
> public class MyClass
> {
> protected HashMap attributes
> 
> public void setAttribute( String key, Object value );
> public Object getAttribute( String key );
> }
> 
> public class MyClass1 extends MyClass
> {
> public static final String NAME = "Name";
> public static final String IP_ADDRESS = "IP Address";
> 
> public String getName ()
> {
> return (String) getAttribute( NAME );
> }
> 
> public String getIpAddress()
> {
> return (String) getAttribute( IP_ADDRESS );
> }
> }
> 
> So, If have a tree instance like
> 
> Root
> |
> |
> ----------------------------------------------
> | | | |
> X X1
> | |
> ----------- ----------
> | | | |
> Y Y2 Z1 Z2
> 
> 
> I want use XPath to select node /Root/X/Y2 or /Root/X/Y[@Name 
> = 'xyz'].
> Is this possible with JXPath.
> 
> Thanks
> Anand
> 
> _________________________________________________________________
> 
> Anand Narasimhan
> anandn@cisco.com
> 
> 


Mime
View raw message