com.jstatcom.model
Class JSCVoid

java.lang.Object
  extended by com.jstatcom.model.AbstractJSCData
      extended by com.jstatcom.model.JSCVoid
All Implemented Interfaces:
JSCData

public final class JSCVoid
extends AbstractJSCData

An object wrapper that conforms to the JSCData interface. Arbitrary objects can be stored. This class is meant to store special purpose objects that are not easily generalized. It can be used to easily pass references to those objects via the symbol table.

Because nothing is known about the underlying value except that it is an Object, no special purpose methods are provided.

Example:
An example usage would be to store an object that represents the state of a certain model, say ModelState. This state object could be immutable and this wrapper notifies listeners whenever a new ModelState has been set. JSCVoid makes it also possible to assign a Symbol for that state object and to store it in a SymbolTable.

Usage Note:
Instances can only be (de)serialized, if the stored value is itself XML serializable, see javolution.xml.XmlFormat.

Comparisons between the stored values rely on the equals method of Object. If a logical check for equality is preferred to a pure reference check, then the class of the value object should overwrite equal (and hashCode to keep the contract).

Whenever the value of this data object changes (by setting a new object), registered JSCDataListeners are notified via a JSCDataEvent. If not otherwise stated, the event objects always contain the values before the change and after the change.

This class is thread-safe. All access to mutable data is synchronized. All events are fired outside the synchronized blocks.

Author:
Markus Kraetzig

Field Summary
static javolution.xml.XmlFormat<JSCVoid> JSCVoid_XML
          XML format field for (de)serialization.
 
Constructor Summary
JSCVoid()
          Creates an empty JSCVoid with a default name.
JSCVoid(java.lang.String name)
          Creates an empty JSCVoid.
JSCVoid(java.lang.String name, java.lang.Object value)
          Creates a JSCVoid from value.
 
Method Summary
 void clear()
          Clears this data object.
 JSCVoid copy()
          Gets a copy of the current object.
 boolean isEmpty()
          Gets whether this is empty.
 boolean isEqual(JSCData o)
          Gets whether the values of this data object and other are logically equal.
 java.lang.String name()
          Gets the name of the data object.
 void setVal(java.lang.Object newValue)
          Sets the value of this to newValue.
 JSCTypes type()
          Gets the type of this JSCData object.
 java.lang.Object value()
          Gets the underlying value, which is stored as an Object.
 
Methods inherited from class com.jstatcom.model.AbstractJSCData
addJSCDataListener, display, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JSCVoid_XML

public static final javolution.xml.XmlFormat<JSCVoid> JSCVoid_XML
XML format field for (de)serialization.

Constructor Detail

JSCVoid

public JSCVoid(java.lang.String name)
Creates an empty JSCVoid.

Parameters:
name - the identifier of that object
Throws:
java.lang.IllegalArgumentException - if name is not valid or if (name == null)
See Also:
JSCConstants.isValidName(java.lang.String)

JSCVoid

public JSCVoid()
Creates an empty JSCVoid with a default name.


JSCVoid

public JSCVoid(java.lang.String name,
               java.lang.Object value)
Creates a JSCVoid from value.

Parameters:
name - the identifier of that object
value - the Object to be used as value
Throws:
java.lang.IllegalArgumentException - if name is not valid or if (name == null)
See Also:
JSCConstants.isValidName(java.lang.String)
Method Detail

clear

public void clear()
Clears this data object. Fires: if it was not empty before. After calling this method isEmpty returns true.


copy

public JSCVoid copy()
Description copied from interface: JSCData
Gets a copy of the current object. Implementations of this method must fulfil the two conditions: JSCDataListeners attached to the original object should not be copied.

Returns:
a clonelike copy of the original object
See Also:
JSCData

isEmpty

public boolean isEmpty()
Gets whether this is empty. If this method returns true, then value returns null.

Returns:
true if empty

isEqual

public boolean isEqual(JSCData o)
Description copied from interface: JSCData
Gets whether the values of this data object and other are logically equal.

Returns:
true if considered equal according to the logic of the representation
See Also:
JSCData

name

public java.lang.String name()
Description copied from interface: JSCData
Gets the name of the data object. It must fulfil the requirements for variable names defined in JSCConstants.

Returns:
the name
See Also:
JSCData

setVal

public void setVal(java.lang.Object newValue)
Sets the value of this to newValue. Fires a JSCDataEvent of type:

Parameters:
newValue - the new value

type

public JSCTypes type()
Gets the type of this JSCData object.

Returns:
JSCTypes.VOID
See Also:
JSCTypes

value

public java.lang.Object value()
Gets the underlying value, which is stored as an Object.

Returns:
the value object or null if this is empty