Interface JSCData
-
- All Known Implementing Classes:
- AbstractJSCData, JSCDate, JSCDRange, JSCInt, JSCMap, JSCNArray, JSCNumber, JSCSArray, JSCString, JSCVoid
public interface JSCDataDefines the contract for all data types to be used withEngine,SymbolandSymbolTable. It extendscom.dautelle.xml.Representableto ensure that all data objects can be serialized with their XML representation that has to be defined intoXML.JSCDataobjects should notify listeners about changes in the underlying value via aJSCDataEvent. There are several event types defined inJSCDataEventTypesfor 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 respectiveJSCDataimplementation.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 ofJSCDatashould 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 theJSCNArrayclass acts as a wrapper fordouble[][], 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 aJSCDataobject can be deserialized from its XML representation, every data class must also implement a public static field with the respective implementation of javolution37.javolution.xml.XmlFormat. See the API documentation of this class for how to do this.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidaddJSCDataListener(JSCDataListener evtListener, JSCDataEventTypes evtType)Adds a listener that is notified when changes of typeevtTypeoccur in this object.voidclear()After applying this method,isEmptyreturnstrue.JSCDatacopy()Gets a copy of the current object.java.lang.Stringdisplay()Gets a formatted string representing the value stored in thisJSCDataobject.java.lang.ObjectgetJSCProperty(JSCPropertyTypes type)Gets the value for a property type.booleanisEmpty()Gets whether this data object contains any data.booleanisEqual(JSCData other)Gets whether the values of this data object andotherare logically equal.java.lang.Stringname()Gets the name of the data object.voidremoveJSCDataListener(JSCDataListener evtListener)Removes aJSCDataListenerfrom all different listener lists.voidremoveJSCProperty(JSCPropertyTypes type)Removes the property value fortype.voidsetJSCProperty(JSCPropertyTypes type, java.lang.Object val)Set the value for a property type.JSCTypestype()Gets the type of the data object.java.lang.Objectvalue()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
nullif 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 typeval- the associated property value
-
removeJSCProperty
void removeJSCProperty(JSCPropertyTypes type)
Removes the property value fortype.- Parameters:
type-
-
addJSCDataListener
void addJSCDataListener(JSCDataListener evtListener, JSCDataEventTypes evtType)
Adds a listener that is notified when changes of typeevtTypeoccur in this object. All other events that are fired by this object are not dispatched toevtListener.- Parameters:
evtListener- the listener object that gets notified when an event of typeevtTypegets firedevtType- the type of event thatevtListenerwants to listen to
-
clear
void clear()
After applying this method,isEmptyreturnstrue. Implementations should fire aJSCDataEventTypes.EMPTY_STATEevent 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:a.isEqual(a.copy())- compares valuesa.getName().equals(a.copy().getName())- compares name
JSCDataListenersattached 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 thisJSCDataobject.- 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:
trueif no data is contained
-
isEqual
boolean isEqual(JSCData other)
Gets whether the values of this data object andotherare logically equal.- Returns:
trueif 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 inJSCConstants.- Returns:
- the name
- See Also:
JSCConstants.isValidName(java.lang.String)
-
removeJSCDataListener
void removeJSCDataListener(JSCDataListener evtListener)
Removes aJSCDataListenerfrom all different listener lists.- Parameters:
evtListener- the listener object to be removed
-
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
-
-
DMelt 3.0 © DataMelt by jWork.ORG