com.edustructures.sifworks
Class DefaultValueBuilder

java.lang.Object
  extended by com.edustructures.sifworks.DefaultValueBuilder
All Implemented Interfaces:
ValueBuilder

public class DefaultValueBuilder
extends java.lang.Object
implements ValueBuilder

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

DefaultValueBuilder

public DefaultValueBuilder(FieldAdaptor data)
Creates an instance of DefaultValueBuilder that builds values based on the SIFDataMap, using the ADK's default text formatter

Parameters:
data -

DefaultValueBuilder

public DefaultValueBuilder(FieldAdaptor data,
                           SIFFormatter formatter)
Creates an instance of DefaultValueBuilder that builds values based on the SIFDataMap, using the specified SIFFormatter instance

Parameters:
data -
formatter -
Method Detail

getData

public FieldAdaptor getData()
Returns the MappingsAdaptor

Returns:
The MappingsAdaptor passed to the constructor

evaluate

public java.lang.String evaluate(java.lang.String expression)
Evaluate an expression that the implementation of this interface understands to return a String value.

Specified by:
evaluate in interface ValueBuilder
Parameters:
expression - The expression to evaluate
Returns:
The value built from the expression

java

public 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


replaceTokens

public 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

Parameters:
src - The source string
adaptor - A set of data values
formatter - The SIFFormatter to use for creating String representations of SIF data.

pad

public 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. If the Source string is already equal to or greater than Width, no action is taken.


toUpperCase

public static java.lang.String toUpperCase(ValueBuilder vb,
                                           java.lang.String source)
"@toUpperCase( Source )" Converts the source string to uppercase


toLowerCase

public static java.lang.String toLowerCase(ValueBuilder vb,
                                           java.lang.String source)
"@toLowerCase( Source )" Converts the source string to lowercase


toMixedCase

public static java.lang.String toMixedCase(ValueBuilder vb,
                                           java.lang.String source)
"@toMixedCase( Source )" Converts the source string to mixed case


setDefaultClass

public static void setDefaultClass(java.lang.String clazz)
Specifies the default class for Java method calls that do not reference a fully-qualified class name. com.edustructures.sifworks.DefaultValueBuilder is used as the default unless this method is called to change it.

Parameters:
clazz - The name of a class (e.g. "com.edustructures.sifworks.DefaultValueBuilder")

addAlias

public static void addAlias(java.lang.String alias,
                            java.lang.String method)
Registers an alias to a static Java method.

Parameters:
alias - The alias name (e.g. "doSomething")
method - The fully-qualified Java method name (e.g. "com.mycompany.MyValueBuilder.doSomething")


Copyright © 2001-2007 Edustructures LLC. All Rights Reserved. SIFWorks® and ADK® are registered trademarks of Edustructures LLC. SIF™ and Schools Interoperability Framework are trademarks of the Schools Interoperability Framework Association.