You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Paul McClure <pm...@paychex.com> on 2004/05/06 14:53:47 UTC

JXPath - shared Context

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");
 sharedContext.setFunctions(new MyExtensionFunctions());
 sharedContext.setLocale(Locale.CANADA);
 sharedContext.setFactory(new MyFactory());

 JXPathContext context = JXPathContext.newContext(sharedContext, auth);

I follow this example, but my 'context' does not know about anything in sharedContext.

thanks,
Paul



>


-----------------------------------------
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


[JXPath] - stable release

Posted by Paul McClure <pm...@paychex.com>.
Do you know when a new stable release will be available?
thanks,

Paul McClure wrote:

> Dmitri, Adrian
>    I switched to the May 10th build - and all problems seem to be 
> addressed (setFunctions() and setLenient()).
> Do you know when a new stable release will be available?
> Thanks very much,
> Paul
>
> Adrian Perez Jorge wrote:
>
>> Dmitri Plotnikov wrote:
>>
>>> 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
>>>  
>>>
>> Looking at the code in the CVS repository it seems the bug was fixed, 
>> sorry.  I was using release 1.1 because jakarta commons site says 
>> it's the stable release and there is no nightly nor milestone 
>> builds.  I read in the source code that you were working in Xalan 
>> integration so I thought CVS code was not adecuate for use in 
>> applications, but I didn't test it :-(
>>
>> BTW jxpath is a very useful piece of sofware. Congratulations.
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


-----------------------------------------
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


Re: JXPath - shared Context

Posted by Paul McClure <pm...@paychex.com>.
Dmitri, Adrian
    I switched to the May 10th build - and all problems seem to be 
addressed (setFunctions() and setLenient()).
Do you know when a new stable release will be available?
Thanks very much,
Paul

Adrian Perez Jorge wrote:

> Dmitri Plotnikov wrote:
>
>> 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
>>  
>>
> Looking at the code in the CVS repository it seems the bug was fixed, 
> sorry.  I was using release 1.1 because jakarta commons site says it's 
> the stable release and there is no nightly nor milestone builds.  I 
> read in the source code that you were working in Xalan integration so 
> I thought CVS code was not adecuate for use in applications, but I 
> didn't test it :-(
>
> BTW jxpath is a very useful piece of sofware. Congratulations.
>
>
> ---------------------------------------------------------------------
> 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


Re: JXPath - shared Context

Posted by Adrian Perez Jorge <ap...@ignos.com>.
Dmitri Plotnikov wrote:

>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
>  
>
Looking at the code in the CVS repository it seems the bug was fixed, 
sorry.  I was using release 1.1 because jakarta commons site says it's 
the stable release and there is no nightly nor milestone builds.  I read 
in the source code that you were working in Xalan integration so I 
thought CVS code was not adecuate for use in applications, but I didn't 
test it :-(

BTW jxpath is a very useful piece of sofware. Congratulations.


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


Re: JXPath - shared Context

Posted by Dmitri Plotnikov <dm...@apache.org>.
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" <pm...@paychex.com>
To: "Jakarta Commons Users List" <co...@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


Re: JXPath - shared Context

Posted by Adrian Perez Jorge <ap...@ignos.com>.
Paul McClure wrote:

> 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.

Documentation says that ctx.getVariables() will return the variable pool 
associated with that context.  And different contexts can use different 
variable pool implementation, so variable storage is not unified in 
parent/childs contexts.  To look for a variable using client API instead 
of XPath you will have to navigate parent context by parent context, 
more or less like the non-client API method getVariablePointer() does.

> 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?

In commons-jxpath-1.1 ctx.isLenient() does not look in parent contexts, 
but current CVS code of jxpath does.

> thanks again for your help,
> Paul
>
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


Re: JXPath - shared Context

Posted by Paul McClure <pm...@paychex.com>.
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


Re: JXPath - shared Context

Posted by Adrian Perez Jorge <ap...@ignos.com>.
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