pivot.wtkx
Class WTKXSerializer

java.lang.Object
  extended by pivot.wtkx.WTKXSerializer
All Implemented Interfaces:
Serializer<Object>, Bindable.ObjectHierarchy

public class WTKXSerializer
extends Object
implements Serializer<Object>, Bindable.ObjectHierarchy

Loads an object hierarchy from an XML document.

Author:
gbrown

Nested Class Summary
 class WTKXSerializer.NamedObjectDictionary
          Dictionary used for named object lookup.
 
Field Summary
static String ID_ATTRIBUTE
           
static String INCLUDE_RESOURCES_ATTRIBUTE
           
static String INCLUDE_SRC_ATTRIBUTE
           
static String INCLUDE_TAG
           
static String MIME_TYPE
           
static char OBJECT_REFERENCE_PREFIX
           
static char RESOURCE_KEY_PREFIX
           
static String SCRIPT_SRC_ATTRIBUTE
           
static String SCRIPT_TAG
           
static char URL_PREFIX
           
static String WTKX_PREFIX
           
 
Constructor Summary
WTKXSerializer()
           
WTKXSerializer(Resources resources)
           
 
Method Summary
 String getMIMEType(Object object)
          Returns the MIME type of the data read and written by this serializer.
 WTKXSerializer.NamedObjectDictionary getNamedObjects()
          Retrieves the named objects dictionary.
<T> T
getObjectByID(String id)
          Retrieves a named object.
 Resources getResources()
           
<T> T
getRootObject()
          Retrieves the root object of the WTKX hierarchy.
 WTKXSerializer getSerializerByID(String id)
          Retrieves a included serializer by its ID.
 Object readObject(InputStream inputStream)
          Reads an object from an input stream.
 Object readObject(String resourceName)
           
 Object readObject(URL location)
           
 void writeObject(Object object, OutputStream outputStream)
          Writes an object to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_PREFIX

public static final char URL_PREFIX
See Also:
Constant Field Values

RESOURCE_KEY_PREFIX

public static final char RESOURCE_KEY_PREFIX
See Also:
Constant Field Values

OBJECT_REFERENCE_PREFIX

public static final char OBJECT_REFERENCE_PREFIX
See Also:
Constant Field Values

WTKX_PREFIX

public static final String WTKX_PREFIX
See Also:
Constant Field Values

ID_ATTRIBUTE

public static final String ID_ATTRIBUTE
See Also:
Constant Field Values

INCLUDE_TAG

public static final String INCLUDE_TAG
See Also:
Constant Field Values

INCLUDE_SRC_ATTRIBUTE

public static final String INCLUDE_SRC_ATTRIBUTE
See Also:
Constant Field Values

INCLUDE_RESOURCES_ATTRIBUTE

public static final String INCLUDE_RESOURCES_ATTRIBUTE
See Also:
Constant Field Values

SCRIPT_TAG

public static final String SCRIPT_TAG
See Also:
Constant Field Values

SCRIPT_SRC_ATTRIBUTE

public static final String SCRIPT_SRC_ATTRIBUTE
See Also:
Constant Field Values

MIME_TYPE

public static final String MIME_TYPE
See Also:
Constant Field Values
Constructor Detail

WTKXSerializer

public WTKXSerializer()

WTKXSerializer

public WTKXSerializer(Resources resources)
Method Detail

getResources

public Resources getResources()

readObject

public Object readObject(String resourceName)
                  throws IOException,
                         SerializationException
Throws:
IOException
SerializationException

readObject

public Object readObject(URL location)
                  throws IOException,
                         SerializationException
Throws:
IOException
SerializationException

readObject

public Object readObject(InputStream inputStream)
                  throws IOException,
                         SerializationException
Description copied from interface: Serializer
Reads an object from an input stream.

Specified by:
readObject in interface Serializer<Object>
Parameters:
inputStream - The data stream from which the object will be read.
Returns:
The deserialized object.
Throws:
IOException
SerializationException

writeObject

public void writeObject(Object object,
                        OutputStream outputStream)
                 throws IOException,
                        SerializationException
Description copied from interface: Serializer
Writes an object to an output stream.

Specified by:
writeObject in interface Serializer<Object>
Parameters:
object - The object to serialize.
outputStream - The data stream to which the object will be written.
Throws:
IOException
SerializationException

getMIMEType

public String getMIMEType(Object object)
Description copied from interface: Serializer
Returns the MIME type of the data read and written by this serializer.

Specified by:
getMIMEType in interface Serializer<Object>
Parameters:
object - If provided, allows the serializer to attach parameters to the returned MIME type containing more detailed information about the data. If null, the base MIME type is returned.

getSerializerByID

public WTKXSerializer getSerializerByID(String id)
Retrieves a included serializer by its ID.

Parameters:
id - The ID of the serializer, relative to this loader. The serializer's ID is the concatentation of its parent IDs and its ID, separated by periods (e.g. "foo.bar.baz").
Returns:
The named serializer, or null if a serializer with the given name does not exist.

getRootObject

public <T> T getRootObject()
Retrieves the root object of the WTKX hierarchy.

Specified by:
getRootObject in interface Bindable.ObjectHierarchy
Type Parameters:
T - The type of the object to return.
Returns:
The root object, or null if this serializer has not yet read an object from an input stream.

getObjectByID

public <T> T getObjectByID(String id)
Retrieves a named object.

Specified by:
getObjectByID in interface Bindable.ObjectHierarchy
Type Parameters:
T - The type of the object to return.
Parameters:
id - The ID of the object, relative to this loader. The object's ID is the concatentation of its parent IDs and its ID, separated by periods (e.g. "foo.bar.baz").
Returns:
The named object, or null if an object with the given name does not exist.

getNamedObjects

public WTKXSerializer.NamedObjectDictionary getNamedObjects()
Retrieves the named objects dictionary. The names are relative to this loader and can reference objects located in nested includes by using period-separated path strings (e.g. "foo.bar.baz").

Returns:
The read-only named objects dictionary.