Package ptolemy.data

Class XMLToken


  • public class XMLToken
    extends Token
    A token that contains a xml document. Currently, no operations between function tokens (add, multiply, etc.) are supported.
    Since:
    Ptolemy II 4.0
    Version:
    $Id$
    Author:
    Yang Zhao
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (neuendor)
    • Constructor Detail

      • XMLToken

        public XMLToken()
        Construct an empty token.
      • XMLToken

        public XMLToken​(java.lang.String init)
                 throws java.lang.Exception
        Construct an XmlToken from the specified string.
        Parameters:
        init - The initialization string.
        Throws:
        java.lang.Exception - If the string is not parsable.
    • Method Detail

      • convert

        public static XMLToken convert​(Token token)
                                throws IllegalActionException
        Convert the specified token into an instance of XMLToken. If the specified token is not an instance of XMLToken, an exception is thrown.
        Parameters:
        token - The token to be converted to a XMLToken.
        Returns:
        A XMLToken.
        Throws:
        IllegalActionException - If the conversion cannot be carried out.
      • getDomTree

        public org.w3c.dom.Document getDomTree()
        Return the dom document parsed from the xml string.
        Returns:
        A Document.
      • equals

        public boolean equals​(java.lang.Object object)
        Return true if the argument is an instance of XMLToken with the same value.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - An instance of Object.
        Returns:
        True if the argument is an IntToken with the same value. If either this object or the argument is nil, return false.
      • hashCode

        public int hashCode()
        Return the hash code for the XMLToken object. If two XMLToken objects contains the same String then they have the same hashcode.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code for this XMLToken object.
      • isCloseTo

        public final BooleanToken isCloseTo​(Token token,
                                            double epsilon)
                                     throws IllegalActionException
        Test that the value of this token is close to the first argument, where "close" means that the distance between them is less than or equal to the second argument. This method only makes sense for tokens where the distance between them is reasonably represented as a double. If the argument token is not of the same type as this token, then either this token or the argument will be converted, if possible, to the type of the other.

        Subclasses should not generally override this method, but override the protected _isCloseTo() method to ensure that type conversion is performed consistently.

        Overrides:
        isCloseTo in class Token
        Parameters:
        token - The token to test closeness of this token with.
        epsilon - The value that we use to determine whether two tokens are close.
        Returns:
        A boolean token that contains the value true if the value and units of this token are close to those of the argument token.
        Throws:
        IllegalActionException - If the argument token and this token are of incomparable types, or the operation does not make sense for the given types.
      • getType

        public Type getType()
        Return the type of this token.
        Overrides:
        getType in class Token
        Returns:
        BaseType.XMLTOKEN.
      • toString

        public java.lang.String toString()
        Return the value of this Token as a string.
        Overrides:
        toString in class Token
        Returns:
        A String.
      • _isCloseTo

        protected BooleanToken _isCloseTo​(Token rightArgument,
                                          double epsilon)
                                   throws IllegalActionException
        Test for closeness of the values of this Token and the argument Token. It is assumed that the type of the argument is an XMLToken.
        Parameters:
        rightArgument - The token to add to this token.
        epsilon - The value that we use to determine whether two tokens are close. This parameter is ignored by this class.
        Returns:
        A BooleanToken containing the result.
        Throws:
        IllegalActionException - If this method is not supported by the derived class.
      • _isEqualTo

        protected BooleanToken _isEqualTo​(Token rightArgument)
                                   throws IllegalActionException
        Test for equality of the values of this Token and the argument Token. It is assumed that the type of the argument is XMLToken.
        Parameters:
        rightArgument - The token to add to this token.
        Returns:
        A BooleanToken containing the result.
        Throws:
        IllegalActionException - If this method is not supported by the derived class.