commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul McClure" <pmccl...@paychex.com>
Subject Re: JXPath question
Date Tue, 04 May 2004 16:24:14 GMT
using a function in a path does not appear to work. This 
        ctx.getValue("cs[1]/vt:asOf('e', $today)");
results in this error:
        Invalid XPath: 'cs[1]/vt:asOf(\'e\', $today)'. Syntax error after: 'cs[1]/vt:a' 

Also: I am not having any luck using my function when set in a parent 
context.
If I set the function on the same context that I call getValue() on, it 
works ok - but if I try to set in on a parent context I get this:

JXPathContext sharedContext = JXPathContext.newContext(null);
FunctionLibrary flib = new FunctionLibrary();
flib.addFunctions(new ClassFunctions(JXPathTests.AsOf.class, "vt"));
sharedContext.setFunctions(flib);
sharedContext.setLocale(Locale.US);
sharedContext.getVariables().declareVariable("today", today);
JXPathContext ctx = JXPathContext.newContext(sharedContext, a);

org.apache.commons.jxpath.JXPathException: Undefined function: vt:asOf
    at 
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getFunction(JXPathContextReferenceImpl.java:614)
    at 
org.apache.commons.jxpath.ri.axes.RootContext.getFunction(RootContext.java:146)
    at 
org.apache.commons.jxpath.ri.compiler.ExtensionFunction.computeValue(ExtensionFunction.java:130)
    at 
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:287)

thanks for your help,

Dmitry Sklyut wrote:

>I haven't tried doing it that way.
>Give it a try.  Let us know
>
>Thanks
>
>-----Original Message-----
>From: Paul McClure [mailto:pmcclure@paychex.com]
>Sent: Tuesday, May 04, 2004 10:42 AM
>To: Jakarta Commons Users List
>Subject: Re: JXPath question
>
>
>Thanks for the reply Dmitry,
>    Is it possible to use an extension function in a path, like this:
>          getValue("A / B / vt:asOf(C, $today) / D)
>
>My graph would have paths like this:
>          A / B / C / D / E / F
>                      |
>                 C is not a normal Java Bean property - but must be 
>accessed as 'getCAsOf(Date)' - which returns a C object that has a D 
>property that is a normal Java Bean Property, and so on...
>
>thanks,
>Paul
>
>Dmitry Sklyut wrote:
>
>  
>
>>Take a look at "Custom Extension Functions":
>>
>>Collections of custom extension functions can be implemented as Functions
>>objects or as Java classes, whose methods become extenstion functions. 
>>
>>Let's say the following class implements various formatting operations: 
>>
>>                                                                      
>>public class Formats {
>>   public static String date(Date d, String pattern){
>>       return new SimpleDateFormat(pattern).format(d);
>>   }
>>   ...
>>}
>>We can register this class with a JXPathContext: 
>>
>>                                                                      
>>context.setFunctions(new ClassFunctions(Formats.class, "format"));
>>...
>>
>>context.getVariables().declareVariable("today", new Date());
>>String today =
>>    (String)context.getValue("format:date($today, 'MM/dd/yyyy')");
>>You can also register whole packages of Java classes using
>>    
>>
>PackageFunctions.
>  
>
>>Also, see FunctionLibrary , which is a class that allows you to register
>>multiple sets of extension functions with the same JXPathContext. 
>>
>>
>>-----Original Message-----
>>From: Paul McClure [mailto:pmcclure@paychex.com]
>>Sent: Tuesday, May 04, 2004 8:10 AM
>>To: commons-user@jakarta.apache.org
>>Subject: JXPath question
>>
>>
>>I am using JXPath to access an object graph and it is working well in 
>>most cases. My problem is that my graph has some objects that are only 
>>valid for a certain period of time. So these properties are accessed by 
>>date - for example, a property 'foo' would have the getter 
>>getFooAsOf(Date dt). There are many types of objects in the graph, but 
>>all of them subclass a common base class. They all follow the naming 
>>convention above.
>>Has anybody used JXPath for this kind of situation - I have not found a 
>>way to add the "ValidTime" properties. I'm looking at a custom 
>>JXPathBeanInfo class but not getting very far...
>>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
>>
>>
>> 
>>
>>    
>>
>
>
>-----------------------------------------
>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.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message