|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.edustructures.sifworks.DefaultValueBuilder
public class DefaultValueBuilder
The default ValueBuilder implementation evaluates an expression to produce a string value.
The ValueBuilder interface is used by the SIFDTD, SIFDataObject, and Mappings
classes when evaluating XPath-like query strings. It enables developers to
customize the way the ADK evaluates value expressions in these query strings
to produce a value for a SIF element or attribute. The DefaultValueBuilder
implementation supports $(variable) token replacement as well as
@com.class.method style calls to static Java methods.
Token Replacement
When a $(variable) token is found in an expression, it is
replaced with a value from the Map passed to evaluate. For
example, if the Map constains the entry "color=blue", calling the evaluate
method with the expression "The color is $(color)" would produce the
string "The color is blue".
Java Method Calls
When a @method( arg1, arg2, ... ) call is found in an expression,
the static Java method is called and its return value inserted into the value
string. Token replacement is performed before calling the method.
If method is not fully-qualified, it is assumed to be a method
declared by this DefaultValueBuilder class. The default class can be changed
by calling the setDefaultClass method. When writing your own
static method, the first parameter must be of type ValueBuilder; zero or
more String parameters may follow. The function must return a String:
String method( ValueBuilder vb, String p1, String p2, ... ).
In the following example, the toUpperCase static method is called to convert
the $(color) variable to uppercase. This expression would yield the result
"The color is BLUE":
The color is @com.edustructures.sifworks.DefaultValueBuilder.toUpperCase( $(color) )
The following static methods are defined by this class:
| Method | Description |
pad( source, padding, width ) |
Pads the source string with padding such that the resulting string is width characters in length. |
toUpperCase( source ) |
Converts the source string to uppercase |
toLowerCase( source ) |
Converts the source string to lowercase |
toMixedCase( source ) |
Converts the source string to mixed case |
| Constructor Summary | |
|---|---|
DefaultValueBuilder(FieldAdaptor data)
Creates an instance of DefaultValueBuilder that builds values based on the SIFDataMap, using the ADK's default text formatter |
|
DefaultValueBuilder(FieldAdaptor data,
SIFFormatter formatter)
Creates an instance of DefaultValueBuilder that builds values based on the SIFDataMap, using the specified SIFFormatter instance |
|
| Method Summary | |
|---|---|
static void |
addAlias(java.lang.String alias,
java.lang.String method)
Registers an alias to a static Java method. |
java.lang.String |
evaluate(java.lang.String expression)
Evaluate an expression that the implementation of this interface understands to return a String value. |
FieldAdaptor |
getData()
Returns the MappingsAdaptor |
java.lang.String |
java(java.lang.String src)
Calls all Java methods referenced in the source string to replace the method reference with the string representation of the method's return value |
static java.lang.String |
pad(ValueBuilder vb,
java.lang.String source,
java.lang.String padding,
java.lang.String width)
"@pad( Source, PadChar, Width )" Pads the Source string with the specified PadChar character so that the source string is at least Width characters in length. |
static java.lang.String |
replaceTokens(java.lang.String src,
FieldAdaptor adaptor,
SIFFormatter formatter)
Replaces all $(variable) tokens in the source string with
the corresponding entry in the supplied Map |
static void |
setDefaultClass(java.lang.String clazz)
Specifies the default class for Java method calls that do not reference a fully-qualified class name. |
static java.lang.String |
toLowerCase(ValueBuilder vb,
java.lang.String source)
"@toLowerCase( Source )" Converts the source string to lowercase |
static java.lang.String |
toMixedCase(ValueBuilder vb,
java.lang.String source)
"@toMixedCase( Source )" Converts the source string to mixed case |
static java.lang.String |
toUpperCase(ValueBuilder vb,
java.lang.String source)
"@toUpperCase( Source )" Converts the source string to uppercase |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultValueBuilder(FieldAdaptor data)
data -
public DefaultValueBuilder(FieldAdaptor data,
SIFFormatter formatter)
SIFFormatter instance
data - formatter - | Method Detail |
|---|
public FieldAdaptor getData()
public java.lang.String evaluate(java.lang.String expression)
evaluate in interface ValueBuilderexpression - The expression to evaluate
public java.lang.String java(java.lang.String src)
public static java.lang.String replaceTokens(java.lang.String src,
FieldAdaptor adaptor,
SIFFormatter formatter)
$(variable) tokens in the source string with
the corresponding entry in the supplied Map
src - The source stringadaptor - A set of data valuesformatter - The SIFFormatter to use for creating String representations
of SIF data.
public static java.lang.String pad(ValueBuilder vb,
java.lang.String source,
java.lang.String padding,
java.lang.String width)
public static java.lang.String toUpperCase(ValueBuilder vb,
java.lang.String source)
public static java.lang.String toLowerCase(ValueBuilder vb,
java.lang.String source)
public static java.lang.String toMixedCase(ValueBuilder vb,
java.lang.String source)
public static void setDefaultClass(java.lang.String clazz)
com.edustructures.sifworks.DefaultValueBuilder
is used as the default unless this method is called to change it.
clazz - The name of a class (e.g. "com.edustructures.sifworks.DefaultValueBuilder")
public static void addAlias(java.lang.String alias,
java.lang.String method)
alias - The alias name (e.g. "doSomething")method - The fully-qualified Java method name (e.g. "com.mycompany.MyValueBuilder.doSomething")
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||