commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam J Chesney" <>
Subject [JXPath] creating sequences
Date Tue, 04 Feb 2003 13:41:56 GMT

I am new to JXPath but it looks great, thanks for all your hard work. I have just been playing
around with it a little as I would like to use it in a new project that I am working on. I
wanted to implement a generic Factory to create objects and I ran into a small snag. I just
wanted to run this by you. My GenericFactory (attached) is a bit rough around the edges but
it automatically creates properties using reflection to find the appropriate set method on
the parent object, and then instantiates an instance of the appropriate class (parameter type).
This works fine for straight beans but using the same method for sequences causes a problem
because atm it is not possible to determine whether or not the target property is a sequence
or not. If you can determine that you are creating a sequence then it is possible (in some
circumstances) to determine the type of the objects to be added to the newly created sequence,
and to add them during the construction of the sequence property. This won't work for generic
Collections, but it will work for custom sequences that implement List, which is what I am
using (Castor based beans). 

By changing line 178 in


     int inx = (index == WHOLE_COLLECTION ? 0 : index);


     int inx = (index == WHOLE_COLLECTION ? -1 : index);

I am now able to determine whether or not the target property for construction is a sequence
and is accessed using an index and I can therefore, in the factory, create the required number
of objects. Previously, it was impossible to tell the difference between /myList and /myList[1]
because the index passed to the Factory in both cases is 0.

So I can now execute calls like:

context.createPathAndSetValue("/myList[2]/name", "harry");

Even though myList is null to start with, the GenericFactory can determine that myList is
a sequence and it can create 2 objects to add into it after creating and sequence and assigning
it to the root context.

Anyway, I don't think this change should negatively effect anyone and so I thought that maybe
you could add it to the main tree. If it's not possible, then no problem, I can maintain my
own version. I guess a change like this could potentially cause problems if the Factory coding
was a bit "lazy".

Anyway, once agin, thanks for this kewl tool.

Warm regards,

Adam Chesney.

Tel:   (+44) 117 908 1254 (Direct)
Mobile (+44) 7780 962 961
This communication is intended solely for the addressee and is confidential.
If you are not the intended recipient, any disclosure, copying, distribution
or any action taken or omitted to be taken in reliance on it, is prohibited
and may be unlawful.
Although this e-mail and any attachments are believed to be free of any
virus, or any other defect which might affect any computer or IT system into
which they are received and opened, it is the responsibility of the
recipient to ensure that they are virus free and no responsibility is
accepted by Multicom Products Limited for any loss or damage arising in any
way from receipt or use thereof.

View raw message