Title: SaxStore: an aspect oriented persistence library for Java based on SAX events
1SaxStore an aspect orientedpersistence library
for Javabased on SAX events
- Riccardo Solmi
- University of BolognaMay 2001
2Summary
- SaxStore features and usage scenarios
- Choice of a perspective
- XML representation
- Accessing XML data
- Accessing application objects
- SaxStore persistence management
3Features
- SaxStore provides a mechanism to map arbitrary
Java objects into a stream of SAX events and
backward. - SAX events can be serialized to an XML stream and
saved to disk or transmitted across a network. - XSLT transformations (translets) can be used to
support versioning, stylesheet application and
conformance to a given XML Schema.
4Long-term persistence scenario
Runtime Application objects
Stylesheet 1.0 to 1.1
Stylesheet 1.1 to 1.2
Stylesheet 1.2 to 1.1
Stylesheet 1.1 to 1.0
SaxStore
XSLT compiler
XSLT compiler
XML serializer
XSLT compiler
XSLT compiler
XML parser
XML
- Compression
- Integrity signature
- Given XML Schema
5Representation scenario
Runtime Application objects
Stylesheet for XSLFO representation
XSLFO representation
SaxStore
XSLT compiler
- Dynamic form filling
- XSLFO, XHTML, SVG,
6Data exchange scenario
Runtime Application objects
Runtime Application objects
Stylesheet transformation to a given XML Schema
Stylesheet transformation from a given XML Schema
Schema instance
SaxStore
XSLT compiler
XSLT compiler
SaxStore
- Given XML Schema
- Sun XMLB is better (may be)
7Persistence
- To preserve something of the current execution
state between successive program runnings. - To store a (runtime) graph of objects to a non
volatile memory and to reconstruct an equivalent
graph of objects.
8Requirements
- Exchangable and neutral data format(i.e. XML)
- Almost automatic but customizable
- Large graphs of objects
- Versioning
- Performance
9Goals
- Powerful and easy to use as Java Serialization
API - Support short-term long-term persistence
- Data exchange between running applications
- Document format for successive executions
- Decouple producers and consumers
- Support distributed applications
10Persistence and Java
- Java has not yet a standard persistence library
- Java Serialization API provides only short term
persistence and was introduced to support RMI. - SUN is working only on projects that doesnt
satisfy my requirements.
11Runtime and persistent representations
- Both runtime and persistent representations
should be user defined. - Runtime. To implement efficiently application
algorithms - Persistent. To support interoperability of
applications and loosly coupled distributed
systems
12Choice of a perspective
- An (almost) automatic transformation between two
unconstrained and unrelated forms is not
possible! - Two alternative points of view are suitable
- Java side
- XML side
My classes
XML
My XML
custumizable
manual
My classes
Java classes
My XML
auto
manual
13Data Binding focus on XML side
- Data Binding (JSR-031) Bind Java objects to an
XML document. Compiles an XML Schema to Java
classes with specific accessor and mutator
methods that affect the underlying XML document. - Writing the XML Schema from application classes
(or even from scratch) is expansive. - Writing the code, in application classes, that
store/retrive data to/from the graph of generated
classes is not trivial. - Generated classes requires additional memory
14SaxStore focus on Java side
- In many applications the format of XML
representation doesnt matter. - Versioning support is the major requirement.
- An easy to understand XML representation is
enough. - Customization is required only for a very small
number of classes.
15SaxStore XML representation
- Is an XML-Schema instance.
- Objects are mapped to elements
- Objects have an id attribute with a unique value
and a xsitype attribute with the runtime type. - Fields are mapped to nested elements with the
same name (because attributes are not
referenceable) - Objects already mapped are represented by an
element with an idref attribute.
16Accessing XML data
- Callbacks (SAX) Is an event-driven model the
parsing of an XML document trigger callback
methods. - Trees (DOM) The parsing of an XML document
create a tree structure manageable with a set of
standard methods. - SaxStore is based on SAX2 events.
17Accessing application objects
- Reflection
- State exposition
- Field level accessor and mutator methods
- Object level persistence methods
- Aspect
18Persistence vs encapsulation
- Reflection violates encapsulation and performs
poorly. - Field level state exposition make encapsulation
useless. - Object level state exposition alone is a weak
solution and requires excessive work. - Aspects preserve encapsulation while retaining
instance methods performance.
19SaxStore persistence management
- User defined
- XmlSerializable interface (source required)
- Custom aspect or single classes
- XmlSerializer interface or adapter class
- Singletons
- Part objects
- Automatic
- AspectWriter preprocessor (source required)
- Reflective XmlSerializer
20Future works
- Produce an XML-Schema
- Support XML-Schema constraints
- Generation of persistence code based on reverse
engineering of classes that uses Java
serialization API - Integration with distributed API