Class VersionAttribute

  • All Implemented Interfaces:
    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. 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$
    Author:
    Christopher Hylands
    See Also:
    SingletonConfigurableAttribute
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (cxh)
    • 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.
          }
          
    • 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

      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone the attribute into the specified workspace. This calls the base class and then sets the attribute public members to refer to the attributes of the new attribute
        Overrides:
        clone in class StringAttribute
        Parameters:
        workspace - The workspace for the new attribute
        Returns:
        A new director.
        Throws:
        java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • 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()