ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dmi...@apache.org>
Subject Re: [RT] [myrmidon] Property evaluation
Date Mon, 22 Apr 2002 23:27:43 GMT
Peter,

You might want to look into using JXPath for this.

I did not quite understand your example, but consider the following
variation:

   class MyDataStructure
   {
      Map items = new HashMap();
   }

   MyDataStructure mds = new MyDataStructure();
   mds.items.put( "item1" , "some text");
   mds.items.put( "item2" , "other text" );
   mds.items.put( "item3" , "third text");

   getContext().setProperty( "mds", mds );


The syntax of the xpath would be:

    "mds/items[@name='item1']"
or
    "mds/items/item1"

both syntax structures are accepted for maps as long as the key is a proper
identifier.  Both will return "some text"

Better yet, put the key in a separate property that can be accessed by
JXPath

    getContext().setProperty("currentItem", "item2");

Then you can use expressions like:

    "mds/items[@name = currentItem]".

Yet another alternative would be to use an XPath variable for indexing:

    context.defineVariable("currentItem", "item2");
    value = context.getValue("mds/items[@name=$currentItem]");

The JXPath home is http://jakarta.apache.org/commons/jxpath.html  We are in
the processes of setting up that home page. If it does not work, go to the
backup: http://www.plotnix.com/jxpath/docs/index.html

Thanks to Jeff Turner for bringing this discussion to my attention.

- Dmitri Plotnikov
dmitri@apache.org

> ----- Forwarded message from Peter Donald
> <peter@apache.org> -----
>
> Date: Sun, 21 Apr 2002 14:13:44 +1000
> From: Peter Donald <peter@apache.org>
> Subject: [RT] [myrmidon] Property evaluation
> To: ant-dev@jakarta.apache.org
> X-Mailer: KMail [version 1.4]
>
> Hi,
>
> I have just went and look at some of the other build
> tools emerging and they
> all share one common characteristeric. They all have
> a richer property access
> expressions. What do I mean? Consider the following
> case;
>
> class MyDataStructure
> {
>   Vector items = new Vector();
> }
>
> MyDataStructure mds = new MyDataStructure();
> mds.items.add( "item1" );
> mds.items.add( "item2" );
> mds.items.add( "item3" );
>
> getContext().setProperty( "mds", mds );
>
> The above creates a complex object and places in
> property store. However under
> the current model there is no way to access the
> "insides" of the mds property
> - at least not without writing another task. I was
> thinking that it may be a
> nice idea to add a simple path expression library on
> top of our property
> evaluation system so that you could do something
> like
>
> <echo message="The following should evaluate to the
> string 'item'"/>
> <echo message="${mds/items['item1']}"/>
>
> We could create our own expression language or clone
> it from an existing
> project (maybe velocity). However I believe there is
> an XPath library at
> Apache that is meant to be damn fine (Jaxen in
> commons IIRC) that we could
> use (Not sure I personally haven't looked at it but
> it is meant to be all
> good).
>
> Anyways I haven't actually prototyped this but I
> thought it would be neat to
> do. Anyone who wants to have a play should feel free
> to do so ;)
>
> --
> Cheers,
>
> Peter Donald



--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message