|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdd.sim.SimObject
Base class for simulation objects. SimObject is the class from which all of the other objects in the simulation engine are built. SimObject has some basic behavior and protocol that is useful for all simulation objects, such as logging, simulation execution support, XML reading and writing, and so on.
Every simulation object has an attribute table that makes it possible
to associate arbitrary name/value pairs with that object. This makes it
possible to add attribute values dynamically and at run time. Attributes
by default are float
values but can be used to store
arbitrary values. Note that simulation attributes are different than
layer-specific attributes. Attributes associated directly with a
SimObject do not exist within a layer, and therefore should not be used in
conjunction with the attribute retrieval calls that use Layer information.
There are four levels of logging provided by this class, in increasing order of severity:
debug
- Debugging messages. These may be
very detailed and turned off for production codelog
- Logging messages. These are
moderate-priority messages that indicate normal action.
warning
- Warning messages. These are
error conditions, but errors which are recoverable (such as caught
exceptions).
error
- Major errors. These are
unrecoverable error conditions. The program may terminate after logging
these errors.
Simulation objects use the JavaBeans property change notification
scheme to provide event-based notification when a simulation object
changes. This should simplify the process of creating computations that
are dependent on an attribute value changing. Setting attribute value
will fire a PropertyChangeEvent
, and subclasses of
SimObject automatically inherit behavior to add and remove event
listeners. However, if a non-attribute property changes, it is the
responsibility of code to call firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)
where
appropriate.
Field Summary | |
protected java.util.HashMap |
attributes
stores the name/value attribute table |
Constructor Summary | |
SimObject()
Generic constructor for simulation objects. |
Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds the listener to the list of objects to be notified when this simulation object changes. |
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Adds a listener to be notified when a specific property changes. |
void |
debug(java.lang.String debugMessage)
Logs a debugging message. |
SimObject |
duplicate()
Makes a new SimObject identical to the current SimObject by serializing it to XML and reading it back in. |
void |
error(java.lang.String errorMessage)
Logs an error message. |
void |
fatal(java.lang.String errorMessage)
Logs an fatal error message. |
static java.util.List |
filter(java.util.Collection simObjects,
java.lang.String name,
double value)
Queries a collection of SimObjects for a property with the specified value. |
static java.util.List |
filter(java.util.Collection simObjects,
java.lang.String name,
java.lang.Object value)
Queries a collection of SimObjects for a property with the specified value. |
void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Informs listeners that a property has changed. |
float |
getAttribute(java.lang.String attributeName)
Gets the value of a named attribute. |
float |
getAttribute(java.lang.String attributeName,
float defaultValue)
Gets the value of a named attribute. |
java.util.HashMap |
getAttributes()
Returns the attributes associated with this object. |
java.lang.Object |
getGlobalAttribute(java.lang.String attributeName)
Gets the value of a named attribute for this simulation. |
java.lang.Object |
getObjectAttribute(java.lang.String attributeName)
Gets the value of a named attribute. |
java.lang.Object |
getObjectAttribute(java.lang.String attributeName,
java.lang.Object defaultValue)
Gets the value of a named attribute. |
void |
incrementAttribute(java.lang.String attributeName)
Increments the value of an attribute by one. |
void |
incrementAttribute(java.lang.String attributeName,
float delta)
Increments the value of the attribute by the amount specified. |
boolean |
isSet(java.lang.String attributeName)
Returns 'true' if the named attribute has a non-zero floating-point value. |
void |
log(java.lang.String logMessage)
Logs a logging message. |
protected static void |
out(java.lang.String message)
|
static SimObject |
readFromXML(java.io.Reader reader)
Creates a new SimObject from an XML representation. |
static SimObject |
readFromXML(java.lang.String fileName)
Creates a new SimObject from an XML representation. |
void |
removeAttribute(java.lang.String attributeName)
Removes a named attribute. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the listener from the notification list. |
void |
setAttribute(java.lang.String attributeName,
boolean value)
Sets the value of a named attribute. |
void |
setAttribute(java.lang.String attributeName,
float value)
Sets the value of a named attribute. |
void |
setAttribute(java.lang.String attributeName,
java.lang.Object value)
Sets the value of a named attribute. |
void |
setAttributes(java.util.HashMap attributes)
Sets the attributes associated with this object. |
void |
setGlobalAttribute(java.lang.String attributeName,
java.lang.Object value)
Sets the value of a named attribute for this simuation. |
void |
warning(java.lang.String warningMessage)
Logs a warning message. |
java.lang.String |
writeText()
|
java.lang.String |
writeXML()
Writes a representation of this SimObject as XML to a String. |
void |
writeXML(java.lang.String fileName)
Writes a representation of this SimObject as XML. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.HashMap attributes
Constructor Detail |
public SimObject()
Method Detail |
public static java.util.List filter(java.util.Collection simObjects, java.lang.String name, double value)
simObjects
- a Collection of SimObjects to queryname
- the property name to queryvalue
- the value the property shold have
public static java.util.List filter(java.util.Collection simObjects, java.lang.String name, java.lang.Object value)
simObjects
- a Collection of SimObjects to queryname
- the property name to queryvalue
- the value the property shold have
protected static void out(java.lang.String message)
public java.util.HashMap getAttributes()
Float
objects).
public void setAttributes(java.util.HashMap attributes)
attributes
- new name/value attribute tablepublic java.lang.Object getGlobalAttribute(java.lang.String attributeName)
attributeName
- name of the global attribute to query
null
if the attribute
does not exist.public void setGlobalAttribute(java.lang.String attributeName, java.lang.Object value)
attributeName
- name of the global attribute to setvalue
- value to which the attribute should be setpublic float getAttribute(java.lang.String attributeName)
getObjectAttribute
. It
returns the value of the attribute specified. Note that attributes
(floating point values) and Object attributes share the same name
space, so this method will fail if it requests a non-numeric
attribute.
attributeName
- name of the attribute to query
java.util.NoSuchElementException
- if there is no attribute with the
specified namepublic float getAttribute(java.lang.String attributeName, float defaultValue)
getObjectAttribute
. It returns
the value of the attribute specified. If that attribute does not
exist, then the default value is returned. Note that attributes
(floating point values) and Object attributes share the same name
space, so this method will fail if it requests a non-numeric
attribute.
attributeName
- name of the attribute to querydefaultValue
- value to return if the attribute does not exist
defaultValue
if
the attribute does not exist.public java.lang.Object getObjectAttribute(java.lang.String attributeName)
attributeName
- name of the attribute to query
null
if the attribute
does not existpublic java.lang.Object getObjectAttribute(java.lang.String attributeName, java.lang.Object defaultValue)
attributeName
- name of the attribute to querydefaultValue
- value to return if the attribute does not exist
defaultValue
if
the attribute does not exist.public void setAttribute(java.lang.String attributeName, float value)
attributeName
- name of the attribute to setvalue
- value to which the attribute should be setPropertyChangeEvent
public void setAttribute(java.lang.String attributeName, boolean value)
attributeName
- name of the attribute to setvalue
- value to which the attribute should be setPropertyChangeEvent
public void setAttribute(java.lang.String attributeName, java.lang.Object value)
attributeName
- name of the attribute to setvalue
- value to which the attribute should be setPropertyChangeEvent
public void removeAttribute(java.lang.String attributeName)
attributeName
- name of the attribute to removepublic boolean isSet(java.lang.String attributeName)
public void incrementAttribute(java.lang.String attributeName)
attributeName
- name of the attribute to incrementpublic void incrementAttribute(java.lang.String attributeName, float delta)
delta
to the current value of the attribute. If
the attribute is unset, it is set to the value delta.
attributeName
- name of the attribute to setdelta
- amount (positive or negative) to add to the attribute)public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- object to notify when properties changepublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- object to no longer receive notificationspublic void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
propertyName
- name of the property to monitorlistener
- object to notify when the property changespublic void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
propertyName
- name of the property that is changingoldValue
- former value of the propertynewValue
- new (probably current) value of the propertypublic void debug(java.lang.String debugMessage)
debugMessage
- descriptive text for the logpublic void log(java.lang.String logMessage)
logMessage
- descriptive text for the logpublic void warning(java.lang.String warningMessage)
warningMessage
- descriptive text for the logpublic void error(java.lang.String errorMessage)
errorMessage
- descriptive text for the logpublic void fatal(java.lang.String errorMessage)
errorMessage
- descriptive text for the logpublic static SimObject readFromXML(java.lang.String fileName)
fileName
- name of the XML file to parse
null
if an error occurspublic static SimObject readFromXML(java.io.Reader reader)
reader
- character stream from which XML will be read
null
if an error occurspublic void writeXML(java.lang.String fileName)
SimXMLWriter
class.
The description returned by this method should be a complete enough
description so that an object can be read in at a future time from
this representation.
fileName
- file upon which the object should be writtenpublic java.lang.String writeXML()
SimXMLWriter
class.
The description returned by this method should be a complete enough
description so that an object can be read in at a future time from
this representation.
public java.lang.String writeText()
public SimObject duplicate()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |