org.apache.pivot.wtkx
Class WTKXSerializer

java.lang.Object
  extended by org.apache.pivot.wtkx.WTKXSerializer
All Implemented Interfaces:
Dictionary<String,Object>, Serializer<Object>

public class WTKXSerializer
extends Object
implements Serializer<Object>, Dictionary<String,Object>

Loads an object hierarchy from an XML document.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary
Dictionary.Pair<K,V>
 
Field Summary
static String DEFINE_TAG
           
static String ID_ATTRIBUTE
           
static String INCLUDE_ASYNCHRONOUS_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_LANGUAGE_ATTRIBUTE
           
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
<T> void
bind(T t, Class<? super T> type)
          Applies WTKX binding annotations to an object.
 boolean containsKey(String name)
          Tests the existence of a key in the dictionary.
 Object get(String name)
          Retrieves a named object.
 int getLineNumber()
          Returns the line number of the element currently being processed.
 URL getLocation()
          Returns the location of the WTKX currently being processed.
 String getMIMEType(Object object)
          Returns the MIME type of the data read and written by this serializer.
 Resources getResources()
           
 Object getRoot()
          Retrieves the root of the object hierarchy most recently processed by this serializer.
 WTKXSerializer getSerializer(String id)
          Retrieves an include serializer by its ID.
 String getTagName()
          Returns the name of the element currently being processed.
 ListenerList<WTKXSerializerListener> getWTKXSerializerListeners()
           
 boolean isEmpty()
          Tests the emptiness of the dictionary.
 Object put(String id, Object value)
          Sets the value of the given key, creating a new entry or replacing the existing value.
 Object readObject(Class<?> baseType, String resourceName)
           
 Object readObject(InputStream inputStream)
          Reads an object from an input stream.
 Object readObject(Object baseObject, String resourceName)
           
 Object readObject(String resourceName)
           
 Object readObject(URL location)
           
 Object remove(String id)
          Removes a key/value pair from the map.
 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

INCLUDE_ASYNCHRONOUS_ATTRIBUTE

public static final String INCLUDE_ASYNCHRONOUS_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

SCRIPT_LANGUAGE_ATTRIBUTE

public static final String SCRIPT_LANGUAGE_ATTRIBUTE
See Also:
Constant Field Values

DEFINE_TAG

public static final String DEFINE_TAG
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(Object baseObject,
                         String resourceName)
                  throws IOException,
                         SerializationException
Throws:
IOException
SerializationException

readObject

public Object readObject(Class<?> baseType,
                         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.

get

public Object get(String name)
Retrieves a named object.

Specified by:
get in interface Dictionary<String,Object>
Parameters:
name - The name of the object, relative to this loader. The object's name is the concatenation 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. Use containsKey(String) to distinguish between the two cases.

put

public Object put(String id,
                  Object value)
Description copied from interface: Dictionary
Sets the value of the given key, creating a new entry or replacing the existing value.

Specified by:
put in interface Dictionary<String,Object>
Parameters:
id - The key whose value is to be set.
value - The value to be associated with the given key.
Returns:
The value previously associated with the key.

remove

public Object remove(String id)
Description copied from interface: Dictionary
Removes a key/value pair from the map.

Specified by:
remove in interface Dictionary<String,Object>
Parameters:
id - The key whose mapping is to be removed.
Returns:
The value that was removed.

containsKey

public boolean containsKey(String name)
Description copied from interface: Dictionary
Tests the existence of a key in the dictionary.

Specified by:
containsKey in interface Dictionary<String,Object>
Parameters:
name - The key whose presence in the dictionary is to be tested.
Returns:
true if the key exists in the dictionary; false, otherwise.

isEmpty

public boolean isEmpty()
Description copied from interface: Dictionary
Tests the emptiness of the dictionary.

Specified by:
isEmpty in interface Dictionary<String,Object>
Returns:
true if the dictionary contains no keys; false, otherwise.

getRoot

public Object getRoot()
Retrieves the root of the object hierarchy most recently processed by this serializer.

Returns:
The root object, or null if this serializer has not yet read an object from an input stream.

getSerializer

public WTKXSerializer getSerializer(String id)
Retrieves an include 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.

getTagName

public String getTagName()
Returns the name of the element currently being processed.

Returns:
The name of the element currently being processed, or null if no element is currently being processed.

getLineNumber

public int getLineNumber()
Returns the line number of the element currently being processed.

Returns:
The line number of the element currently being processed, or -1 if no element is currently being processed.

getLocation

public URL getLocation()
Returns the location of the WTKX currently being processed.

Returns:
The location of the WTKX, or null if no WTKX is currently being processed or the location is not known.

bind

public <T> void bind(T t,
                     Class<? super T> type)
          throws BindException
Applies WTKX binding annotations to an object.

NOTE This method uses reflection to set internal member variables. As a result, it may only be called from trusted code.

Parameters:
t -
type -
Throws:
BindException - If an error occurs during binding

getWTKXSerializerListeners

public ListenerList<WTKXSerializerListener> getWTKXSerializerListeners()