|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.edustructures.sifworks.tools.mapping.FieldMapping
public class FieldMapping
A FieldMapping defines how to map a local application field to an element or attribute of the SIF Data Object type encapsulated by the parent ObjectMapping. Each FieldMapping is associated with a Rule that is evaluated at runtime to carry out the actual mapping operation on a SIFDataObject instance. The way the rule behaves is up to its implementation.
A FieldMapping may have a default value. If set, the default value is assigned to the SIF element or attribute if the corresponding field value is null or undefined. This is useful if you wish to ensure that a specific SIF element/attribute always has a value regardless of whether or not there is a corresponding value in your application's database.
A Field Mapping that has a default value can also set another attribute that specifies the behavior of the Field Mapping if the application value being mapped is null.
The application-defined field name that is associated with a FieldMapping must be unique; that is, there cannot be more than one FieldMapping for the same application field. However, if you wish to map the same field to more than one SIF element or attribute, you can create an alias. An alias is a FieldMapping that has a unique field name but refers to another field. For example, if your application defines the field STUDENT_NUM and you wish to define two FieldMappings for that field, create an alias:
// Create the default mapping
In the above example, the "STUDENT_NUM" mapping produces an <OtherId>
element with its Type attribute set to '06'. The "MYALIAS" mapping produces
a second <OtherId> element with its Type attribute set to 'ZZ'. Both
elements will have the value of the application-defined STUDENT_NUM field.
Note that if MYALIAS were an actual field name of your application, however,
the value of the <OtherId Type='ZZ'> element would be equal to that
field's value. When creating aliases be sure to choose a name that does not
conflict with the real field names used by your application.
FieldMapping fm = new FieldMapping("STUDENT_NUM","OtherId[@Type='06']");
// Create an alias (the field name must be unique)
FieldMapping zz = new FieldMapping("MYALIAS","OtherId[@Type='ZZ']");
zz.setAlias( "STUDENT_NUM" );
| Field Summary | |
|---|---|
static byte |
IFNULL_DEFAULT
Specifies that if the field being mapped is NULL, this field mapping should use the default value, if set. |
static byte |
IFNULL_SUPPRESS
Specifies that if the field being mapped is NULL, this field mapping should not generate a SIF Element, even if a default value is specified |
static byte |
IFNULL_UNSPECIFIED
The field mapping behavior for null fields is unspecified. |
| Constructor Summary | |
|---|---|
FieldMapping()
Constructor |
|
FieldMapping(java.lang.String name,
OtherIdMapping rule)
Constructs a FieldMapping with an <OtherId> rule. |
|
FieldMapping(java.lang.String name,
OtherIdMapping rule,
org.w3c.dom.Node node)
Constructs a FieldMapping with an <OtherId> rule. |
|
FieldMapping(java.lang.String name,
java.lang.String rule)
Constructs a FieldMapping with an XPath-like rule |
|
FieldMapping(java.lang.String name,
java.lang.String rule,
org.w3c.dom.Node node)
Creates a new FieldMapping rule |
|
| Method Summary | |
|---|---|
FieldMapping |
copy(ObjectMapping newParent)
Creates a copy this ObjectMapping instance. |
SIFSimpleType |
evaluate(SIFXPathContext xpathContext,
SIFVersion version,
boolean returnDefault)
Evaluates this rule against a SIFXpathContexts and returns the text value of the element or attribute that satisfied the query. |
static FieldMapping |
fromXML(ObjectMapping parent,
org.w3c.dom.Element element)
Creates a new FieldMapping instance and populates its properties from the given XML Element |
java.lang.String |
getAlias()
Determines if this FieldMapping is an alias of another field mapping. |
SIFDataType |
getDataType()
Returns the datatype that this FieldMapping represents. |
java.lang.String |
getDefaultValue()
Gets the default value for this field when no corresponding element or attribute is found in the SIF Data Object. |
SIFSimpleType |
getDefaultValue(SIFTypeConverter converter,
SIFFormatter formatter)
|
java.lang.String |
getFieldName()
Gets the name of the local application field that maps to the SIF Data Object element or attribute |
MappingsFilter |
getFilter()
Gets optional filtering attributes. |
java.lang.String |
getKey()
Returns the key to a Field Mapping. |
org.w3c.dom.Node |
getNode()
Gets the optional DOM Node associated with this FieldMapping instance. |
byte |
getNullBehavior()
Returns the behavior that this field mapping will follow when mapping a null value. |
Rule |
getRule()
Gets the field mapping rule |
java.lang.String |
getValueSetID()
Gets the ID of the ValueSet that should be used to translate the value of this field. |
boolean |
hasDefaultValue()
Quickly determines whether this field mapping has a default value defined without going through the extra work of actually resolving the default value |
void |
setAlias(java.lang.String fieldName)
Defines this FieldMapping to be an alias of another field mapping. |
void |
setDataType(SIFDataType dataType)
Sets the name of the data type this field represents. |
void |
setDefaultValue(java.lang.String defValue)
Sets a default value for this field when no corresponding element or attribute is found in the SIF Data Object. |
void |
setFieldName(java.lang.String name)
Sets the name of the local application field that maps to the SIF Data Object element or attribute |
void |
setFilter(MappingsFilter filter)
Sets optional filtering attributes. |
void |
setNode(org.w3c.dom.Node node)
Sets the optional DOM Node associated with this FieldMapping instance. |
void |
setNullBehavior(byte behavior)
Sets the behavior that the field mapping should follow when mapping a null value. |
void |
setRule(OtherIdMapping otherId)
Sets this object's rule to an "<OtherId> rule" |
void |
setRule(OtherIdMapping otherId,
org.w3c.dom.Node node)
Sets an OtherId rule for this FieldMapping |
void |
setRule(java.lang.String definition)
Sets this FieldMapping rule to an XPath-like query string |
void |
setValueSetID(java.lang.String id)
Sets the ID of the ValueSet that should be used to translate the value of this field. |
void |
toXML(org.w3c.dom.Element element)
Writes the values of this FieldMapping to the specified XML Element |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final byte IFNULL_UNSPECIFIED
setNullBehavior(byte),
Constant Field Valuespublic static final byte IFNULL_DEFAULT
setNullBehavior(byte),
Constant Field Valuespublic static final byte IFNULL_SUPPRESS
setNullBehavior(byte),
Constant Field Values| Constructor Detail |
|---|
public FieldMapping()
public FieldMapping(java.lang.String name,
java.lang.String rule)
name - The name of the local application field that maps to the
SIF Data Object element or attribute described by this FieldMappingrule - An XPath-like query string described by the SIFDTD.lookupByXPath
method
public FieldMapping(java.lang.String name,
java.lang.String rule,
org.w3c.dom.Node node)
name - The name of the field being mappedrule - The XPath rule associated with this mappingnode - The optional DOM Node associated with this FieldMapping
public FieldMapping(java.lang.String name,
OtherIdMapping rule)
name - The name of the local application field that maps to the
SIF Data Object element or attribute described by this FieldMappingrule - An OtherIdMapping object that describes how to select
a <OtherId> element during a mapping operation
public FieldMapping(java.lang.String name,
OtherIdMapping rule,
org.w3c.dom.Node node)
name - The name of the local application field that maps to the
SIF Data Object element or attribute described by this FieldMappingrule - An OtherIdMapping object that describes how to select
a <OtherId> element during a mapping operationnode - The optional DOM Node that this FieldMapping stores its configuration
to, or Null| Method Detail |
|---|
public org.w3c.dom.Node getNode()
public void setNode(org.w3c.dom.Node node)
node - The DOMNode associated with this FieldMapping instance
public static FieldMapping fromXML(ObjectMapping parent,
org.w3c.dom.Element element)
throws ADKConfigException
parent - element -
ADKConfigException - If the FieldMapping cannot read expected
values from the DOM Nodepublic void toXML(org.w3c.dom.Element element)
element - The XML Element to write values to
public FieldMapping copy(ObjectMapping newParent)
throws ADKMappingException
newParent - The parent that this FieldMapping is associated with
ADKMappingExceptionpublic void setFieldName(java.lang.String name)
name - A field name. (This value will be used as the key in the
HashMap populated by the Mappings.map methods.)public java.lang.String getFieldName()
public java.lang.String getKey()
public void setValueSetID(java.lang.String id)
Note: The Mappings classes do not automatically perform translations if this attribute is defined. Rather, it is provided so that agents can associate a ValueSet with a field in the Mappings configuration file, and have a means of looking up that association at runtime.
id - The ID of a ValueSet defined in the Mappings (e.g. "EthnicityCodes"). If
set to NULL or "", the ValueSet is removedgetValueSetID()public java.lang.String getValueSetID()
Note: The Mappings classes do not automatically perform translations if this attribute is defined. Rather, it is provided so that agents can associate a ValueSet with a field in the Mappings configuration file, and have a means of looking up that association at runtime.
setValueSetID methodsetValueSetID(java.lang.String)public void setDefaultValue(java.lang.String defValue)
defValue - A default string value for this fieldpublic java.lang.String getDefaultValue()
public boolean hasDefaultValue()
public SIFSimpleType getDefaultValue(SIFTypeConverter converter,
SIFFormatter formatter)
throws ADKMappingException
converter - formatter -
ADKMappingException - If the default value specified cannot be converted to the
proper data typepublic void setAlias(java.lang.String fieldName)
To use aliases, create a FieldMapping where the field name is a unique
name and the alias is the name of an existing field. For example, to map
an application-defined field named "STUDENT_NUM" to more than one
element/attribute in the SIF Data Object,
// Create the default mapping
FieldMapping fm = new FieldMapping("STUDENT_NUM","OtherId[@Type='06']");
// Create an alias; the field name must be unique
FieldMapping fm2 = new FieldMapping("STUDENT_NUM_B","OtherId[@Type='ZZ']=STUDENTID:$(STUDENTNUM)");
fieldName - The name of the field for which this entry is an aliaspublic java.lang.String getAlias()
setAlias(java.lang.String)
public SIFSimpleType evaluate(SIFXPathContext xpathContext,
SIFVersion version,
boolean returnDefault)
throws ADKSchemaException
xpathContext - The SIFXpathContext the rule is evaluated againstversion - The SIFVersion to use when lookup up the valuereturnDefault - True if the default value should be returned when there is no value
returnDefault parameter
is set to true, the default value will be returned, if specified
- Throws:
ADKSchemaException - is thrown if the rule associated with this
object is invalid or the default value cannot be parsedpublic void setRule(java.lang.String definition)
definition - An XPath-like query string described by the
SIFDTD.lookupByXPath methodpublic void setRule(OtherIdMapping otherId)
otherId - An OtherIdMapping object that describes how to select
a <OtherId> element during a mapping operation
public void setRule(OtherIdMapping otherId,
org.w3c.dom.Node node)
otherId - The OtherIdMapping instance to use for this field mappingnode - The DOM Node associated with the OtherId mappingpublic Rule getRule()
public void setFilter(MappingsFilter filter)
Mappings.map method at runtime.
filter - A MappingsFilter instance (null to clear the current
filter attributes)getFilter()public MappingsFilter getFilter()
setFilter(com.edustructures.sifworks.tools.mapping.MappingsFilter)public void setNullBehavior(byte behavior)
null value. The value set should be one of the the
IFNULL_XXX constants defined in this class. The default
behavior for null values if this value is not set is to use the
default value, if present.
behavior - One of the the IFNULL_XXX constants defined in this classpublic byte getNullBehavior()
null value.
IFNULL_XXX constants defined in this classpublic void setDataType(SIFDataType dataType)
This datatype is used if the datatype cannot be derived from the field mapping.
If this value is null, this instance will use the STRING data type.
dataType - public SIFDataType getDataType()
If the
datatype attribute is not set on the
<field> mapping, a default of SIFDataType.STRING
is assumed. This value is primarily used for assigning default values
to field mappings.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||