Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 17609 invoked from network); 8 May 2004 19:56:01 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 8 May 2004 19:56:01 -0000 Received: (qmail 75858 invoked by uid 500); 8 May 2004 19:55:47 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 75465 invoked by uid 500); 8 May 2004 19:55:45 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 75451 invoked from network); 8 May 2004 19:55:45 -0000 Received: from unknown (HELO rwcrmhc13.comcast.net) (204.127.198.39) by daedalus.apache.org with SMTP; 8 May 2004 19:55:45 -0000 Received: from plotnix2500 (pcp02137893pcs.reston01.va.comcast.net[68.48.26.233]) by comcast.net (rwcrmhc13) with SMTP id <20040508195550015007ke2je>; Sat, 8 May 2004 19:55:50 +0000 Message-ID: <008001c43536$763c83c0$0500a8c0@plotnix2500> From: "Dmitri Plotnikov" To: "Jakarta Commons Users List" , References: <4097C3AE.1000100@paychex.com> <409A355B.9080500@paychex.com> <409B5B1B.3080409@ignos.com> <409BFC46.4080801@paychex.com> Subject: Re: JXPath - shared Context Date: Sat, 8 May 2004 15:55:49 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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" To: "Jakarta Commons Users List" 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