This example explain how to apply X-O lite XML serialization/deserialization to a complex recursive model.
The model for this example is a boolean expression like:
(a and (true or b)) or (not (a and c)))
for this example, he expressions are kept simple, they are based on few building blocks:
This expression above (as any expression) can be expressed as a syntactic tree:
This syntactic tree naturally maps to a XML tree:
<?xml version="1.0"?> <or xmlns="xo-lite.sf.net/examples/expression"> <and> <variable name="a" /> <or> <true /> <variable name="b" /> </or> </and> <not> <and> <variable name="a" /> <variable name="c" /> </and> </not> </or>
In the scope of this example, the boolean expressions are composite of java objects with following behaviour:
The complete source code of this example is located in the:
xo-lite-1.0/src-projects/xo-lite-examples/src/main/java/net/sf/xolite/expression/xolite
directory inside the xo-lite-1.0-all.zip or xo-lite-1.0-all.tgz distribution archive.
To build and run all the examples:
Serializing/deserializing recursive models (the 'composite' design pattern) is done naturally with X-O lite. In addition, the inheritance between classes can easily be used to simplify the parsing (in this case, the "And", "Or" and "Not" operators doesn't have to define parsing as they inherit everything needed from the CompositeOperator class).