ptolemy.copernicus.kernel
Class GeneratorAttribute

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.kernel.util.SingletonAttribute
              extended by ptolemy.copernicus.kernel.GeneratorAttribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, ChangeListener, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Singleton
Direct Known Subclasses:
GeneratorTableauAttribute

public class GeneratorAttribute
extends SingletonAttribute
implements ChangeListener

This is an attribute that stores the configuration of a code generator.

The initial default parameters, their values and their documentation are read in from a MoML file specified by the initialParametersURL. Having the parameters defined in a MoML file allows us to easily add and modify parameters without lots of bookkeeping.

To view the initial default parameters, either call toString(), or run:

 java -classpath $PTII ptolemy.copernicus.kernel.Copernicus -help
 

Since:
Ptolemy II 2.0
Version:
$Id: GeneratorAttribute.java,v 1.81 2007/12/06 21:56:53 cxh Exp $
Author:
Edward A. Lee, Christopher Hylands
See Also:
Serialized Form
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
 StringParameter initialParametersURL
          MoML file that contains other parameters.
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
GeneratorAttribute(NamedObj container, java.lang.String name)
          Construct an attribute with the given name contained by the specified entity.
 
Method Summary
 void changeExecuted(ChangeRequest change)
          React to a change request has been successfully executed.
 void changeFailed(ChangeRequest change, java.lang.Exception exception)
          React to a change request has resulted in an exception.
 java.lang.String getParameter(java.lang.String name)
          Get the string for the argument with the given name from this GeneratorAttribute.
 boolean hasParameter(java.lang.String name)
          Return true if a parameter with the given name is defined in this GeneratorAttribute.
 void initialize()
          If this GeneratorAttribute has not yet been initialized, the initialized it by reading the moml file named by the initialParametersURL and creating Parameters and Variables accordingly.
static java.lang.String lookupClassAsResource(java.lang.String necessaryClass)
          Deprecated. Call ptolemy.util.ClassUtilities.lookupClassAsResource() instead;
 void sanityCheckAndUpdateParameters(java.lang.String modelPathOrURL)
           
 void setParameter(java.lang.String name, java.lang.String value)
          Set the string for the argument with the given name from this GeneratorAttribute to be the given value.
 java.lang.String toString()
          Return a String representation of this object.
 void updateModelAttributes(java.lang.String modelPathOrURL)
          Update the modelPath, modelName and iterations parameters in the GeneratorAttribute.
 
Methods inherited from class ptolemy.kernel.util.SingletonAttribute
setContainer
 
Methods inherited from class ptolemy.kernel.util.Attribute
_getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

initialParametersURL

public StringParameter initialParametersURL
MoML file that contains other parameters. The default value is the string "ptolemy/copernicus/kernel/Generator.xml".

Constructor Detail

GeneratorAttribute

public GeneratorAttribute(NamedObj container,
                          java.lang.String name)
                   throws IllegalActionException,
                          NameDuplicationException
Construct an attribute with the given name contained by the specified entity. The container argument must not be null, or a NullPointerException will be thrown. This attribute 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 attribute.
Throws:
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

changeExecuted

public void changeExecuted(ChangeRequest change)
Description copied from interface: ChangeListener
React to a change request has been successfully executed. This method is called after a change request has been executed successfully.

Specified by:
changeExecuted in interface ChangeListener
Parameters:
change - The change that has been executed, or null if the change was not done via a ChangeRequest.

changeFailed

public void changeFailed(ChangeRequest change,
                         java.lang.Exception exception)
Description copied from interface: ChangeListener
React to a change request has resulted in an exception. This method is called after a change request was executed, but during the execution an exception was thrown.

Specified by:
changeFailed in interface ChangeListener
Parameters:
change - The change that was attempted or null if the change was not done via a ChangeRequest.
exception - The exception that resulted.

getParameter

public java.lang.String getParameter(java.lang.String name)
                              throws IllegalActionException
Get the string for the argument with the given name from this GeneratorAttribute.

Throws:
IllegalActionException - If no Settable object with the given name exists in this GeneratorAttribute.

hasParameter

public boolean hasParameter(java.lang.String name)
                     throws IllegalActionException
Return true if a parameter with the given name is defined in this GeneratorAttribute.

Throws:
IllegalActionException

initialize

public void initialize()
                throws IllegalActionException,
                       NameDuplicationException
If this GeneratorAttribute has not yet been initialized, the initialized it by reading the moml file named by the initialParametersURL and creating Parameters and Variables accordingly.

Throws:
IllegalActionException
NameDuplicationException

lookupClassAsResource

public static java.lang.String lookupClassAsResource(java.lang.String necessaryClass)
Deprecated. Call ptolemy.util.ClassUtilities.lookupClassAsResource() instead;

Given a dot separated classname, return the jar file or directory where the class can be found.

Parameters:
necessaryClass - The dot separated class name, for example "ptolemy.kernel.util.NamedObj"
Returns:
If the class can be found as a resource, return the directory or jar file where the necessary class can be found. otherwise, return null.

sanityCheckAndUpdateParameters

public void sanityCheckAndUpdateParameters(java.lang.String modelPathOrURL)
                                    throws IllegalActionException,
                                           NameDuplicationException
Throws:
IllegalActionException
NameDuplicationException

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
                  throws IllegalActionException
Set the string for the argument with the given name from this GeneratorAttribute to be the given value.

Throws:
IllegalActionException - If no Settable object with the given name exists in this GeneratorAttribute.

toString

public java.lang.String toString()
Return a String representation of this object.

Overrides:
toString in class NamedObj
Returns:
The class name and the full name.

updateModelAttributes

public void updateModelAttributes(java.lang.String modelPathOrURL)
                           throws IllegalActionException
Update the modelPath, modelName and iterations parameters in the GeneratorAttribute. This method parses the model and updates all GeneratorAttribute parameters that are determined by the model itself.

Parameters:
modelPathOrURL - The file pathname or URL to the model.
Throws:
IllegalActionException