Class MirrorDecorator
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- org.ptolemy.ssm.MirrorDecorator
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
MeasurementModel
,StateSpaceModel
public class MirrorDecorator extends TypedAtomicActor implements Decorator
A special decorator that mirrors its parameters and ports to the decorated actor. The ports are added to the decorated container, whereas the parameters are contained by the DecoratorAttributes object.- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Ilge Akkaya
- Pt.AcceptedRating:
- Red (ilgea)
- Pt.ProposedRating:
- Red (ilgea)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Parameter>
_addedParameters
A list containing the user added parameters.protected java.util.List<java.lang.String>
_addedPortNames
A list containing the names of user added ports.protected java.util.List<java.lang.String>
_addedPortParameterNames
A list containing the names of user added port parameters.protected java.util.List<NamedObj>
_decoratedObjects
Cached list of decorated objects.protected long
_decoratedObjectsVersion
Version for _decoratedObjects.protected java.util.ArrayList<MirrorDecoratorListener>
_listeners
Listeners registered to receive events from this object.-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description MirrorDecorator(CompositeEntity container, java.lang.String name)
Construct a MirrorDecorator with a name and a container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addAttribute(Attribute attr)
Add an attribute.protected void
_addPort(TypedIOPort port)
Add a port to this entity.protected void
_removeAttribute(Attribute attr)
Remove the given attribute.protected void
_removePort(Port port)
Remove the specified port.void
attributeChanged(Attribute attribute)
React to a change in an attribute.java.lang.Object
clone(Workspace workspace)
Clone the object into the specified workspace.DecoratorAttributes
createDecoratorAttributes(NamedObj target)
Create and return the decorated attributes for the target NamedObj.java.util.List<NamedObj>
decoratedObjects()
Return the decorated objects.java.util.List<Parameter>
getAddedParameters()
Return the added paramters.java.util.List<java.lang.String>
getAddedPortNames()
Return the added port names.java.util.List<java.lang.String>
getAddedPortParameterNames()
Return the added port parameter names.boolean
isGlobalDecorator()
Return true to indicate that this decorator should decorate objects across opaque hierarchy boundaries.void
registerListener(MirrorDecoratorListener monitor)
Add a communication aspect monitor to the list of listeners.void
sendParameterEvent(MirrorDecoratorListener.DecoratorEvent eventType, Parameter parameter)
Notify the monitor that an event happened.void
sendPortEvent(MirrorDecoratorListener.DecoratorEvent eventType, java.lang.String portName)
Notify the monitor that an event happened.void
setContainer(CompositeEntity container)
Override the base class to first set the container, then establish a connection with any decorated objects it finds in scope in the new container.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
_decoratedObjects
protected java.util.List<NamedObj> _decoratedObjects
Cached list of decorated objects.
-
_decoratedObjectsVersion
protected long _decoratedObjectsVersion
Version for _decoratedObjects.
-
_listeners
protected java.util.ArrayList<MirrorDecoratorListener> _listeners
Listeners registered to receive events from this object.
-
_addedPortNames
protected java.util.List<java.lang.String> _addedPortNames
A list containing the names of user added ports.
-
_addedPortParameterNames
protected java.util.List<java.lang.String> _addedPortParameterNames
A list containing the names of user added port parameters.
-
_addedParameters
protected java.util.List<Parameter> _addedParameters
A list containing the user added parameters.
-
-
Constructor Detail
-
MirrorDecorator
public MirrorDecorator(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a MirrorDecorator with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the container is incompatible with this actor.NameDuplicationException
- If the name coincides with an actor already in the container.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
Description copied from class:NamedObj
React to a change in an attribute. This method is called by a contained attribute when its value changes. In this base class, the method does nothing. In derived classes, this method may throw an exception, indicating that the new attribute value is invalid. It is up to the caller to restore the attribute to a valid value if an exception is thrown.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the change is not acceptable to this container (not thrown in this base class).
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the object into the specified workspace.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new NamedObj.
- Throws:
java.lang.CloneNotSupportedException
- If any of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
createDecoratorAttributes
public DecoratorAttributes createDecoratorAttributes(NamedObj target)
Description copied from interface:Decorator
Create and return the decorated attributes for the target NamedObj. Implementations of this method should create an Attribute that implementsDecoratorAttributes
. Implementations should populate that attribute with parameters that have appropriate default values.This method is called if
NamedObj.getDecoratorAttribute(Decorator, String)
orNamedObj.getDecoratorAttributes(Decorator)
is called, and the specified target object does not already have decorated attributes for this decorator.The implementer of this method is responsible for ensuring consistency with the
Decorator.decoratedObjects()
method. Specifically, any object returned byDecorator.decoratedObjects()
, when passed as an argument to this method, should not result in a null returned value. And conversely, any object passed to this method that is not in the list returned by decoratedObjects() should result in a null returned value.- Specified by:
createDecoratorAttributes
in interfaceDecorator
- Parameters:
target
- The NamedObj that will be decorated.- Returns:
- The decorated attributes for the target NamedObj, or null if the specified NamedObj is not decorated by this decorator.
-
decoratedObjects
public java.util.List<NamedObj> decoratedObjects() throws IllegalActionException
Return the decorated objects.- Specified by:
decoratedObjects
in interfaceDecorator
- Returns:
- The decorated objects.
- Throws:
IllegalActionException
- If some object cannot be determined to be decorated or not (e.g., a parameter cannot be evaluated).
-
getAddedPortNames
public java.util.List<java.lang.String> getAddedPortNames()
Return the added port names.- Returns:
- a list containing the added port names
-
getAddedPortParameterNames
public java.util.List<java.lang.String> getAddedPortParameterNames()
Return the added port parameter names.- Returns:
- a list containing the added port parameter names
-
getAddedParameters
public java.util.List<Parameter> getAddedParameters()
Return the added paramters.- Returns:
- a list containing the added parameters.
-
isGlobalDecorator
public boolean isGlobalDecorator()
Return true to indicate that this decorator should decorate objects across opaque hierarchy boundaries.- Specified by:
isGlobalDecorator
in interfaceDecorator
- Returns:
- True if decorator is global.
-
registerListener
public void registerListener(MirrorDecoratorListener monitor)
Add a communication aspect monitor to the list of listeners.- Parameters:
monitor
- The communication aspect monitor.
-
sendPortEvent
public void sendPortEvent(MirrorDecoratorListener.DecoratorEvent eventType, java.lang.String portName)
Notify the monitor that an event happened.- Parameters:
eventType
- Type of event.portName
- Name of port to be added/removed
-
sendParameterEvent
public void sendParameterEvent(MirrorDecoratorListener.DecoratorEvent eventType, Parameter parameter)
Notify the monitor that an event happened.- Parameters:
eventType
- Type of event.parameter
- Parameter to be added/removed
-
setContainer
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
Override the base class to first set the container, then establish a connection with any decorated objects it finds in scope in the new container.- Overrides:
setContainer
in classAtomicActor<TypedIOPort>
- Parameters:
container
- The container to attach this attribute to..- Throws:
IllegalActionException
- If this attribute is not of the expected class for the container, or it has no name, or the attribute and container are not in the same workspace, or the proposed container would result in recursive containment.NameDuplicationException
- If the container already has an attribute with the name of this attribute.- See Also:
ComponentEntity.getContainer()
-
_addPort
protected void _addPort(TypedIOPort port) throws IllegalActionException, NameDuplicationException
Description copied from class:Entity
Add a port to this entity. This method should not be used directly. Call the setContainer() method of the port instead. This method does not set the container of the port to point to this entity. It assumes that the port is in the same workspace as this entity, but does not check. The caller should check. Derived classes should override this method if they require a subclass of Port to throw an exception if the argument is not of an acceptable class. This method is not synchronized on the workspace, so the caller should be.- Overrides:
_addPort
in classEntity<TypedIOPort>
- Parameters:
port
- The port to add to this entity.- Throws:
IllegalActionException
- If the port has no name.NameDuplicationException
- If the port name collides with a name already in the entity.
-
_removePort
protected void _removePort(Port port)
Description copied from class:Entity
Remove the specified port. This method should not be used directly. Call the setContainer() method of the port instead with a null argument. The port is assumed to be contained by this entity (otherwise, nothing happens). This method does not alter the container of the port. This method is not synchronized on the workspace, so the caller should be.- Overrides:
_removePort
in classEntity<TypedIOPort>
- Parameters:
port
- The port being removed from this entity.
-
_addAttribute
protected void _addAttribute(Attribute attr) throws NameDuplicationException, IllegalActionException
Description copied from class:NamedObj
Add an attribute. This method should not be used directly. Instead, call setContainer() on the attribute. Derived classes may further constrain the class of the attribute. To do this, they should override this method to throw an exception when the argument is not an instance of the expected class.This method is write-synchronized on the workspace and increments its version number.
- Overrides:
_addAttribute
in classNamedObj
- Parameters:
attr
- The attribute to be added.- Throws:
NameDuplicationException
- If this object already has an attribute with the same name.IllegalActionException
- If the attribute is not an an instance of the expect class (in derived classes).
-
_removeAttribute
protected void _removeAttribute(Attribute attr)
Description copied from class:NamedObj
Remove the given attribute. If there is no such attribute, do nothing. This method is write-synchronized on the workspace and increments its version. It should only be called by setContainer() in Attribute.- Overrides:
_removeAttribute
in classNamedObj
- Parameters:
attr
- The attribute to be removed.
-
-