commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@yahoo.com>
Subject Re: [JXPath] Iterators and Pointers (on partial matches)
Date Fri, 05 Jun 2009 13:32:37 GMT

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 <ahhughes@gmail.com> wrote:

> From: Andrew Hughes <ahhughes@gmail.com>
> Subject: Re: [JXPath] Iterators and Pointers (on partial matches)
> To: "Commons Users List" <user@commons.apache.org>
> 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 <gudnabrsam@yahoo.com>
> 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 <ahhughes@gmail.com>
> wrote:
> >
> > > From: Andrew Hughes <ahhughes@gmail.com>
> > > Subject: [JXPath] Iterators and Pointers (on
> partial matches)
> > > To: "Commons Users List" <user@commons.apache.org>
> > > 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: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
> >
> >
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message