Sonic ESB API

com.sonicsw.esb.service.common.util.variables
Interface VariableParser

All Known Implementing Classes:
VariableParserImpl

public interface VariableParser

Utility for finding and resolving variable tokens in string content.

The simplest usage is to call replaceAllVariables(String) to find and replace all variable tokens in a string. For more complex cases use getVariableIterator(String) to obtain an iterator and operate on individual tokens.

VariableParser instances are not intended to be thread-safe.


Method Summary
 boolean containsVariables(java.lang.String content)
          Returns true if the given content contains one or more variable tokens.
 VariableFactory.Variable getVariable(java.lang.String content)
          Returns a Variable object for the given variable token.
 VariableIterator getVariableIterator(java.lang.String content)
          Creates an iterator over variable and literal tokens in the given string content.
 VariableResolverFactory getVariableResolverFactory()
          Gets the variable resolver factory used by this parser.
 boolean isVariable(java.lang.String content)
          Returns true if the given content consists of exactly one variable token.
 java.lang.String replaceAllVariables(java.lang.String content)
          Replaces all variables in the given string content.
 java.lang.String resolveVariable(java.lang.String variable)
          Resolves a single variable token, delegating to an appropriate VariableResolver.
 void setVariableResolverFactory(VariableResolverFactory resolverFactory)
          Sets the variable resolver factory to use for this parser.
 

Method Detail

containsVariables

boolean containsVariables(java.lang.String content)
Returns true if the given content contains one or more variable tokens. This does not try to resolve the variables.

Parameters:
content - string content to be examined
Returns:
true if one or more variables are found; false otherwise.

isVariable

boolean isVariable(java.lang.String content)
Returns true if the given content consists of exactly one variable token. This does not try to resolve the variable.

Parameters:
content - string content to be examined
Returns:
true if the content consists of exactly one variable token; false otherwise.

replaceAllVariables

java.lang.String replaceAllVariables(java.lang.String content)
Replaces all variables in the given string content. If the content consists only of variables that resolve to null, the result will be null.

Parameters:
content - string content to be examined
Returns:
string content after all variables have been replaced, or null

getVariableIterator

VariableIterator getVariableIterator(java.lang.String content)
Creates an iterator over variable and literal tokens in the given string content. This can be used in conjunction with resolveVariable(String) to implement custom variable substitution logic.

For example, the following approach could be used to only resolve a subset of the variables in a string:

 VariableIterator iter = parser.createIterator(content);
 StringBuffer result = new StringBuffer();
 while (iter.hasNext()) {
     String token = (String) iter.next();
     if (iter.wasLastTokenVariable() && shouldResolve(token)) {
         String value = parser.resolveVariable(token);
         result.append(value);
     } else {
         // don't resolve this variable
         result.append(token);
     }
 }
 

Parameters:
content - string content to iterate over
Returns:
an iterator over the variable/literal tokens of the content

resolveVariable

java.lang.String resolveVariable(java.lang.String variable)
Resolves a single variable token, delegating to an appropriate VariableResolver. Note that the result may be null.

Parameters:
variable - variable token to be resolved
Returns:
the value for the variable, or null if no value exists

getVariable

VariableFactory.Variable getVariable(java.lang.String content)
Returns a Variable object for the given variable token. Returns null if no appropriate resolver can be found or if the resolver does not implement VariableFactory.

This method is intended for tools support. The resulting Variable object must be cast to a concrete type to be of any use.

Returns:
a Variable, or null

getVariableResolverFactory

VariableResolverFactory getVariableResolverFactory()
Gets the variable resolver factory used by this parser. Note that while a parser is intended for single-threaded use, the resolver factory may be shared by multiple parsers.

Returns:
the resolver factory used by this parser

setVariableResolverFactory

void setVariableResolverFactory(VariableResolverFactory resolverFactory)
Sets the variable resolver factory to use for this parser.

Parameters:
resolverFactory - a variable resolver factory

Sonic ESB API

Copyright © 2001-2013 Aurea, Inc. All Rights Reserved.
HTML formatted on 29-April-2013.