org.eclipse.datatools.connectivity.oda.util
Class StringSubstitutionUtil

java.lang.Object
  extended by org.eclipse.datatools.connectivity.oda.util.StringSubstitutionUtil

public final class StringSubstitutionUtil
extends java.lang.Object

StringSubstitutionUtil is a general utility that any ODA provider can use, which performs string substitutions. The utility is designed for ODA data sources that has a concept of embedded delimited strings in text strings. For example, an ODA driver query text could contain embedded parameters in the form of a colon followed by a parameter name, like ":myVariable". Two forms of string substitutions are supported by the utility: subsitution by index or by name.


Method Summary
static int getDelimitedStringCount(java.lang.String text, java.lang.String startDelimiter)
          Returns the number of named and un-named delimited strings in the text argument, where the delimited strings are labeled by only a start delimiter.
static int getDelimitedStringCount(java.lang.String text, java.lang.String startDelimiter, boolean requiresNamedDelimiters)
          Returns the number of delimited strings in the text argument, where the delimited strings are labeled by only a start delimiter.
static int getDelimitedStringCount(java.lang.String text, java.lang.String startDelimiter, java.lang.String endDelimiter)
          Returns the number of named and un-named delimited strings in the text argument, where the delimited strings are labeled by a start delimiter and an end delimiter.
static int getDelimitedStringCount(java.lang.String text, java.lang.String startDelimiter, java.lang.String endDelimiter, boolean requiresNamedDelimiters)
          Returns the number of delimited strings in the text argument, where the delimited strings are labeled by a start delimiter and an end delimiter.
static void resetLogger()
          Resets the StringSubstitutionUtil logger.
static void setLogger(java.util.logging.Logger logger)
          Sets the StringSubstitutionUtil logger to log its utility methods.
static java.lang.String substituteByIndex(java.lang.String text, java.lang.String startDelimiter, java.util.List substitutionList)
          Performs string substitution based on index, where the delimited strings are labeled by only a start delimiter.
static java.lang.String substituteByIndex(java.lang.String text, java.lang.String startDelimiter, java.lang.String endDelimiter, java.util.List substitutionList)
          Performs string substitution based on index, where the delimited strings are labeled by a start delimiter and an end delimiter.
static java.lang.String substituteByName(java.lang.String text, java.lang.String startDelimiter, java.util.Map nameValues)
          Performs string substitution based on name, where the delimited strings are labeled by only a start delimiter.
static java.lang.String substituteByName(java.lang.String text, java.lang.String startDelimiter, java.lang.String endDelimiter, java.util.Map nameValues)
          Performs string substitution based on name, where the delimited strings are labeled by a start delimiter and an end delimiter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setLogger

public static void setLogger(java.util.logging.Logger logger)
Sets the StringSubstitutionUtil logger to log its utility methods.

Parameters:
logger - the logger that StringSubstitutionUti uses to log its methods.

resetLogger

public static void resetLogger()
Resets the StringSubstitutionUtil logger. The caller of setLogger should call this to remove its logger from the StringSubstituionUtil. Otherwise, subsequent calls to this utility's methods by other callers may be logged in the set logger.


getDelimitedStringCount

public static int getDelimitedStringCount(java.lang.String text,
                                          java.lang.String startDelimiter)
Returns the number of named and un-named delimited strings in the text argument, where the delimited strings are labeled by only a start delimiter. Calls getDelimitedStringCount( text, startDelimiter, false ).

Parameters:
text - string containing delimited strings.
startDelimiter - the start delimiter string.
Returns:
the number of named and un-named delimited strings.
See Also:
getDelimitedStringCount

getDelimitedStringCount

public static int getDelimitedStringCount(java.lang.String text,
                                          java.lang.String startDelimiter,
                                          boolean requiresNamedDelimiters)
Returns the number of delimited strings in the text argument, where the delimited strings are labeled by only a start delimiter. If requiresNamedDelimiters is set to true, only the named delimiters will be counted. This should be used when the caller wants to perform substitution by name on the text string. Otherwise, both named and un-named delimiters will be counted. This should be used when the caller wants to perform substitution by index on the text string.

For example:
text = ":param1 :param2 :param3"
startDelimiter = ":"
returns: 3

Parameters:
text - string containing delimited strings.
startDelimiter - the start delimiter string.
requiresNamedDelimiters - determines whether only named delimiters will be counted.
Returns:
the number of delimited strings.
Throws:
java.lang.NullPointerException - if text or startDelimiter is null.

getDelimitedStringCount

public static int getDelimitedStringCount(java.lang.String text,
                                          java.lang.String startDelimiter,
                                          java.lang.String endDelimiter)
Returns the number of named and un-named delimited strings in the text argument, where the delimited strings are labeled by a start delimiter and an end delimiter. Calls getDelimitedStringCount( text, startDelimiter, endDelimiter, false ).

Parameters:
text - string containing delimited strings.
startDelimiter - the start delimiter string.
endDelimiter - the end delimiter string.
Returns:
the number of named and un-named delimited strings.
See Also:
getDelimitedStringCount

getDelimitedStringCount

public static int getDelimitedStringCount(java.lang.String text,
                                          java.lang.String startDelimiter,
                                          java.lang.String endDelimiter,
                                          boolean requiresNamedDelimiters)
Returns the number of delimited strings in the text argument, where the delimited strings are labeled by a start delimiter and an end delimiter. If requiresNamedDelimiters is set to true, only the named delimiters will be counted. This should be used when the caller wants to perform substitution by name on the text string. Otherwise, both named and un-named delimiters will be counted. This should be used when the caller wants to perform substitution by index on the text string.

For example:
text = "select <start>param1<end>.* from STUDENT"
startDelimiter = "<start>"
endDelimiter = "<end>"
returns: 1

Parameters:
text - string containing delimited strings.
startDelimiter - the start delimiter string.
endDelimiter - the end delimiter string.
requiresNamedDelimiters - determines whether only named delimiters will be counted.
Returns:
the number of delimited strings.
Throws:
java.lang.NullPointerException - if text, startDelimiter, or endDelimiter is null.

substituteByIndex

public static java.lang.String substituteByIndex(java.lang.String text,
                                                 java.lang.String startDelimiter,
                                                 java.util.List substitutionList)
Performs string substitution based on index, where the delimited strings are labeled by only a start delimiter.

For example:
text = "SELECT STUDENT.:COLUMN, STUDENT.:COLUMN FROM STUDENT"
startDelimiter = ":"
substitutionList = ["ID", "NAME"]
returns: "SELECT STUDENT.ID, STUDENT.NAME FROM STUDENT"

Parameters:
text - text string containing delimited strings.
startDelimiter - the start delimiter string.
substitutionList - list of substitution values for the delimited strings.
Returns:
the fully substituted string.
Throws:
java.lang.NullPointerException - if text, startDelimiter, or substitutionList is null.

substituteByIndex

public static java.lang.String substituteByIndex(java.lang.String text,
                                                 java.lang.String startDelimiter,
                                                 java.lang.String endDelimiter,
                                                 java.util.List substitutionList)
Performs string substitution based on index, where the delimited strings are labeled by a start delimiter and an end delimiter.

For example:
text = "SELECT <start>TABLE<end>.<start>COLUMN<end> FROM STUDENT"
startDelimiter = "<start>"
endDelimiter = "<end>"
substitutionList = ["STUDENT", "NAME"]
returns: "SELECT STUDENT.NAME FROM STUDENT"

Parameters:
text - text string containing delimited strings.
startDelimiter - the start delimiter string.
endDelimiter - the end delimiter string.
substitutionList - list of substitution values for the delimited strings.
Returns:
the fully substituted string.
Throws:
java.lang.NullPointerException - if text, startDelimiter, endDelimiter, or substitutionList is null.

substituteByName

public static java.lang.String substituteByName(java.lang.String text,
                                                java.lang.String startDelimiter,
                                                java.util.Map nameValues)
Performs string substitution based on name, where the delimited strings are labeled by only a start delimiter.

For example:
text = "SELECT ?PARAM.?PARAM1 FROM ?PARAM"
startDelimiter = "?"
nameValues = {PARAM=PEOPLE, PARAM1=NAME}
returns: "SELECT PEOPLE.NAME FROM PEOPLE"

Parameters:
text - text string containing delimited strings.
startDelimiter - the start delimiter string.
nameValues - map of substitution name-value pairs.
Returns:
the fully substituted string.
Throws:
java.lang.NullPointerException - if text, startDelimiter, or nameValues is null.

substituteByName

public static java.lang.String substituteByName(java.lang.String text,
                                                java.lang.String startDelimiter,
                                                java.lang.String endDelimiter,
                                                java.util.Map nameValues)
Performs string substitution based on name, where the delimited strings are labeled by a start delimiter and an end delimiter.

For example:
text = "SELECT :PARAM:.:PARAM1: FROM :PARAM:
startDelimiter = ":"
endDelimiter = ":"
nameValues = {PARAM=PEOPLE, PARAM1=NAME}
returns: "SELECT PEOPLE.NAME FROM PEOPLE"

Parameters:
text - text string containing delimited strings.
startDelimiter - the start delimiter string.
endDelimiter - the end delimiter string.
nameValues - map of substitution name-value pairs.
Returns:
the fully substituted string.
Throws:
java.lang.NullPointerException - if text, startDelimiter, endDelimiter, or nameValues is null.