public class SharedParameter extends Parameter implements Initializable
One exception is that if this parameter is (deeply) within an instance of EntityLibrary, then the parameter is not shared. Were this not the case, then opening a library containing this parameter would force expansion of all the sublibraries of EntityLibrary, which would defeat the lazy instantiation of EntityLibrary.
When this parameter is constructed, the specified container will be used to infer the parameter value from the container. That is, if the container is within a model that has any parameters shared with this one, then the value will be set to the last of those encountered. If the container is subsequently changed, it is up to the code implementing the change to use the inferValueFromContext() method to reset the value to match the new context. Note that this really needs to be done if the container of the container, or its container, or any container above this parameter is changed. It is recommended to use the four-argument constructor, so you can specify a default value to use if there are no shared parameters.
Note that it might be tempting to use a static parameter field to achieve this effect, but this would be problematic for two reasons. First, the parameter would only be able to have one container. Second, the parameter would be shared across all models in the same Java virtual machine, not just within a single model.
Variable.CircularDependencyError, Variable.VariableScope
NamedObj.ContainedObjectsIterator
Settable.Visibility
_currentExpression, _needsEvaluation, _parserScope, _parseTreeValid, _suppressVariableSubstitution, _valueListeners
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
EXPERT, FULL, NONE, NOT_EDITABLE
Constructor and Description |
---|
SharedParameter(NamedObj container,
java.lang.String name)
Construct a parameter with the given container and name.
|
SharedParameter(NamedObj container,
java.lang.String name,
java.lang.Class<?> containerClass)
Construct a parameter with the given container, name, and
container class.
|
SharedParameter(NamedObj container,
java.lang.String name,
java.lang.Class<?> containerClass,
java.lang.String defaultValue)
Construct a parameter with the given container, name,
container class, and default value.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_propagateValue(NamedObj destination)
Override the base class to do the propagation only if
the specified destination is not shared, because if
it is shared, then the value will be propagated
in through the sharing mechanism.
|
void |
addInitializable(Initializable initializable)
Add the specified object to the list of objects whose
preinitialize(), initialize(), and wrapup()
methods should be invoked upon invocation of the corresponding
methods of this object.
|
java.lang.Object |
clone(Workspace workspace)
Override the base class to register the object, since setName()
will not be called.
|
NamedObj |
getRoot()
Return the top level of the containment hierarchy, unless
one of the containers is an instance of EntityLibrary,
in which case, return null.
|
Token |
getToken()
Get the token contained by this variable.
|
void |
inferValueFromContext(java.lang.String defaultValue)
Infer the value of this parameter from the container
context.
|
void |
initialize()
Do nothing except invoke the initialize methods
of objects that have been added using addInitializable().
|
boolean |
isFireFunctional()
Return true.
|
boolean |
isStrict()
Return false.
|
boolean |
isSuppressingPropagation()
Return true if this instance is suppressing propagation.
|
void |
preinitialize()
Traverse the model and update values.
|
void |
removeInitializable(Initializable initializable)
Remove the specified object from the list of objects whose
preinitialize(), initialize(), and wrapup()
methods should be invoked upon invocation of the corresponding
methods of this object.
|
void |
setContainer(NamedObj container)
Override the base class to register as an initializable slave with the
new container.
|
void |
setExpression(java.lang.String expression)
Override the base class to also set the expression of shared
parameters.
|
void |
setName(java.lang.String name)
Override the base class to register as a shared parameter in the workspace.
|
void |
setSuppressingPropagation(boolean propagation)
Specify whether this instance should be suppressing
propagation.
|
void |
setToken(Token token)
Override the base class to also set the token of shared
parameters.
|
java.util.Collection |
sharedParameterSet()
Return a collection of all the shared parameters within the
same model as this parameter.
|
java.util.Collection |
validate()
Override the base class to also validate the shared instances.
|
void |
wrapup()
Supress propagation.
|
addChoice, exportMoML, getChoices, removeAllChoices, removeChoice
_description, _evaluate, _getCurrentExpression, _notifyValueListeners, _parseIfNecessary, _propagate, _propagateToValueListeners, _setToken, _setTokenAndNotify, addValueListener, attributeChanged, getDeclaredType, getExpression, getFreeIdentifiers, getParserScope, getScope, getScope, getType, getTypeTerm, getValueAsString, getVariable, getVisibility, invalidate, isKnown, isLazy, isStringMode, isSuppressVariableSubstitution, isTypeAcceptable, removeValueListener, reset, setLazy, setParseTreeEvaluator, setStringMode, setSuppressVariableSubstitution, setToken, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, setUnknown, setValueListenerAsWeakDependency, setVisibility, stringRepresentation, toString, typeConstraintList, typeConstraints, valueChanged
getDefaultExpression
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDisplayName
description, getContainer, getFullName, getName, getName
public SharedParameter(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the parameter.IllegalActionException
- If the parameter is not of an
acceptable class for the container.NameDuplicationException
- If the name coincides with
a parameter already in the container.public SharedParameter(NamedObj container, java.lang.String name, java.lang.Class<?> containerClass) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the parameter.containerClass
- The class used to determine shared instances.IllegalActionException
- If the parameter is not of an
acceptable class for the container.NameDuplicationException
- If the name coincides with
a parameter already in the container.public SharedParameter(NamedObj container, java.lang.String name, java.lang.Class<?> containerClass, java.lang.String defaultValue) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the parameter.containerClass
- The class used to determine shared instances.
An argument of null means simply to use the class of the container,
whatever that happens to be.defaultValue
- The default value to use if the container's
model has no shared parameters.IllegalActionException
- If the parameter is not of an
acceptable class for the container, or an empty string to specify no
default value.NameDuplicationException
- If the name coincides with
a parameter already in the container.public void addInitializable(Initializable initializable)
addInitializable
in interface Initializable
initializable
- The object whose methods should be invoked.removeInitializable(Initializable)
,
CompositeActor.addPiggyback(Executable)
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class Parameter
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If any of the attributes
cannot be cloned.Parameter.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public Token getToken() throws IllegalActionException
getToken
in class Variable
IllegalActionException
- If the expression cannot
be parsed or cannot be evaluated, or if the result of evaluation
violates type constraints, or if the result of evaluation is null
and there are variables that depend on this one.setToken(Token)
public NamedObj getRoot()
public void inferValueFromContext(java.lang.String defaultValue)
defaultValue
- The default parameter value to use.public void initialize() throws IllegalActionException
initialize
in interface Initializable
IllegalActionException
- If one of the added objects
throws it.public boolean isFireFunctional()
public boolean isStrict()
public boolean isSuppressingPropagation()
setSuppressingPropagation(boolean)
public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
IllegalActionException
- Not thrown in this base class.public void removeInitializable(Initializable initializable)
removeInitializable
in interface Initializable
initializable
- The object whose methods should no longer be invoked.addInitializable(Initializable)
,
CompositeActor.removePiggyback(Executable)
public void setContainer(NamedObj container) throws IllegalActionException, NameDuplicationException
setContainer
in class Variable
container
- The proposed container.IllegalActionException
- If the action would result in a
recursive containment structure, or if
this entity and container are not in the same workspace.NameDuplicationException
- If the container already has
an entity with the name of this entity.Attribute.getContainer()
public void setName(java.lang.String name) throws IllegalActionException, NameDuplicationException
setName
in interface Nameable
setName
in class Variable
name
- The proposed name.IllegalActionException
- If the name contains a period
or if this variable is referenced in some other expression.NameDuplicationException
- If there is already an
attribute with the same name in the container.NamedObj.getName()
,
NamedObj.getName(NamedObj)
public void setExpression(java.lang.String expression)
setExpression
in interface Settable
setExpression
in class Variable
expression
- The expression.Variable.getExpression()
public void setSuppressingPropagation(boolean propagation)
propagation
- True to suppress propagation.isSuppressingPropagation()
public void setToken(Token token) throws IllegalActionException
setToken
in class Variable
token
- The token.IllegalActionException
- Thrown if super class throws it.getToken()
public java.util.Collection sharedParameterSet()
public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
IllegalActionException
- Not thrown in this base class.public java.util.Collection validate() throws IllegalActionException
validate
in interface Settable
validate
in class Variable
sharedParameterSet()
.IllegalActionException
- If this variable or a
variable dependent on this variable cannot be evaluated (and is
not lazy) and the model error handler throws an exception.
Also thrown if the change is not acceptable to the container.protected void _propagateValue(NamedObj destination) throws IllegalActionException
_propagateValue
in class Variable
destination
- Object to which to propagate the
value.IllegalActionException
- If the value cannot
be propagated.