Class ValueMacroExpression

  • All Implemented Interfaces:
    Expression<String>, ExternalizableLite, PortableObject, Serializable

    public class ValueMacroExpression
    extends Object
    implements Expression<String>, ExternalizableLite, PortableObject
    A ValueMacroExpression is a string value potentially containing expandable macros.

    Resolving the expression performs macro expansion. The macro syntax is ${macro-parameter default-value}. Thus, a value of near-${coherence.client direct} is macro expanded by default to near-direct. If property coherence.client is set to remote, then the value would be expanded to near-remote.

    As of Coherence 14.1.2.0.0, the following common shell parameter expansion capabilities have been added.

     ${macro-parameter ${macro-parameter-default default-value}}
     Supports nesting of macro parameters to enable the defaulting value to be configured as a macro-parameter.
     
    In addition to the default delimiter of a space character, the colon character indicates a modifier for macro expansion.
    Note that word referenced below is either a nested macro parameter default or the default value.

     ${macro-parameter:-word}
     If macro-parameter is unset or null, the expansion of wordis substituted,
     otherwise, the value of macro-parameter is substituted.
    
     ${macro-parameter:+word}
     If macro-parameter is null or unset, nothing is substituted,
     otherwise the expansion of word is substituted.
    
     ${macro-parameter:offset}
     ${macro-parameter:offset:length}
     Note that length and offset are integer values.
     
    See ValueMacroExpression.OffsetLengthSubstringExpansionProcessor.process(String, ParameterResolver, int) for substring expansion details and example usages.
    Since:
    Coherence 12.2.1
    Author:
    jf 2015.05.18
    See Also:
    Serialized Form
    • Field Detail

      • MAX_MACRO_EXPANSIONS

        public static int MAX_MACRO_EXPANSIONS
        Avoid recursive macro expansions that never return. No need for more than 20 macro expansions on one value.
      • PARAMETER_PREFIX

        public static final String PARAMETER_PREFIX
        Prefix indicating the start of a property macro.
        See Also:
        Constant Field Values
      • PARAMETER_SUFFIX

        public static final Character PARAMETER_SUFFIX
        Suffix indicating the close of a property macro.
      • SUBSTRING_OFFSET_LENGTH_EXPANSION

        public static final String SUBSTRING_OFFSET_LENGTH_EXPANSION
        Delimiter introducing substring expansion of optional :offset and/or :length in a macro parameter.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ValueMacroExpression

        public ValueMacroExpression()
        Default constructor needed for serialization.
      • ValueMacroExpression

        public ValueMacroExpression​(String value)
        Parameters:
        value - the value that potentially contains a macro expression.
    • Method Detail

      • substitute

        protected String substitute​(String sValue,
                                    ParameterResolver resolver,
                                    int cDepth)
        Return a string value containing no outstanding macro parameters.
        Parameters:
        sValue - a value containing 0 or more macro parameters
        resolver - a macro parameter resolver
        cDepth - current number of macro parameter resolutions
        Returns:
        a string value containing no outstanding macro parameters
      • processRegisteredMacroExpansions

        protected String processRegisteredMacroExpansions​(String sMacro,
                                                          ParameterResolver resolver,
                                                          int cDepth)
        Process macro expansion of sMacro by registered macro-expansion processors.
        Parameters:
        sMacro - macro parameter
        resolver - resolve macro parameter within sMacro
        cDepth - count of macro parameter expansions
        Returns:
        result of macro parameter expansion processing
      • containsMacro

        public boolean containsMacro()
        Check if this contains a macro.
        Returns:
        true iff this contains a macro
      • containsMacro

        public static boolean containsMacro​(String sValue)
        Check if string contains a macro.
        Parameters:
        sValue - string potentially containing a macro
        Returns:
        true iff the string value contains a macro
      • containsRegisteredDelimiter

        protected static boolean containsRegisteredDelimiter​(String sMacro)
        Return true if sMacro contains a registered delimiter.
        Parameters:
        sMacro - macro parameter
        Returns:
        true if sMacro string contains a registered delimiter
      • readExternal

        public void readExternal​(DataInput in)
                          throws IOException
        Restore the contents of this object by loading the object's state from the passed DataInput object.
        Specified by:
        readExternal in interface ExternalizableLite
        Parameters:
        in - the DataInput stream to read data from in order to restore the state of this object
        Throws:
        IOException - if an I/O exception occurs
        NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into
      • writeExternal

        public void writeExternal​(DataOutput out)
                           throws IOException
        Save the contents of this object by storing the object's state into the passed DataOutput object.
        Specified by:
        writeExternal in interface ExternalizableLite
        Parameters:
        out - the DataOutput stream to write the state of this object to
        Throws:
        IOException - if an I/O exception occurs
      • readExternal

        public void readExternal​(PofReader reader)
                          throws IOException
        Restore the contents of a user type instance by reading its state using the specified PofReader object.
        Specified by:
        readExternal in interface PortableObject
        Parameters:
        reader - the PofReader from which to read the object's state
        Throws:
        IOException - if an I/O error occurs
      • writeExternal

        public void writeExternal​(PofWriter writer)
                           throws IOException
        Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
        Specified by:
        writeExternal in interface PortableObject
        Parameters:
        writer - the PofWriter to which to write the object's state
        Throws:
        IOException - if an I/O error occurs