commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hughes" <ahhug...@gmail.com>
Subject Re: JXPath XBeanInfo & Generic Collection Problem
Date Sun, 23 Nov 2008 23:19:29 GMT
After a little more investigation, I have overriden every
Collection/ArrayList method in the "PojoNode" class to see how/if JXPath
calls ANY of the inherited super methods. It does not! If JXPath is not
traversing my data structure in any way, then it's probably not even
evaluating it. But Im not sure why this would be, or why under such
circumstances a mis-configuration like this does not throw any exceptions.
As I said, I think I have exhausted the online docs and I'm getting a little
desperate (probably sound like it too). So any help would definitely be
appreciated. :)


On Fri, Nov 21, 2008 at 1:42 PM, Andrew Hughes <ahhughes@gmail.com> wrote:

> Hi,
> I'm trying to work out how I can add the following PojoNode to JXPath's
> context for evaluation.
>
> public class PojoNode extends java.util.ArrayList<PojoNode> {
> public PojoNode(Pojo pojo) {
>  this.pojo = pojo;
>  }
>  private Pojo pojo;
>  public Pojo getPojo() {
>  return pojo;
>  }
> }
>
>
>
> The PojoNode tree above is (definitely) populated... then I setup and ask
> JXPath to evaluate an expression on it:
>
>
> JXPathIntrospector.registerDynamicClass(PojoNode.class,PojoDynamicPropertyHandler.class);
> JXPathContext jxPathContext = JXPathContext.newContext(rootPojoNode);
> PojoNode result = (PojoNode)jxPathContext.getValue("/"); //this always
> produces an empty result
>
>
> What concerns me is not the code I have written but the code I have not.
> I've got log statements in the PojoXInfoBean and PojoDynamicPropertyHandler
> (see below) but none every fire (in particular  "I have been asked to
> look.." and "...w00t").  Consequently the PojoNode tree is not being
> traversed correctly and thus fails. I suspect that because PojoNode
> implements a Collection it's picked up buy another DynamicPropertyHandler.
>
> I feel like I have exhausted the javadocs and any help would be very very
> much appreciated.
>
> Thank You.
>
>
> ps if you wanted to see more code it is below....
>
> public class PojoNodeDynamicPropertyHandler implements
>  DynamicPropertyHandler {
>
> private final static Logger log =
> Logger.getLogger(PojoNodeDynamicPropertyHandler.class);
>
> public Object getProperty(Object PojoNode, String name) {
>  log.debug("I have been asked to look for '"+name+"'");
>  Collection<PojoNode> hits = new ArrayList<PojoNode>();
>  for(PojoNode childPojoNode : (PojoNode) PojoNode){
>  if (childPojoNode.getPojo().getName().equals(name)){
>  hits.add(childPojoNode);
>  }
>  }
>
> log.debug("I have found '"+hits.size()+"' instances of '"+name+"'");
>  return hits;
>  }
>
> public String[] getPropertyNames(Object PojoNode) {
>  log.debug("JXPath has asked for this, w00t!");
>  HashSet<String> nameSet = new HashSet<String>();
>  nameSet.addAll(collectChildNames(PojoNode));
>  return (String[]) nameSet.toArray(new String[nameSet.size()]);
>  }
>
> public void setProperty(Object arg0, String arg1, Object arg2) {
>  throw new RuntimeException(
>  "Manipulation through JXPath is not allowed.... (yet)");
>  }
>
> private HashSet<String> collectChildNames(Object PojoNode) {
>  HashSet<String> nameSet = new HashSet<String>();
>  for (PojoNode childPojo : (PojoNode) PojoNode) {
>  nameSet.add(childPojo.getPojo().getName());
>  }
>  return nameSet;
>  }
>
> }
>
> ........................................................................................
>
> public class PojoNodeXBeanInfo implements JXPathBeanInfo{
>
>   private static final Logger log =
> Logger.getLogger(PojoNodeXBeanInfo.class);
>
>
> public Class<PojoNodeDynamicPropertyHandler>
> getDynamicPropertyHandlerClass() {
>
>  log.debug("JXPath has asked for this, w00t!");
>
>  return PojoNodeDynamicPropertyHandler.class;
>
>  }
>
>
>  public PropertyDescriptor getPropertyDescriptor(String arg0) {
>
>  log.debug("JXPath has asked for this, w00t!");
>
>  return null;
>
> }
>
>
> public PropertyDescriptor[] getPropertyDescriptors() {
>
>  log.debug("JXPath has asked for this, w00t!");
>
>  return null;
>
>  }
>
>
>  public boolean isAtomic() {
>
> log.debug("JXPath has asked for this, w00t!");
>
>  return false;
>
>  }
>
>
>  public boolean isDynamic() {
>
> log.debug("JXPath has asked for this, w00t!");
>
>  return true;
>
>  }
>
>  }
>
>
>
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message