org.xlattice.corexml.bind
Class Binding

java.lang.Object
  extended by org.xlattice.corexml.bind.Join
      extended by org.xlattice.corexml.bind.Binding
Direct Known Subclasses:
AttrBinding, EmptyElBinding, SubElBinding, TextBinding

public abstract class Binding
extends Join

Superclass for Joins that bind XML element or attribute values to fields in Java objects. The fields are either Java primitives or Strings.

Author:
Jim Dixon

Field Summary
protected  int argTypeIndex
          argument type as index into the list of types above
static int BOOLEAN
          boolean field
static int BYTE
           
static int CHAR
           
static int DOUBLE
           
protected  java.lang.String fieldName
          name of the object field being bound to
static int FLOAT
           
static int INT
           
static int LONG
           
static int SHORT
           
static int STRING
          String field
static java.lang.String[] TYPES
          names of field types, for diagnostic messages
 
Fields inherited from class org.xlattice.corexml.bind.Join
ATTRBINDING, clazz, COLLECTOR, EMPTYEL, getter, getterName, INTERFACE, JOIN_TYPES, joined, MAPPING, maxOccur, minOccur, name, setter, setterName, sizer, sizerName, SUBEL, SUBMAPPING, TEXT, UNSPECIFIED
 
Constructor Summary
Binding(java.lang.String name)
           
Binding(java.lang.String name, java.lang.String fieldName)
          Create a binding between an XML name (tag or attribute name) and a field in an associated class.
 
Method Summary
protected  void findMethods(java.lang.Class clazz)
          Overrides the method in the superclass, Join.
protected  java.lang.String getField(java.lang.Object o)
          Get the value of the associated field in a bound object as a String.
protected static int getTypeIndex(java.lang.Class argType)
          Given a method argument type learned by reflection, return the index of that type.
protected  void join(java.lang.Class clazz)
          Method called when the definition of the Mapping is complete.
 Binding optional()
          The joined element or attribute need not appear in the XML and should not be output if the field has its default value.
 Binding repeats()
          The joined element may be repeated any number of times.
protected  void setField(java.lang.Object o, java.lang.String value)
          Set a field in the bound object to the value passed.
 Binding setGetter(java.lang.String g)
          Set the unqualified name of the field getter method.
 Binding setMaxOccur(int n)
          Set the maximum number of times a bound value may occur.
 Binding setMinOccur(int n)
          Set the minimum number of times a bound value must occur.
 Binding setSetter(java.lang.String s)
          Set the unqualified name of the field setter method.
 Binding setSizer(java.lang.String s)
          Set the unqualified name of the sizer method.
protected static java.lang.String typeToString(int i)
           
 
Methods inherited from class org.xlattice.corexml.bind.Join
_getGetterName, _getSetterName, _getSizerName, _setGetter, _setMaxOccur, _setMinOccur, _setSetter, _setSizer, apply, checkElmJoin, checkJoinObject, checkNameAndState, generate, getClazz, getMaxOccur, getMinOccur, getName, joined, joinType, setClazz, size, tagMatch
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN

public static final int BOOLEAN
boolean field

See Also:
Constant Field Values

CHAR

public static final int CHAR
See Also:
Constant Field Values

FLOAT

public static final int FLOAT
See Also:
Constant Field Values

DOUBLE

public static final int DOUBLE
See Also:
Constant Field Values

BYTE

public static final int BYTE
See Also:
Constant Field Values

SHORT

public static final int SHORT
See Also:
Constant Field Values

INT

public static final int INT
See Also:
Constant Field Values

LONG

public static final int LONG
See Also:
Constant Field Values

STRING

public static final int STRING
String field

See Also:
Constant Field Values

TYPES

public static final java.lang.String[] TYPES
names of field types, for diagnostic messages


fieldName

protected final java.lang.String fieldName
name of the object field being bound to


argTypeIndex

protected int argTypeIndex
argument type as index into the list of types above

Constructor Detail

Binding

public Binding(java.lang.String name,
               java.lang.String fieldName)
Create a binding between an XML name (tag or attribute name) and a field in an associated class. By default the setter method name is 'set' concatenated with the field name with first letter capitalized. The getter name is constructed in the same way. These default names may be overridden.

Parameters:
name - of an element name (tag) or attribute name
fieldName - base name used in field setter/getter methods

Binding

public Binding(java.lang.String name)
Method Detail

setMaxOccur

public Binding setMaxOccur(int n)
Set the maximum number of times a bound value may occur.

Parameters:
n - maximum number of occurrences
Returns:
reference to this, for chaining

setMinOccur

public Binding setMinOccur(int n)
Set the minimum number of times a bound value must occur.

Parameters:
n - minimum number of occurrences
Returns:
reference to this, for chaining

optional

public Binding optional()
The joined element or attribute need not appear in the XML and should not be output if the field has its default value. That is, this sets minOccur to zero. XXX DEFAULT VALUE CHECKS ARE NOT CURRENTLY IMPLEMENTED

Returns:
reference to this, for chaining

repeats

public Binding repeats()
The joined element may be repeated any number of times. That is, this sets maxOccur to Integer.MAX_VALUE.

Returns:
reference to this, for chaining

setGetter

public Binding setGetter(java.lang.String g)
Set the unqualified name of the field getter method. This overrides the default getter name.

Parameters:
g - new name of the getter
Returns:
a reference to this Binding, a convenience in chaining

setSetter

public Binding setSetter(java.lang.String s)
Set the unqualified name of the field setter method. This overrides the default setter name.

Parameters:
s - new name of the setter
Returns:
a reference to this Binding, a convenience in chaining

setSizer

public Binding setSizer(java.lang.String s)
Set the unqualified name of the sizer method. This overrides the default setter name. The sizer method is used to determine the number of values present in a bound Java object.

Parameters:
s - new name of the setter
Returns:
a reference to this Binding, a convenience in chaining

join

protected void join(java.lang.Class clazz)
             throws CoreXmlException
Method called when the definition of the Mapping is complete. This assigns the parent class, finds getter/setter/sizer methods, and determines the type of the field in the bound object.

Specified by:
join in class Join
Parameters:
clazz - Class involved in the Join
Throws:
CoreXmlException

findMethods

protected void findMethods(java.lang.Class clazz)
                    throws CoreXmlException
Overrides the method in the superclass, Join. Done this way because we need to know the setter type before assigning the default getter type.

Overrides:
findMethods in class Join
Throws:
CoreXmlException

getField

protected java.lang.String getField(java.lang.Object o)
                             throws CoreXmlException
Get the value of the associated field in a bound object as a String.

Parameters:
o - object involved in this Binding
Throws:
CoreXmlException

setField

protected void setField(java.lang.Object o,
                        java.lang.String value)
                 throws CoreXmlException
Set a field in the bound object to the value passed. The calling method must have confirmed that the object is an instance of the appropriate class and that the binding has been joined.

Parameters:
o - object that the binding is to be applied to
value - String value to be set; must be converted
Throws:
CoreXmlException

typeToString

protected static final java.lang.String typeToString(int i)
Returns:
the string corresponding to a type index

getTypeIndex

protected static int getTypeIndex(java.lang.Class argType)
Given a method argument type learned by reflection, return the index of that type.

Parameters:
argType - learned from reflection
Returns:
type index