commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Plotnikov" <dmi...@apache.org>
Subject Re: JXPath - shared Context
Date Sat, 08 May 2004 19:55:49 GMT
Paul,

It looks like you may be using a very old codebase (perhaps the 1.1
release).  The line numbers in your patch don't seem to match the current
version. We have fixed a million bugs since that release.  Could you try
switching to the current build to see if the problem has already been
addressed?  Please let me know.

Thank you very much.

- Dmitri

----- Original Message ----- 
From: "Paul McClure" <pmcclure@paychex.com>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Friday, May 07, 2004 5:14 PM
Subject: Re: JXPath - shared Context


> Thanks Adrian,
>     The patch for functions works - and I see the variable in the parent
> now also. I was trying to access them with:
>   ctx.getVariables().getVariable("myVar");
> which didn't work.
> One other thing I was trying to do is to set lenient to true
> (s_sharedContext.setLenient(true);). This is not shown in the examples,
> but should this be seen by child contexts?
> thanks again for your help,
> Paul
>
> Adrian Perez Jorge wrote:
>
> > Paul McClure wrote:
> >
> >> I'm creating my JXPathContext with a parent context arg - but the new
> >> context does not seem to see anything that was set in the parent
> >> context. Should this work - this would be a very useful feature....
> >>
> >> JXPathContext sharedContext = JXPathContext.newContext(null);
> >> sharedContext.getVariables().declareVariable("title", "Java");
> >
> >
> > I don't agree.  Accessing variables declared/defined in parent context
> > works for me.  Maybe it's a problem of your AbstractFactory?
> >
> >> sharedContext.setFunctions(new MyExtensionFunctions());
> >
> >
> > It seems there is a bug in method getFunction(QName, Object[]) at file
> > JXPathContextReferenceImpl.java.  The code just looks for the function
> > to be called in all Functions objects established for each context,
> > starting from the current context and then going on each parent
> > context.  But the problem is that when a Function object has not been
> > established for any of the context mentioned, the search stops.
> >
> > Here is a patch that solves that problem (untested; for release
> > commons-jxpath-1.1):
> >
> > --- JXPathContextReferenceImpl.java.orig    Fri May  7 10:05:37 2004
> > +++ JXPathContextReferenceImpl.java    Fri May  7 10:06:06 2004
> > @@ -603,9 +603,6 @@
> >
> >                 funcCtx = funcCtx.getParentContext();
> >             }
> > -            else {
> > -                break;
> > -            }
> >         }
> >         func = GENERIC_FUNCTIONS.getFunction(namespace, name,
> > parameters);
> >         if (func != null) {
> > @@ -639,4 +636,4 @@
> >             throw new JXPathException("Cannot allocate " + className,
> > ex);
> >         }
> >     }
> > -}
> > \ No newline at end of file
> > +}
> >
> >
> >
> >> sharedContext.setLocale(Locale.CANADA);
> >
> >
> > Locale is also inherited at runtime from parent context, so it should
> > work.
> >
> >> sharedContext.setFactory(new MyFactory());
> >
> >
> > I haven't included here a test for that feature, but again parent
> > context factory works for me in contexts where a parent context
> > exists.  I can publish a test case if anybody wants it.
> >
> >>
> >> JXPathContext context = JXPathContext.newContext(sharedContext, auth);
> >>
> >> I follow this example, but my 'context' does not know about anything
> >> in sharedContext.
> >>
> >> thanks,
> >> Paul
> >>
> >
> > Here is the code I used to test that stuff.  I used a BeanShell script
> > and two very simple classes.  To run this use the correct CLASSPATH to
> > commons-jxpath.jar and bsh.jar and compile the two java classes:
> >
> > ---- testParentCtx.beanshell -- starts here
> >
> > import org.apache.commons.jxpath.JXPathContext;
> > import org.apache.commons.jxpath.ClassFunctions;
> > import test.MyExtensionFunctions;
> > import test.MyDummyExtensionFunctions;
> >
> > sharedContext = JXPathContext.newContext(null);
> > sharedContext.setFunctions(new
> > ClassFunctions(MyExtensionFunctions.class, "myfunc"));
> > sharedContext.getVariables().declareVariable("title", "Java");
> > sharedContext.setLocale(new Locale("es", "ES"));
> >
> > context = JXPathContext.newContext(sharedContext, null);
> > context.setFunctions(new
> > ClassFunctions(MyDummyExtensionFunctions.class, "myfunc"));
> >
> > System.out.println(context.getValue("myfunc:sayhello('hola')"));
> > System.out.println(context.getValue("$title"));
> > System.out.println(context.getLocale());
> >
> > ---- ends here
> >
> > --- MyExtensionFunctions.java -- starts here
> >
> > package test;
> >
> > public class MyExtensionFunctions {
> >
> >    static public String sayhello(String salutation) {
> >
> >    return new String("I say " + salutation);
> >    }
> > }
> >
> > --- end here
> >
> > --- MyDummyExtensionFunctions.java -- starts here
> > package test;
> >
> > public class MyDummyExtensionFunctions {
> >
> > }
> > --- ends here
> >
> >
> > Cheers,
> >
> > Adrian P.J.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
>
> -----------------------------------------
> The information contained in this message may be privileged, confidential,
and protected from disclosure. If the reader of this message is not the
intended recipient, or any employee or agent responsible for delivering this
message to the intended recipient, you are hereby notified that any
dissemination, distribution, or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify
us immediately by replying to the message and deleting it from your
computer.
>
> Thank you. Paychex, Inc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>



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


Mime
View raw message