|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.data.expr.ScopeExtendingAttribute
ptolemy.actor.parameters.ParameterSet
public class ParameterSet
An attribute that reads multiple values from a file and sets corresponding parameters in the container. The values are in the form:
attributeName = valuewhere
variableName
is the name of the attribute
in a format suitable for NamedObj.setName(String)
(i.e., does not contain periods) and value
is
the expression in the Ptolemy expression language.
Comments are lines that begin with the #
character.
Each line in the file is interpreted as a separate assignment.
The attributes that are created will have the same visibility as parameters of the container of the attribute. They are shadowed, however, by parameters of the container. That is, if the container has a parameter with the same name as one in the parameter set, the one in the container provides the value to any observer.
If the file is modified during execution of a model, by default this will not be noticed until the next run. If you set the checkForFileUpdates parameter to true, then on each prefiring of the enclosing opaque composite actor, this parameter will check for updates of the file. Otherwise, it will only check between runs of the model or when the file name or URL gets changed.
Note that the order the parameters are created is arbitrary, this is because we read the file in using java.util.Properties.load(), which uses a HashMap to store the properties. We use a Properties.load() because it provides a nice parser for the files and can read and write values in both text and XML.
Variable
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private long |
_date
Date of the file when last read. |
private java.lang.String |
_fileName
The previously read file name. |
private java.util.List<Initializable> |
_initializables
List of objects whose (pre)initialize() and wrapup() methods should be slaved to these. |
private java.util.Properties |
_properties
Cached copy of the last hashset of properties, used to remove old properties. |
Parameter |
checkForFileUpdates
If this parameter is set to true, then the specified file or URL will be checked for updates on every prefiring of the enclosing opaque composite actor. |
FileParameter |
fileOrURL
A parameter naming the file or URL to be read that contains attribute names and values. |
Fields inherited from class ptolemy.kernel.util.NamedObj |
---|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _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 | |
---|---|
ParameterSet(NamedObj container,
java.lang.String name)
Construct an attribute with the given name contained by the specified entity. |
Method Summary | |
---|---|
private void |
_reReadIfNeeded()
If either the file name or the date on the file have changed since the last reading, then re-read the file. |
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. |
void |
attributeChanged(Attribute attribute)
If the parameter is fileOrURL, and the specified file name is not null, then open and read the file. |
void |
fire()
Do nothing. |
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. |
int |
iterate(int count)
Check to see whether the specified file has changed, and if so, re-read it. |
boolean |
postfire()
Do nothing. |
boolean |
prefire()
Check to see whether the specified file has changed, and if so, re-read it. |
void |
preinitialize()
Check to see whether the specified file has changed, and if so, re-read it, and invoke the preinitialize() methods of objects that have been added using addInitializable(). |
void |
read()
Read the contents of the file named by this parameter and create attributes in the current scope. |
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 a piggyback with the nearest opaque composite actor above in the hierarchy. |
void |
stop()
Do nothing. |
void |
stopFire()
Do nothing. |
void |
terminate()
Do nothing. |
void |
wrapup()
Check to see whether the specified file has changed, and if so, re-read it, and invoke the wrapup() methods of objects that have been added using addInitializable(). |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ptolemy.data.expr.ScopeExtender |
---|
attributeList, getAttribute |
Field Detail |
---|
public Parameter checkForFileUpdates
public FileParameter fileOrURL
private long _date
private java.lang.String _fileName
private transient java.util.List<Initializable> _initializables
private java.util.Properties _properties
Constructor Detail |
---|
public ParameterSet(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this attribute.
IllegalActionException
- If the attribute is not of an
acceptable class for the container, or if the name contains a period.
NameDuplicationException
- If the name coincides with
an attribute already in the container.Method Detail |
---|
public void addInitializable(Initializable initializable)
addInitializable
in interface Initializable
initializable
- The object whose methods should be invoked.removeInitializable(Initializable)
,
CompositeActor.addPiggyback(Executable)
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.
IllegalActionException
- If the superclass throws it, or
if the file cannot be read, or if the file parameters cannot
be evaluated.public void fire() throws IllegalActionException
fire
in interface Executable
IllegalActionException
- If firing is not permitted.public void initialize() throws IllegalActionException
initialize
in interface Initializable
IllegalActionException
- If one of the added objects
throws it.public boolean isFireFunctional()
isFireFunctional
in interface Executable
public boolean isStrict()
isStrict
in interface Executable
public int iterate(int count) throws IllegalActionException
iterate
in interface Executable
count
- The number of iterations to perform, ignored by this
method.
IllegalActionException
- If re-reading the file fails.public boolean postfire()
postfire
in interface Executable
public boolean prefire() throws IllegalActionException
prefire
in interface Executable
IllegalActionException
- If re-reading the file fails.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
IllegalActionException
- If one of the added objects
throws it, or if re-reading the file fails.public void read() throws IllegalActionException, NameDuplicationException, java.io.IOException
java.io.IOException
- If there is a problem reading the file.
IllegalActionException
- If there is a problem
reading the previous attribute or validating the settables
NameDuplicationException
- If there is a problem removing
a previous attribute or creating a new variable.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 ScopeExtendingAttribute
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 stop()
stop
in interface Executable
public void stopFire()
stopFire
in interface Executable
public void terminate()
terminate
in interface Executable
public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
IllegalActionException
- If one of the added objects
throws it, or if re-reading the file fails.private void _reReadIfNeeded() throws IllegalActionException
IllegalActionException
- If re-reading the file fails.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |