Java Link

See which of your colleagues or former colleagues are already on Java Link: Check out the Contact Finder
News »Browse Articles » Xvantage - Yet Another Xml Serializer!
0
Vote Vote

Xvantage - Yet Another Xml Serializer!

Views 0 Views    Comments 0 Comments    Share Share    Posted 01-10-2009  
Why yet another xml tool?

To make it clear: At the moment xvantage is in its early stage (one week old) and I hacked it down in some hours of my spare time. So it is not a fully fledged and bugless solution like the other ones should be.

But it has some new ideas included to make the serialization as easy as XStream and XmlEncoder, but to make the xml checkable through an xsd file. The advantage of a valid xml is first of all: “then you know all is fine” and second “It is nice to read and editable from a person!”. The latter one was very important for me and is really important for xml configuration files.

Apache Digester was another candidate but the set up was relative complex and the dependencies are to big for me. And last but not least: you need an additional, not further developed library (Betwixt) to make writing working too! So xvantage seems to solve at least these two problems: it is small and it can write xml from your POJOs and read it back.

How would it look like to write my objects?
view source
print?
1.// Create a data pool with all your POJOs you want to serialize
2.DataPool pool = new DefaultDataPool();
3.Map map = pool.getData(SimpleObj.class);
4.map.put(0L, new SimpleObj("test"));
5.StringWriter writer = new StringWriter();
6.xadv.mount("/path/", SimpleObj.class);
7.xadv.saveObjects(pool, writer);

The resulting xml looks like
view source
print?
1.
2.
3.
4.test
5.
6.

And reading?
view source
print?
01.// get xml from somewhere
02.StringReader iStream = new StringReader(
03. "" +
04. " test" +
05. "");
06.
07.// mount to /path/ with an alternative name `myobject` instead of the default which would be simpleObj
08.// this is the preferred way for mounting, because otherwise class refactoring results in different xml
09.xadv.mount("/path/myobject", SimpleObj.class);
10.DataPool pool = xadv.readObjects(iStream);
11.
12.// get the first SimpleObj and check the name
13.SimpleObj obj = pool.getData(SimpleObj.class).values().iterator().next();
14.assertEquals("test", obj.getName());
Why does xvantage needs the DataPool interface?

Without it it couldn’t handle references properly. And now with this DataPool interesting use cases arises, e.g. where parts of an object graph should be refreshed through xml (imagine you grab some objects as xmls through HTTP GET …)

Why do we need to mount classes?

To mount a class means: xvantage should track every occurance of that class as references and should NOT nest the object within other objects.

This looks interesting, but does it works for more complex objects?

Yes, it should. I could successfully embed this in my TimeFinder project, where I tried to persist 4 entities (some of them with hundreds of objects and several references) and read them successfully back. Objects which are not mounted explicitly will be nested within mounted objects like in xstream.
...................

Source:
http://java.dzone.com/articles/xvantage-%E2%80%93-yet-another-xml
0
Vote  Vote
Enter your comment:
No Comments For This News

Search News

What's the News?

Post a link to something interesting from another site, or submit your own original writing for the Java community to read.

Most Popular News

Most Recent User Submitted News