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 Tue, 25 Nov 2008 00:35:17 GMT
Everything falls apart once collections or array's are involved. I am doing
something wrong, help would be most appreciated. I can't see any simple
examples online and there's no doco on how to do this.
I'm considering giving up, like the rest of the people before me.

On Mon, Nov 24, 2008 at 12:28 PM, Andrew Hughes <ahhughes@gmail.com> wrote:

> After further testing, I have reduced the complexity of my 'Bean'. The
> 'Bean' is no longer a Collection<> and provides getThe* methods that do not
> meet the Beans standard. Hence, JXPath must use an XBeanInfo and
> DynamicHandler to perform sucessful traversal/evalution, and it does...
> For the first time I can see  DynamicHandler<init> being called. My
> previous DynamicHandler that worked with a Collection class was never
> initialized and thus proves JXPath was never using it.
>
> The big question is, why? I know I can get around this by reworking my
> datastructure so that it does not extend ArrayList<MyBean> () but I really
> don't think I should have to do this.
>
> I've read a few posts with the same problem now (some as far back as 2006).
> Im yet to see a solution, it looks like everyone else just decides to 'give
> up' which I'd rather not do, because if this works it's a great solution.
>
> :)
>
>
> On Mon, Nov 24, 2008 at 9:49 AM, Andrew Hughes <ahhughes@gmail.com> wrote:
>
>> 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