Hi Again, I believe that I am much closer now :) - I've used reflection to gain access to some of the protected/private bits of jxpath [JXPathCompiledExpression.getExpression() and JXPathContextReferenceImpl.getEvalContext()]. - JXPathCompiledExpression.getExpression().computeValue(evalContext) gives me a NodePointer for expressions like '/World/Blah' ^note, I will come back to this. - These NodePointers are good, because if the NodePointer is pointing at a node that does not exist, then I can getParent and listen for my actual NodePointer to be created (all that way back to the context root). Hence I can now listen for a node's creation :) - ^However... this works fin for NodePointers... because they have parents, but other expressions (such as core functions) do not and this won't work for them. I still don't understand how/where JXPath works well enuff to get this working.
Thanks again for all your help :) On Fri, Jun 5, 2009 at 11:02 PM, Matt Benson <[email protected]> wrote: > > Oops--my class is actually called HierarchyMap, not that it matters. ;) > Basically I've done stuff where I did simple tokenization of / delimited > xpath components--that might be enough for you, really, as those really are > the steps, even when they are qualified with [stuff]... otherwise there are > a number of techniques you might employ to get at the RI Path/Steps. The > simplest of these might involve casting the results of > JXPathContext.compile(String) to JXPathCompiledExpression and using > reflection-based access modification to get the Expression from the > JXPathCompiledExpression (its accessor is protected). In the distant past I > have a memory of extending a class just so I could use my subclass to access > protected methods of another instance of the same superclass, but I'm not > sure if that still works or if there were special circumstances that made it > work. Good luck with it. > > -Matt > > --- On Thu, 6/4/09, Andrew Hughes <[email protected]> wrote: > > > From: Andrew Hughes <[email protected]> > > Subject: Re: [JXPath] Iterators and Pointers (on partial matches) > > To: "Commons Users List" <[email protected]> > > Date: Thursday, June 4, 2009, 7:25 PM > > Hi Matt, > > Your explanation re: HierarchyTable sounds very similar. > > Another possible > > option is if I can somehow tokenize the "steps" in the > > expression itself. > > Then I could keep appending the .next() token... and re-run > > the expression > > until it fails (in actual fact it would be best to start > > removing '--' > > tokens from the end and re-querying as it is more > > responsive). > > > > Somthing that would look like... > > > > Iterator<String> tokens = > > MythicalTokenizer.tokenize("/Earth/Australia/NSW/Sydney/Utopia"); > > jxpathContext.selectNode(expression+=tokens.next()); // > > success with > > expression = "/Earth" > > jxpathContext.selectNode(expression+=tokens.next()); // > > success with > > expression = "/Earth/Australia" > > jxpathContext.selectNode(expression+=tokens.next()); // > > success with > > expression = "/Earth/Australia/NSW" > > jxpathContext.selectNode(expression+=tokens.next()); // > > success with > > expression = "/Earth/Australia/NSW/Sydney" > > jxpathContext.selectNode(expression+=tokens.next()); // > > FAILURE with > > expression = "/Earth/Australia/NSW/Sydney/Utopia" > > > > > > I've had a look at the compiled expressions and parser's on > > the RI but I > > can't see anything that would allow me to do this > > :'( Hopefully I am > > missing something. > > > > THANKS HEAPS FOR THE RESPONSE!!!! > > --Andrew > > > > > > On Fri, Jun 5, 2009 at 12:03 AM, Matt Benson <[email protected]> > > wrote: > > > > > > > > Hi Andrew, > > > I'm not sure if JXPath is necessarily really the > > right tool for this. > > > This almost just looks like a sort of > > hierarchical lookup. I have a > > > HierarchyTable we use at my $work for these type > > purposes; unfortunately I > > > haven't yet gotten clearance to release it into the > > wild. I plan someday to > > > include it in [collections] but it may need rewriting > > before the Commons > > > community would even agree to it, the reason being > > that it's somewhat heavy. > > > I suppose I can explain its > > implementation: It stores hierarchical data a > > > node per level, and its nodes it uses each hold a > > HashMap (the heavy part) > > > to keep track of child nodes. So you _could_ > > implement your own version of > > > that. If you are determined to use JXPath for > > this, for example if you just > > > really need to be able to get at this information with > > an expression, you > > > might be able to accomplish it with a custom function > > but I'm still afraid > > > at some point you might have to parse the steps, or > > rely on JXPath RI > > > packages/classes. > > > > > > HTH, > > > Matt > > > > > > --- On Wed, 6/3/09, Andrew Hughes <[email protected]> > > wrote: > > > > > > > From: Andrew Hughes <[email protected]> > > > > Subject: [JXPath] Iterators and Pointers (on > > partial matches) > > > > To: "Commons Users List" <[email protected]> > > > > Date: Wednesday, June 3, 2009, 9:45 PM > > > > Hi Again, > > > > I'm trying to resolve an issue I have trying to > > step > > > > through object's > > > > slightly *different* to the JXPath > > ReferenceImpl. > > > > > > > > Say I have String expression = > > > > "/Earth/Australia/NSW/Sydney/Utopia"; Since > > > > "Utopia" is a mythical place that never exists > > I'll never > > > > get a result from > > > > > > selectNode("/Earth/Australia/NSW/Sydney/Utopia"); > > > > > > > > Neither can I do this with an iterator: > > > > > > > > http://commons.apache.org/jxpath/apidocs/org/apache/commons/jxpath/JXPathContext.html#iteratePointers(java.lang.String) > > > > > > > > "If the xpath matches no properties in the graph, > > the > > > > Iterator be empty, but > > > > not null." > > > > > > > > I've tested this is and when I look for Utopia, I > > get an > > > > empty iterator.... > > > > > > > > I need an iterator that allows me see just how > > close I can > > > > get to 'Utopia': > > > > > > > > Iterator step = > > > > > > jxpathContext.iterator("/Earth/Australia/NSW/Sydney/Utopia" > > > > ); > > > > system.out.println(step.next().toString());// '' > > the root > > > > object > > > > system.out.println(step.next().toString());// > > 'Earth' > > > > system.out.println(step.next().toString());// > > 'Australia' > > > > system.out.println(step.next().toString());// > > 'NSW' > > > > system.out.println(step.next().toString());// > > 'Sydney' > > > > system.out.println(step.next().toString());// > > THROWS AN > > > > EXCEPTION BECAUSE > > > > UTOPIA DOES NOT EXIST!!!! > > > > > > > > > > > > Thanks heaps for reading (again) :) > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > 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] > >
