You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Greg <gr...@ozemail.com.au> on 2003/02/10 05:23:12 UTC

AbstractFactory question v1.1b1

All,

I'm trying to plug in a general purpose DOM AbstractFactory that will handle creation of elements/attributes as needed.


JXPathContext context = JXPathContext.newContext( myDomElement );

AbstractFactory factory = new MyJXPathDOMFactory();
context.setFactory(factory);
context.setLenient(true);

where myDomElement does contain <someElement> but not <fred> or @fred the following lines fail without calling my factory (which contains printlines to show where the createObject and declareVariable methods are called.

context.createPath( "//someElement/fred" );            // fails
context.createPath( "//someElement/@fred" );        // fails

I get the following exception:

JXPathExpression: Expression is not a path
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPathJXPathContextReferenceImpl.java:361)


1. Is there a *simple* example floating around that in a few lines of code shows how a custom AbstractFactory is plugged into a JXPathContext using DOM?

2. Is there already an implementation of a general purpose DOM AbstractFactory available anywhere?

Thanks,
Greg.

Re: AbstractFactory question v1.1b1

Posted by Dmitri Plotnikov <dp...@yahoo.com>.
Greg,

--- Greg <gr...@ozemail.com.au> wrote:
> All,
> 
> I'm trying to plug in a general purpose DOM AbstractFactory that will
> handle creation of elements/attributes as needed.
> 
> 
> JXPathContext context = JXPathContext.newContext( myDomElement );
> 
> AbstractFactory factory = new MyJXPathDOMFactory();
> context.setFactory(factory);
> context.setLenient(true);
> 
> where myDomElement does contain <someElement> but not <fred> or @fred
> the following lines fail without calling my factory (which contains
> printlines to show where the createObject and declareVariable methods
> are called.
> 
> context.createPath( "//someElement/fred" );            // fails
> context.createPath( "//someElement/@fred" );        // fails
> 
> I get the following exception:
> 
> JXPathExpression: Expression is not a path
> at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPathJXPathContextReferenceImpl.java:361)

I have improved the error reporting since b1.  You will see the new
error message in b2.  Here's the text of the message:

"JXPath can only create a path if it uses exclusively the child:: and
attribute:: axes and has no context-dependent predicates"

In your case you are using the descendent-or-self:: axis. JXPath does
not know how (or where in tree) to create the missing nodes.

> 
> 
> 1. Is there a *simple* example floating around that in a few lines of
> code shows how a custom AbstractFactory is plugged into a
> JXPathContext using DOM?
There are several factories in the test tree.  See for example
org.apache.commons.jxpath.ri.model.dom.TestDOMFactory.

> 2. Is there already an implementation of a general purpose DOM
> AbstractFactory available anywhere?
Not that I know of.


> Thanks,
> Greg.
> 

Regards,
- Dmitri

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com