ptolemy.kernel.attributes
Class VersionAttribute

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.kernel.util.AbstractSettableAttribute
              extended by ptolemy.kernel.util.StringAttribute
                  extended by ptolemy.kernel.attributes.VersionAttribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable
Direct Known Subclasses:
RequireVersion

public class VersionAttribute
extends StringAttribute
implements java.lang.Comparable

A nonpersistent attribute that identifies the version of an object. This attribute does not export MoML The value of the attribute contains a String version-id that represents the version. A version-id is a string with substrings separated by one of '.', '-' or '_'. The substrings may consist of any characters except space. Version-ids can be compared against each other other with the compareTo() method.

The JNLP specification at http://jcp.org/jsr/detail/056.jsp gives the following syntax for version-ids:

 version-id ::= string ( separator string ) *
 string ::= char ( char ) *
 char ::= Any ASCII character except a space, a separator or a
 modifier
 separator ::= "." | "-" | "_"
 
Valid version-id include "1.3", "1.3.1", "1.3-beta_01".

The JNLP specification includes version-strings, which are used for matching one or more version-ids in a fashion similar to wildcard matches within a regular expression. At this time, this class does not implement version-strings.

Since:
Ptolemy II 2.0
Version:
$Id: VersionAttribute.java 57767 2010-05-04 14:07:08Z cxh $
Author:
Christopher Hylands
See Also:
SingletonConfigurableAttribute, Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Nested classes/interfaces inherited from interface ptolemy.kernel.util.Settable
Settable.Visibility
 
Field Summary
private  java.util.List _tupleList
           
static VersionAttribute CURRENT_VERSION
          The VersionAttribute that contains the version of the Ptolemy II release that is currently running.
 
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.kernel.util.Settable
EXPERT, FULL, NONE, NOT_EDITABLE
 
Constructor Summary
VersionAttribute(NamedObj container, java.lang.String name)
          Construct an attribute with the given name contained by the specified container.
VersionAttribute(java.lang.String expression)
          Construct an object in the default workspace with the empty string as its name.
 
Method Summary
 int compareTo(java.lang.Object object)
          Compare the value of this VersionAttribute against the argument according to the VersionAttribute syntax and padding rules.
 boolean equals(java.lang.Object object)
          Return true if the specified object is an instance of VersionAttribute and represents the same version as this one.
 int hashCode()
          Return a hash code value for attribute.
 boolean isLessThan(VersionAttribute version)
          Return true if this version is less than the specified version.
 java.util.Iterator iterator()
          Return an iterator over the elements of the version, each of which is a String.
static java.lang.String majorCurrentVersion()
          Return the major version, which consists of the first two tuples.
 void setExpression(java.lang.String expression)
          Set the value of the string attribute and notify the container of the value of this attribute by calling attributeChanged().
 
Methods inherited from class ptolemy.kernel.util.StringAttribute
_propagateValue, addValueListener, exportMoML, getExpression, getVisibility, removeValueListener, setVisibility, validate
 
Methods inherited from class ptolemy.kernel.util.AbstractSettableAttribute
getDefaultExpression, getValueAsString
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setContainer, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, 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, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.kernel.util.Settable
getDisplayName
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName, setName
 

Field Detail

CURRENT_VERSION

public static final VersionAttribute CURRENT_VERSION
The VersionAttribute that contains the version of the Ptolemy II release that is currently running. This variable may be read to take action if the assumed version does not match the current version. For example,

  VersionAttribute assumedVersion = ...;
  if (VersionAttribute.CURRENT_VERSION.isLessThan(assumedVersion)) {
      throw new IllegalActionException("You need to upgrade!");
  }
  

Similarly, this variable may be used to change the Ptolemy II functionality depending on the version number:

  if (VersionAttribute.CURRENT_VERSION.compareTo(
         new VersionAttribute("2.0")) >= 0 ) {
      // Perform some operation if the current version is
      // Ptolemy II 2.0 or later.
  }
  


_tupleList

private java.util.List _tupleList
Constructor Detail

VersionAttribute

public VersionAttribute(java.lang.String expression)
                 throws IllegalActionException
Construct an object in the default workspace with the empty string as its name. The object is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
expression - The initial value of this parameter, set using setExpression().
Throws:
IllegalActionException - If the value is of the incorrect format.
See Also:
setExpression(String)

VersionAttribute

public VersionAttribute(NamedObj container,
                        java.lang.String name)
                 throws IllegalActionException,
                        NameDuplicationException
Construct an attribute with the given name contained by the specified container. 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

compareTo

public int compareTo(java.lang.Object object)
Compare the value of this VersionAttribute against the argument according to the VersionAttribute syntax and padding rules. For example:

"1.2.2-005" is greater than "1.2.2.4",
"1.3.1" is an greater than "1.3"
"1.3-beta" is an greater than "1.3-alpha"

Version-id contain one or more elements. When two version-id's are compared, they are normalized by padding the shortest version-id with additional elements containing "0". During comparison, if both elements can be parsed as Java ints, then they are compared as integers. If the elements cannot be parsed as integers, they are compared as Strings.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - The VersionAttribute to compare against.
Returns:
A negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object, respectively.

equals

public boolean equals(java.lang.Object object)
Return true if the specified object is an instance of VersionAttribute and represents the same version as this one.

Overrides:
equals in class java.lang.Object
Parameters:
object - The specified object that is compared against.
Returns:
True if the specified version is the same as this one.

hashCode

public int hashCode()
Return a hash code value for attribute. This method returns the hash code of the expression.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code value for this token.

isLessThan

public boolean isLessThan(VersionAttribute version)
Return true if this version is less than the specified version. This method uses compareTo(), but may yield more readable code in certain circumstances.

Parameters:
version - The VersionAttribute that is compared against.
Returns:
True if this version is less than the specified version.
See Also:
compareTo(Object)

iterator

public java.util.Iterator iterator()
Return an iterator over the elements of the version, each of which is a String.

Returns:
An iterator over the elements of the version.

majorCurrentVersion

public static java.lang.String majorCurrentVersion()
Return the major version, which consists of the first two tuples. Thus, if the version is 6.0.1-beta, then this method will return "6.0".

Returns:
The major version.

setExpression

public void setExpression(java.lang.String expression)
                   throws IllegalActionException
Set the value of the string attribute and notify the container of the value of this attribute by calling attributeChanged(). Notify any value listeners of this attribute.

Specified by:
setExpression in interface Settable
Overrides:
setExpression in class StringAttribute
Parameters:
expression - The version string, consisting of version ID tuples separated by '.', '-' or '_'. For example: "1.2", "1.2_beta-4".
Throws:
IllegalActionException - If the argument contains a space, which violates the JNLP Version format specification.
See Also:
StringAttribute.getExpression()