commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dmi...@apache.org>
Subject Re: New to JXPath. Please help
Date Fri, 22 Apr 2005 11:55:16 GMT
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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message