at.ac.tuwien.infosys.sm4all.copal.api.xml
Class Attribute<T>

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.xml.Attribute<T>
Type Parameters:
T - the type of unmarshaled and marshaled attribute value.
All Implemented Interfaces:
Marshaller<T>, Unmarshaller<T>
Direct Known Subclasses:
BooleanAttribute, DateAttribute, IntegerAttribute, LongAttribute, StringAttribute

public abstract class Attribute<T>
extends java.lang.Object
implements Unmarshaller<T>

Unmarshals and marshals an attribute from/to an Element.

Author:
sanjin

Nested Class Summary
static class Attribute.Builder<T>
          Builder of Attribute.
 
Constructor Summary
protected Attribute(java.lang.String name, org.w3c.dom.Element element)
          Creates instance of an attribute Unmarshaller which uses specified Element to unmarshal and/or marshal the attribute with specified name.
 
Method Summary
 org.w3c.dom.Element getElement()
          Returns the Element used for unmarshalling/marshalling.
 java.lang.String getName()
          Returns the name of the attribute in the Element used for unmarshalling/marshalling.
 void marshal(T value)
          Marshals specified value into the attribute in the Element.
 void remove()
          Removes the attribute from the Element.
protected abstract  java.lang.String toString(T value)
          Converts specified value of attribute to String.
 T unmarshal()
          Unmarshals the attribute from the Element.
protected abstract  T valueOf(java.lang.String str)
          Converts specified String value of the attribute to desired class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Attribute

protected Attribute(java.lang.String name,
                    org.w3c.dom.Element element)
Creates instance of an attribute Unmarshaller which uses specified Element to unmarshal and/or marshal the attribute with specified name.

Parameters:
name - the name of the attribute in the Element used for unmarshalling and marshalling.
element - the Element used for unmarshalling and marshalling.
Throws:
java.lang.NullPointerException - if specified Element or name is null.
java.lang.IllegalArgumentException - if specified name is an empty or blank string.
Method Detail

valueOf

protected abstract T valueOf(java.lang.String str)
                      throws InvalidFieldValueException
Converts specified String value of the attribute to desired class.

Parameters:
str - the String value of the attribute.
Returns:
the attribute as instance of the desired class.
Throws:
InvalidFieldValueException - if specified value is not valid.

toString

protected abstract java.lang.String toString(T value)
Converts specified value of attribute to String.

Parameters:
value - the value of the attribute.
Returns:
the attribute as String.

getName

public java.lang.String getName()
Returns the name of the attribute in the Element used for unmarshalling/marshalling.

Returns:
the name of the attribute in the Element used for unmarshalling/marshalling.

getElement

public org.w3c.dom.Element getElement()
Returns the Element used for unmarshalling/marshalling.

Returns:
the Element used for unmarshalling/marshalling.

unmarshal

public T unmarshal()
            throws MissingFieldException,
                   InvalidFieldValueException
Unmarshals the attribute from the Element.

Specified by:
unmarshal in interface Unmarshaller<T>
Returns:
the unmarshaled attribute.
Throws:
MissingFieldException - if specified Element does not have the attribute.
InvalidFieldValueException - if the attribute is empty or blank string or invalid value.

marshal

public void marshal(T value)
Marshals specified value into the attribute in the Element.

Specified by:
marshal in interface Marshaller<T>
Parameters:
value - the value of the attribute.
Throws:
java.lang.NullPointerException - if specified value is null.

remove

public void remove()
Removes the attribute from the Element.

Specified by:
remove in interface Marshaller<T>


Copyright © 2010 Distributed Systems Group, Vienna University of Technology. All Rights Reserved.