com.jstatcom.model
Interface JSCData

All Known Implementing Classes:
AbstractJSCData, JSCDate, JSCDRange, JSCInt, JSCMap, JSCNArray, JSCNumber, JSCSArray, JSCString, JSCVoid

public interface JSCData

Defines the contract for all data types to be used with Engine, Symbol and SymbolTable. It extends com.dautelle.xml.Representable to ensure that all data objects can be serialized with their XML representation that has to be defined in toXML.

JSCData objects should notify listeners about changes in the underlying value via a JSCDataEvent. There are several event types defined in JSCDataEventTypes for the most common changes, but different types may be defined by extending this enumeration. This is most preferably done by defining a static inner class for the respective JSCData implementation.

A further requirement for implementations of this interface is that all setter methods should copy mutable data before it is set and all getter methods should only return a copy of mutable objects. References should only be passed if the underlying objects are immutable, see (Joshua Bloch, "Effective Java", Item 13) .

Design Note:
Implementations of JSCData should in general act as wrapper to other types by providing additional functionality, like notification of listeners. Implementations should provide basic adapter methods to modify the underlying values, but the idea is, to keep them thin. For example the the JSCNArray class acts as a wrapper for double[][], but it is not designed as a general purpose matrix class for linear algebra. Instead this should be delegated to classes especially designed for these purposes. The wrapper can provide accessor methods that get the underlying value as instances of these special classes.

Usage Note:
To make sure that a JSCData object can be deserialized from its XML representation, every data class must also implement a public static field with the respective implementation of javolution.xml.XmlFormat. See the API documentation of this class for how to do this.

Author:
Markus Kraetzig

Method Summary
 void addJSCDataListener(JSCDataListener evtListener, JSCDataEventTypes evtType)
          Adds a listener that is notified when changes of type evtType occur in this object.
 void clear()
          After applying this method, isEmpty returns true.
 JSCData copy()
          Gets a copy of the current object.
 java.lang.String display()
          Gets a formatted string representing the value stored in this JSCData object.
 java.lang.Object getJSCProperty(JSCPropertyTypes type)
          Gets the value for a property type.
 boolean isEmpty()
          Gets whether this data object contains any data.
 boolean isEqual(JSCData other)
          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 removeJSCDataListener(JSCDataListener evtListener)
          Removes a JSCDataListener from all different listener lists.
 void removeJSCProperty(JSCPropertyTypes type)
          Removes the property value for type.
 void setJSCProperty(JSCPropertyTypes type, java.lang.Object val)
          Set the value for a property type.
 JSCTypes type()
          Gets the type of the data object.
 java.lang.Object value()
          Gets the value stored in this data object.
 

Method Detail

getJSCProperty

java.lang.Object getJSCProperty(JSCPropertyTypes type)
Gets the value for a property type.

Parameters:
type - the property type
Returns:
the value or null if the property has not been set

setJSCProperty

void setJSCProperty(JSCPropertyTypes type,
                    java.lang.Object val)
Set the value for a property type. Values are not serialized. The properties can be used to store runtime information associated with a data object.

Parameters:
type - the property type
val - the associated property value

removeJSCProperty

void removeJSCProperty(JSCPropertyTypes type)
Removes the property value for type.

Parameters:
type -

addJSCDataListener

void addJSCDataListener(JSCDataListener evtListener,
                        JSCDataEventTypes evtType)
Adds a listener that is notified when changes of type evtType occur in this object. All other events that are fired by this object are not dispatched to evtListener.

Parameters:
evtListener - the listener object that gets notified when an event of type evtType gets fired
evtType - the type of event that evtListener wants to listen to

clear

void clear()
After applying this method, isEmpty returns true. Implementations should fire a JSCDataEventTypes.EMPTY_STATE event if the data object was not empty before.


copy

JSCData copy()
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

display

java.lang.String display()
Gets a formatted string representing the value stored in this JSCData object.

Returns:
a formatted string

isEmpty

boolean isEmpty()
Gets whether this data object contains any data. Implementations of this method should document precisely, when the respective object is considered to be empty.

Returns:
true if no data is contained

isEqual

boolean isEqual(JSCData other)
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

name

java.lang.String name()
Gets the name of the data object. It must fulfil the requirements for variable names defined in JSCConstants.

Returns:
the name
See Also:
JSCConstants.isValidName(java.lang.String)

removeJSCDataListener

void removeJSCDataListener(JSCDataListener evtListener)
Removes a JSCDataListener from all different listener lists.

Parameters:
evtListener - the listener object to be removed

type

JSCTypes type()
Gets the type of the data object.

Returns:
data type
See Also:
JSCTypes

value

java.lang.Object value()
Gets the value stored in this data object.

Returns:
object that can be cast to a certain type depending on the JSCType