Class Token

  • All Implemented Interfaces:
    BeanReferenceable, Replicable<Token>

    public class Token
    extends java.lang.Object
    implements BeanReferenceable, Replicable<Token>
    A token has a string value of its own or contains information for fetching a specific value from another provider.

    The following symbols are used to distinguish the providers of values:

    #

    Refers to a bean specified by the Bean Registry.

    ex)
    • #{beanId}
    • #{beanId^getterName}
    • #{beanId^getterName:defaultString}
    • #{class:className}
    • #{class:className^getterName}
    • #{class:className^getterName:defaultString}
    ~

    Refers to a string formatted from the Template Rule Registry.

    ex)
    • ~{templateId}
    • ~{templateId:defaultString}
    $

    Refers to a parameter value.

    ex)
    • ${parameterName}
    • ${parameterName:defaultString}
    @

    Refers to an attribute value.

    ex)
    • @{attributeName}
    • @{attributeName:defaultString}
    • @{attributeName^getterName:defaultString}
    %

    Refers to a property from the specified Properties file or environment variables.

    ex)
    • %{environmentPropertyName}
    • %{classpath:propertiesPath^getterName}
    • %{classpath:propertiesPath^getterName:defaultString}

    Created: 2008. 03. 27 PM 10:20:06

    • Constructor Detail

      • Token

        public Token​(java.lang.String defaultValue)
        Instantiates a new Token.
        Parameters:
        defaultValue - the default value
      • Token

        public Token​(TokenType type,
                     java.lang.String name)
        Instantiates a new Token.
        Parameters:
        type - the token type
        name - the token name
      • Token

        public Token​(TokenType type,
                     TokenDirectiveType directiveType,
                     java.lang.String value)
        Instantiates a new Token.
        Parameters:
        type - the token type
        directiveType - the token directive type
        value - the token value
    • Method Detail

      • getType

        public TokenType getType()
        Gets the token type.
        Returns:
        the token type
      • getName

        public java.lang.String getName()
        Gets the token name.
        Returns:
        the token name
      • getValue

        public java.lang.String getValue()
        Returns the class name of the bean or the classpath of the Properties file, depending on the type of token. For example, if the token type is "bean" and the token name is "class", the value of the token is the class name of the bean. Also, if the token type is "property" and the token name is "classpath", the value of the token is the path to reference in the Properties file.
        Returns:
        the default value or bean's class name
      • setValue

        public void setValue​(java.lang.String value)
        Sets the class name of the bean or the classpath of the Properties file, depending on the type of the token.
        Parameters:
        value - the class name of the bean or the classpath of the Properties file
      • getGetterName

        public java.lang.String getGetterName()
        Gets the name of the property whose value is to be retrieved.
        Returns:
        the name of the property whose value is to be retrieved
      • getAlternativeValue

        public java.lang.Object getAlternativeValue()
        Gets the alternative value. It is a value corresponding to class name or class path according to token directive.
        Returns:
        the alternative value
      • setAlternativeValue

        public void setAlternativeValue​(java.lang.Object value)
        Sets the alternative value. It is a value corresponding to class name or class path according to token directive.
        Parameters:
        value - the new alternative value
      • setGetterName

        public void setGetterName​(java.lang.String getterName)
        Sets the name of the property whose value is to be retrieved.
        Parameters:
        getterName - the name of the property whose value is to be retrieved
      • getDefaultValue

        public java.lang.String getDefaultValue()
        Gets the default value.
        Returns:
        the default value
      • setDefaultValue

        public void setDefaultValue​(java.lang.String defaultValue)
        Sets the default value.
        Parameters:
        defaultValue - the new default value
      • stringify

        public java.lang.String stringify()
        Convert a Token object into a string.
        Returns:
        a string representation of the token
      • equals

        public boolean equals​(java.lang.Object token)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • replicate

        public Token replicate()
        Description copied from interface: Replicable
        Creates and returns a new instance after replicating a rule or Object.
        Specified by:
        replicate in interface Replicable<Token>
        Returns:
        replicated rule or new instance of Object
      • replicate

        public Token[] replicate​(Token[] tokens)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isTokenSymbol

        public static boolean isTokenSymbol​(char c)
        Returns whether a specified character is the token symbol.
        Parameters:
        c - a character
        Returns:
        true, if a specified character is one of the token symbols
      • hasToken

        public static boolean hasToken​(java.lang.String str)
      • resolveTypeAsSymbol

        public static TokenType resolveTypeAsSymbol​(char symbol)
        Returns the token type for the specified character.
        Parameters:
        symbol - the token symbol character
        Returns:
        the token type
      • resolveAlternativeValue

        public static void resolveAlternativeValue​(Token token,
                                                   java.lang.ClassLoader classLoader)