We are using DynamicPropertyHandler similar to the way you have it. It looks like you will only be able to get the "x' property and not the elements of the array list. Do you want to hide the list? Maybe you need a name for the list too so the list can also be accessible to XPath expressions.

Vos, Jerry R. wrote:

Thanks Paul, your interpretation was correct. I did see Container
before, and while I don't think is going to work in this case, it did
make me think of using the DynamicPropertyHandler to do this.  I was
actually considering using the DynamicPropertyHandler for something
else, but didn't think of using it for this purpose.

Basically, what I'm going to try and do is just have my
DynamicPropertyHandler return the normal properties for my class. So in
my example I'd do something like:

public class BarHandler implements DynamicPropertyHandler {
public Object getProperty(Object object, String propertyName) {
        if (propertyName.equals("x")) {
                return ((Bar) object).getSubContexts();
        }
        return null;
}
                
public String[] getPropertyNames(Object object) {
        return new String[] { "x" };
}
                
public void setProperty(Object object, String propertyName, Object
value) {
        throw new UnsupportedOperationException("");
}
}

And then something like
JXPathIntrospector.registerDynamicClass(Bar.class, BarHandler.class);

Anyway, will update with the results of this.  If anyone sees an obvious
problem with that please let me know.

Jerry

-----Original Message-----
From: Paul Copeland [mailto:[EMAIL PROTECTED]
Sent: Monday, July 24, 2006 4:52 PM
To: Jakarta Commons Users List
Subject: Re: JXPath and custom collection

Essentially you are asking if you can access non-child attributes of a
Collection. Normally you would access the elements of a Collection as
nodes with iterate (rather than getValue).  It seems to want to treat
Collections as NodeSets rather than as Nodes. So it works if Bar has
an
ArrayList property, but not if Bar is a subclass of ArrayList as in
your
example.  Maybe you can do something with a Container...


http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpa
th
/Container.html


Vos, Jerry R. wrote:

public class Bar extends ArrayList {
          public String getX() { return "xValue" }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to