Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Prism is a data representation mechanisms that allows to present data in several formats and the same time.

The goal of prism is to represent the data in a format that is usable in a broad variety of situations. While the are represented in a structure of ordinary Java objects, they can be represented as DOM tree, Java Maps, serialized to and parsed from XML and JSON, etc.

TODO: native prism representation (Java)

XML representation
<user>
  <name>jack</name>
  <employeeType>Captain</employeeType>
  <employeeType>Pirate</employeeType>
  <activation>
    <enabled>true</enabled>
  <activation>
</user>
JSON representation
{
  "name": "jack",
  "employeeType": [ "Captain", "Pirate" ],
  "activation": {
    "enabled": true,
  }
}

Live Data

Prism objects are more or less ordinary data structures in Java. They can be accessed using a native Prism interface (API), but the same data can also be accessed by variety of other interfaces (JAXB, DOM, ...). The unique feature of prism is that the data are not transformed to these formats but real live data are presented. For example if a bean property is set by invoking JAXB setter the change is immediately reflected to the underlying prism data model. The next call to DOM interface will return the new value of the property.

Live data example
// Set the "fullName" property using a JAXB interface
UserType userType = ....
userType.setFullName("Jack Sparrow");

// Invoking native Prism interface to read fullName, returns "Jack Sparrow"
PrismObject<UserType> userPrism = ....
String fullName = userPrism.findProperty(new QName(NS_C, "fullName").getValue().getValue();

// Invoking DOM interface to read the fullName, returns "Jack Sparrow"
Element fullnameElement = ....
String fullName = fullnameElement.getTextContent()

Extensible

TODO: extension, namespaces

Prism Native Data Structures

Full article: Prism Data Structures

Each prism data structure is constructed from items. The items can be of three types:

  • Property is an item that contains useful value. It usually contains primitive data types such as string, integer or date. But it may also contain complex data structures. Property is the "atomic" unit of information, it cannot be divided to smaller parts. Property values can be added, deleted or replaced, but only a complete value. Prism does not care for anything smaller than a property.
  • Reference points to a prism object. It is used to represent relationship between prism objects.
  • Container contains other items: properties, references or other containers. Containers build the structure of prism data.

Prism objects are special cases of prism containers. Although prism data can be represented without objects, objects give a kind of order to the data. Objects are supposed to be stand-alone meaningful sets of prism data. Each object has its unique identifier called simple object identifier or OID for short. Prism references are used to point to objects which is a method to create complex data structures.

Any prism item (except object) may have multiple values. Such values are unordered. Limiting the values to unordered makes it much easier to work with relative changes.

Definition and Schema

Full article: Prism Schema

Each prism item has a definition. The definition is defined by the schema or is determined at runtime. The definition tells the type of the item, e.g. whether it is string, integer or a date. This is necessary to present the same data in various formats. E.g. to be able to correctly process write of the data using a DOM interface the prism must know that it is date to correctly parse it from the DOM string representation.

The presence of a schema at runtime has yet another advantage: code can be generated from the schema. This is used by the prism JAXB code generator which generates data representation that provide a simple Java Bean interface. Having a data model generated and compiled is a huge advantage for most systems. E.g. compiler checks are making the development cycle much shorter and it makes refactoring much more reliable.

Currently Prism Schema is defined in XML Schema Defenition (XSD) language with custom annotations (but that may change in the future).

Dynamic Schemas

On of the unique features of prism is support for runtime and dynamic schemas.

Runtime schema is a static schema definition that is not available at compile time. It may be available as assembly time or even at runtime. It usually takes form of XSD files that are loaded at system start. As such schema is not available as compile time it cannot be used to generate compiled code. But except for that the runtime schema behaves almost the same as compile time schema: it is used to parse and validate data when parsing prism items from XML, to serialize data, etc.

Dynamic schema is schema that is not fixed, not even in runtime. E.g. there may be a container that can store items of any type, even each instance of the container may have different items of different types. Prism supports such schema and still correctly maintains definitions for such items end-to-end. E.g. it parses the data from the source format and creates appropriate definition. The definition travels with the item though the system. If the data are serialized, the definition is serialized with the data (if possible), e.g. by using the XML xsi:type runtime type specification.

TODO: parsing state (raw element)

Deltas

TODO:

Prism Interfaces

Prism object are accessible using several interfaces. The details are described in following sections. Yet there are few concepts that are common to all interfaces.

Prism object can be switched from one interface to the other. Methods to do that start with prefix as, e.g. asObjectable(). Such method return the same object represented by the mechanism of the other interface. The two objects still refer to the same data, therefore changing the content of one object is immediately reflected to the other.

Interface switching example
PrismObject<UserType> userPrism = ....;                                        // Native Prism API
UserType userType = userPrism.asObjectable();                                  // Switch to JAXB generated class

userType.setFullName("Jack Sparrow");                                          // Sets the "fullName" property

String fullName = 
  userPrism.findProperty(new QName(NS_C, "fullName").getValue().getValue();    // Returns "Jack Sparrow"

Prism context (PrismContext) is an umbrella class that maintains the instances needed for operation of the whole prism library. E.g. the prism context maintains registered schemas, initialized JAXB context (if compile-time classes are used) and so on. Prism context is present in all prism items (as transient member), therefore it usually do not need to be provided for most of the operations. However, some operations require prism context as an explicit parameter or are invoked directly on a prism context. This include mostly parsing and serialization operations and construction of a new prisms.

Native Prism API

Native Prism API is ideal for dynamic manipulation of the data structures. It is also the only API that exposes all the functions of Prism library.

TODO

Most prism classes implement the clone() method, therefore the prism data objects are easily clonnable.

Prism items, values and definitions are Serializable. However, there is a catch. Prism context is not serializable and it is a transient member of prism items and definitions. Therefore deserialized prism items and definitions may not be fully operational. The call to revive(...) method is required after deserialization to make the prisms work as expected.

JAXB Generated Beans

Prism JAXB interface maintains the same looks and feel as usual JAXB generated classes. But instead of plain annotated Java Beans the Prism JAXB compiler plug-in generates classes that are just proxies for real Prism classes. This implements the immediate propagation of changes: the data are always stored only in native prism data structures. Any JAXB classes are just relaying the calls to the native classes. Any get is getting the data from prisms, any set is applied directly to prisms.

TODO: schema-full and schema-less JAXB operation

DOM

The DOM Prism API has now only a very rough implementation in a form of proof of concept. It is not yet finished.

Parsing and Serialization

In addition to live data interfaces prism data can be parsed from and serialized to a variety of data formats.

Data Format

Parsing

Serialization

XML

Yes (DOM, StAX planned soon)

Yes (DOM)

JSON

Planned

Planned

See Also

  • No labels