Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 37765 invoked from network); 4 May 2004 16:25:20 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 4 May 2004 16:25:20 -0000 Received: (qmail 39430 invoked by uid 500); 4 May 2004 16:25:07 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 39405 invoked by uid 500); 4 May 2004 16:25:06 -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 39374 invoked from network); 4 May 2004 16:25:05 -0000 Received: from unknown (HELO paychex.com) (141.123.100.8) by daedalus.apache.org with SMTP; 4 May 2004 16:25:05 -0000 Message-ID: <4097C3AE.1000100@paychex.com> Date: Tue, 04 May 2004 12:24:14 -0400 From: "Paul McClure" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: JXPath question References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------020708050405050105000307" 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 --------------020708050405050105000307 Content-Type: text/plain; charset="us-ascii"; format="flowed" Content-Transfer-Encoding: 7bit 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. --------------020708050405050105000307--