Hi Stephen,
> What tools/approaches can I use to modify all of my XML files to
> include the new attribute 'c' with a certain value
> say 'newattrvalue'.
You can modify XML with XSLT; tho here you may be better off doing it
within the class.
Both are discussed in the JSX manual:
http://jsx.org/pdf/JSXmanual.pdf
XSLT
----
The JSX manual (see above, or link at top of www.jsx.org/support.html)
has examples of accessing the JSX XML format in terms of classes and
fields (pp.20-25).
Within the class
----------------
But for this case, I would suggest putting this evolution code within
the classes themselves - this is because that is where the evolution
occurred in the first place, and the person making the change will
know what value to use.
JSX uses the same hooks as JOS (Java Object Serialization - standard
part of java, in java.io.*) for this kind of evolution. It enables
your objects to look at the fields that are in the stream, and if
something is missing, to supply the correct value. (you could also do
this by testing for null, 0 or false, but then you can't distinguish
between the field being absent, or the field being present and
actually having that value).
This is discussed on page 10 of the JSX manual - but because it is the
same as JOS, there are also several tutorials about it.
"serialPersistentFields" is probably the best search term for this.
> I need this tool to be fairly powerful but easy to use because
> we are in a commercial environment and can add/remove
> complex attributes from existing classes that are not of
> simple types String, int, boolean, etc.
Adding complex types is probably simpler to do within the classes.
You can also do it with XSLT and XML: I'd suggest generating the XML
you need (by writing code to create the object you need, and then
serializing it), and then writing an XSLT script to insert it into the
XML for each object of that class.
Deleting is automatic, because when reading, JSX silently discards a
value if its field does not appear in the current version of the class
(same as JOS).
cheers,
Brendan
--- In JSX-ideas@yahoogroups.com, "Stephen Kurlow" <skurlow@...> wrote:
>
> Lets say for example I have:
>
> class foo1 {
> String a;
> String b;
> }
>
> and I have literally hundreds of different objects of class foo1
> serialised to different XML files. Now I need to modify class foo1 to
> include a new attribute so its class definition is now:
>
> class foo1 {
> String a;
> String b;
> String c;
> }
>
> What tools/approaches can I use to modify all of my XML files to
> include the new attribute 'c' with a certain value say 'newattrvalue'.
> I need this tool to be fairly powerful but easy to use because we are
> in a commercial environment and can add/remove complex attributes from
> existing classes that are not of simple types String, int, boolean, etc.
>
> Thanks,
> Stephen
>