Sonic ESB API

com.sonicsw.esb.service.common.util.variables
Class VariableParserImpl

java.lang.Object
  extended by com.sonicsw.esb.service.common.util.variables.VariableParserImpl
All Implemented Interfaces:
VariableParser

public class VariableParserImpl
extends java.lang.Object
implements VariableParser

Default VariableParser implementation that handles variables of the form ${uri}.


Constructor Summary
VariableParserImpl()
           
 
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 token)
          Resolves a single variable token, delegating to an appropriate VariableResolver.
 void setVariableResolverFactory(VariableResolverFactory resolverFactory)
          Sets the variable resolver factory to use for this parser.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableParserImpl

public VariableParserImpl()
Method Detail

replaceAllVariables

public java.lang.String replaceAllVariables(java.lang.String content)
Description copied from interface: VariableParser
Replaces all variables in the given string content. If the content consists only of variables that resolve to null, the result will be null.

Specified by:
replaceAllVariables in interface VariableParser
Parameters:
content - string content to be examined
Returns:
string content after all variables have been replaced, or null

containsVariables

public boolean containsVariables(java.lang.String content)
Description copied from interface: VariableParser
Returns true if the given content contains one or more variable tokens. This does not try to resolve the variables.

Specified by:
containsVariables in interface VariableParser
Parameters:
content - string content to be examined
Returns:
true if one or more variables are found; false otherwise.

isVariable

public boolean isVariable(java.lang.String content)
Description copied from interface: VariableParser
Returns true if the given content consists of exactly one variable token. This does not try to resolve the variable.

Specified by:
isVariable in interface VariableParser
Parameters:
content - string content to be examined
Returns:
true if the content consists of exactly one variable token; false otherwise.

getVariableIterator

public VariableIterator getVariableIterator(java.lang.String content)
Description copied from interface: VariableParser
Creates an iterator over variable and literal tokens in the given string content. This can be used in conjunction with VariableParser.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);
     }
 }
 

Specified by:
getVariableIterator in interface VariableParser
Parameters:
content - string content to iterate over
Returns:
an iterator over the variable/literal tokens of the content

resolveVariable

public java.lang.String resolveVariable(java.lang.String token)
Description copied from interface: VariableParser
Resolves a single variable token, delegating to an appropriate VariableResolver. Note that the result may be null.

Specified by:
resolveVariable in interface VariableParser
Parameters:
token - variable token to be resolved
Returns:
the value for the variable, or null if no value exists

getVariable

public VariableFactory.Variable getVariable(java.lang.String content)
Description copied from interface: VariableParser
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.

Specified by:
getVariable in interface VariableParser
Returns:
a Variable, or null

setVariableResolverFactory

public void setVariableResolverFactory(VariableResolverFactory resolverFactory)
Description copied from interface: VariableParser
Sets the variable resolver factory to use for this parser.

Specified by:
setVariableResolverFactory in interface VariableParser
Parameters:
resolverFactory - a variable resolver factory

getVariableResolverFactory

public VariableResolverFactory getVariableResolverFactory()
Description copied from interface: VariableParser
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.

Specified by:
getVariableResolverFactory in interface VariableParser
Returns:
the resolver factory used by this parser

Sonic ESB API

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