Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 73816 invoked from network); 18 Jun 2004 01:42:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 18 Jun 2004 01:42:47 -0000 Received: (qmail 40264 invoked by uid 500); 18 Jun 2004 01:42:53 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 40040 invoked by uid 500); 18 Jun 2004 01:42:51 -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 39204 invoked by uid 99); 18 Jun 2004 01:42:39 -0000 Received: from [204.127.198.39] (HELO rwcrmhc13.comcast.net) (204.127.198.39) by apache.org (qpsmtpd/0.27.1) with ESMTP; Thu, 17 Jun 2004 18:42:39 -0700 Received: from plotnix2500 (pcp02137893pcs.reston01.va.comcast.net[68.48.26.233]) by comcast.net (rwcrmhc13) with SMTP id <2004061801420101500t19r9e>; Fri, 18 Jun 2004 01:42:01 +0000 Message-ID: <009101c454d5$753e4940$0500a8c0@plotnix2500> From: "Dmitri Plotnikov" To: "Jakarta Commons Users List" References: Subject: Re: [jxpath] Custom NodePointer implementation Date: Thu, 17 Jun 2004 21:42:03 -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-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Simon, A possible alternative to using custom NodePointers in this situation could be a custom Function. Step 1. You implement a static method that does pretty much what you have in your example: public class MyFunc { public static Bar barByLang(Foo foo, String ln) { Language lang = (Language)mapping.get(ln); return foo.getBar(lang); } } Step 2. Register the MyFunc class with JXPathContext. Step 3. Use the function like this context.getValue("barByLang(/foo, 'fr')"); Also see http://jakarta.apache.org/commons/jxpath/users-guide.html#Extension%20Functions Now, if you insist on custom implementation of NodePointer, choose the right superclass. For example, BeanPropertyPointer might be the right one. I hope this helps - Dmitri ----- Original Message ----- From: "Simon Raess" To: "Jakarta Commons Users List" Sent: Thursday, June 17, 2004 5:32 PM Subject: [jxpath] Custom NodePointer implementation > hi > > I hope to get some ideas how to implement the following: > > Let's say I have a class Foo that can contain several Bar instances. > The Bar instances are accessed by a key, let's say a Language object. > So I have the following methods in Foo: > > public Bar getBar(Language l); > public Set getLanguages(); > > In the model of my application I don't want to have an absolute > ordering of Bar objects, that is I don't want to expose a method like > > public Bar getBar(int index); > > or similar. My idea is to have an external object impose an ordering on > the Bar objects (that is an ordering on languages). The point is, that > the ordering may change at runtime. What that basically means is, that > I'll have a mapping from a int key to a Language. For example the > mapping would contain: > > Language int key > de 0 > fr 1 > en 2 > > So my idea is to create a custom NodePointer that receives such a > mapping definition (so it knows about the ordering of languages). The > following xpath expression (with the above mapping definition) should > return the text with language fr: > > foo/bar[2] > > This should be translated (by the custom NodePointer) to a call to: > > int index = ...; > Foo foo = ...; > List mapping = ...; > Language lang = (Language)mapping.get(index); > Bar fr_bar = foo.getBar(lang); > > The following xpath > > foo/bar > > should probably be converted to something like > > List list = foo.getBar(); > > I'm still unconfident about the jxpath internals, so could please > somebody give me some pointers how I could achieve that? I'm I on the > right tracks? Which methods from NodePointer class must I override > (except the abstract ones, of course)? Is there a simple example that > shows how to implement a NodePointer for objects without using any > reflection, introspection, ...? Is there anything else I should > consider? Please ask me if I missed some important information! > > best regards > Simon > > > --------------------------------------------------------------------- > 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