Package com.tangosol.config.expression
Class ValueMacroExpression
- java.lang.Object
-
- com.tangosol.config.expression.ValueMacroExpression
-
- All Implemented Interfaces:
Expression<String>
,ExternalizableLite
,PortableObject
,Serializable
public class ValueMacroExpression extends Object implements Expression<String>, ExternalizableLite, PortableObject
AValueMacroExpression
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.
SeeValueMacroExpression.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ValueMacroExpression.DefaultDelimiterExpansionProcessor
Process macro parameter default delimiter expansion.protected static class
ValueMacroExpression.MacroExpansionProcessor
A Macro Expansion Processor for a macro not containing any registered delimiters.protected static class
ValueMacroExpression.OffsetLengthSubstringExpansionProcessor
Process:offset
and:length
substring expansion.
protected static class
ValueMacroExpression.SpaceDefaultDelimiterExpansionProcessor
ValueMacroExpression.SpaceDefaultDelimiterExpansionProcessor
performs DefaultDelimiter expansion processing and disambiguates: -
for offset and length from space for default delimiter.
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_MACRO_EXPANSIONS
Avoid recursive macro expansions that never return.static String
PARAMETER_PREFIX
Prefix indicating the start of a property macro.static Character
PARAMETER_SUFFIX
Suffix indicating the close of a property macro.static String
SUBSTRING_OFFSET_LENGTH_EXPANSION
Delimiter introducing substring expansion of optional :offset and/or :length in a macro parameter.
-
Constructor Summary
Constructors Constructor Description ValueMacroExpression()
Default constructor needed for serialization.ValueMacroExpression(String value)
Construct aValueMacroExpression
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsMacro()
Check if this contains a macro.static boolean
containsMacro(String sValue)
Check if string contains a macro.protected static boolean
containsRegisteredDelimiter(String sMacro)
Return true ifsMacro
contains aregistered delimiter
.String
evaluate(ParameterResolver resolver)
Evaluates theExpression
to produce a value of type T.protected String
processRegisteredMacroExpansions(String sMacro, ParameterResolver resolver, int cDepth)
Process macro expansion ofsMacro
byregistered macro-expansion processors
.void
readExternal(PofReader reader)
Restore the contents of a user type instance by reading its state using the specified PofReader object.void
readExternal(DataInput in)
Restore the contents of this object by loading the object's state from the passed DataInput object.protected String
substitute(String sValue, ParameterResolver resolver, int cDepth)
Return a string value containing no outstanding macro parameters.String
toString()
void
writeExternal(PofWriter writer)
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.void
writeExternal(DataOutput out)
Save the contents of this object by storing the object's state into the passed DataOutput object.
-
-
-
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)
Construct aValueMacroExpression
.- Parameters:
value
- the value that potentially contains a macro expression.
-
-
Method Detail
-
evaluate
public String evaluate(ParameterResolver resolver)
Evaluates theExpression
to produce a value of type T.- Specified by:
evaluate
in interfaceExpression<String>
- Parameters:
resolver
- theParameterResolver
for resolving any parameters used by theExpression
- Returns:
- The result of evaluating the expression
-
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 parametersresolver
- amacro 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 ofsMacro
byregistered macro-expansion processors
.- Parameters:
sMacro
- macro parameterresolver
- resolve macro parameter withinsMacro
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 ifsMacro
contains aregistered 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 interfaceExternalizableLite
- 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 occursNotActiveException
- 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 interfaceExternalizableLite
- 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 interfacePortableObject
- 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 interfacePortableObject
- Parameters:
writer
- the PofWriter to which to write the object's state- Throws:
IOException
- if an I/O error occurs
-
-