Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 17466 invoked from network); 24 Nov 2008 01:58:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Nov 2008 01:58:48 -0000 Received: (qmail 25024 invoked by uid 500); 24 Nov 2008 01:58:55 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 24955 invoked by uid 500); 24 Nov 2008 01:58:55 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 24944 invoked by uid 99); 24 Nov 2008 01:58:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Nov 2008 17:58:55 -0800 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ahhughes@gmail.com designates 209.85.142.184 as permitted sender) Received: from [209.85.142.184] (HELO ti-out-0910.google.com) (209.85.142.184) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Nov 2008 01:57:30 +0000 Received: by ti-out-0910.google.com with SMTP id u5so1063443tia.10 for ; Sun, 23 Nov 2008 17:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=2rxzjyYn/Xj0AZs824dGLGfP2HDz9iRexpvq5TlPtnQ=; b=bHE1PU2pfLHQtw3JyNhn8Z1p1e945CYbhLBaAcxz2u5NjExLugl1c9+DBulvK08atn opGHnzVdehRNCd/pvvpTCQRmjPoYtuaIg8n92GnZpL2OCMtKg9fy2NXhU0q2MwdKs+OW DXqsjgwS0y0d7vDyWuDj+whHGc7K5lZ1zRRWA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=jCKIjz0lhmcsoFkKCkwK4qPtUOJbCDwFcwtd9+YjWwfA/bwuciHVKEsN+BcLNgvN01 ivd3WKKEHDXs9bAtn/4Wg48wtVxIyP85qJEw8O6XIHuu84K7WmJtRd83gn8whdnSWIIT YfKNcWurHEF0SQiDO2eQisZmKItklYX/BJ100= Received: by 10.110.73.19 with SMTP id v19mr4115011tia.35.1227491894790; Sun, 23 Nov 2008 17:58:14 -0800 (PST) Received: by 10.110.60.8 with HTTP; Sun, 23 Nov 2008 17:58:14 -0800 (PST) Message-ID: <5f528cf40811231758g4009528bl8049fb0f6d407b37@mail.gmail.com> Date: Mon, 24 Nov 2008 12:28:14 +1030 From: "Andrew Hughes" To: "Commons Users List" Subject: Re: JXPath XBeanInfo & Generic Collection Problem In-Reply-To: <5f528cf40811231519v5e45d176i269ef91d27690fba@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_164681_17580311.1227491894794" References: <5f528cf40811201912w45483968n82ad388d02989047@mail.gmail.com> <5f528cf40811231519v5e45d176i269ef91d27690fba@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_164681_17580311.1227491894794 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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 () 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 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 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 { >> 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 hits = new ArrayList(); >> 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 nameSet = new HashSet(); >> 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 collectChildNames(Object PojoNode) { >> HashSet nameSet = new HashSet(); >> 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 >> 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; >> >> } >> >> } >> >> >> >> >> >> >> > ------=_Part_164681_17580311.1227491894794--