com.edustructures.sifworks.tools.mapping
Class ObjectMapAdaptor

java.lang.Object
  extended by com.edustructures.sifworks.tools.mapping.ObjectMapAdaptor
All Implemented Interfaces:
FieldAdaptor, org.apache.commons.jxpath.Variables
Direct Known Subclasses:
StringMapAdaptor

public class ObjectMapAdaptor
extends java.lang.Object
implements FieldAdaptor, org.apache.commons.jxpath.Variables

A FieldAdaptor implementation that contains field values to assign to the supplied SIFDataObject, where each entry in the map is keyed by the local application-defined name of a field and the value is the native Java datatype of the corresponding element or attribute of the SIFDataObject, such as a Calender, String, Integer, Boolean, etc.

To use this class,

  1. Create an instance and optionally populate the Map with known field values that will not be subject to the mapping process. If pre-loading the Map, the key of each entry should be the local application-defined field name and the value should be the native data type value of that field. Any field added to the Map before calling this method will not be subject to mapping rules, unless the setOverwriteValues(boolean) property is set to True.
  2. Use this class instance with the Mappings class,by calling the appropriate map method and passing the SIFDataObject instance to retrieve field values from for insertion into the Map. The method first looks up the ObjectMapping instance corresponding to the SIF Data Object type. If no ObjectMapping has been defined for the object type, no action is taken and the method returns successfully without exception. Otherwise, all field rules defined by the ObjectMapping are evaluated in order. If a rule evaluates successfully, the corresponding element or attribute value will be inserted into the HashMap. A rule will not be evaluated if the associated field already exists in the Map, unless the setOverwriteValues(boolean) property is set to True.

Version:
2.0
See Also:
Mappings

Constructor Summary
ObjectMapAdaptor(java.util.Map map)
          Creates an instance of ObjectMapAdaptor that uses the specified Map
 
Method Summary
 void declareVariable(java.lang.String varName, java.lang.Object value)
          Declares a field for the JXPath variable and assigns the value
 java.util.Map getMap()
          Gets the Map being used for SIF data mapping operations
 boolean getOverwriteValues()
          Returns whether this class will overwrite existing values in the Map during inbound mapping operations of data coming from SIF.
 SIFSimpleType getSIFValue(java.lang.String fieldName, SIFTypeConverter typeConverter, FieldMapping mapping)
          Gets a value from the underlying data store to be used in an outbound field mapping operation
 java.lang.Object getValue(java.lang.String fieldName)
          Returns the underlying value being stored for the field.
 java.lang.Object getVariable(java.lang.String varName)
          Get the specified field from the Map for a JXPath variable
 boolean hasField(java.lang.String fieldName)
          Returns whether the field being requested for mapping has a value that can be mapped to SIF
 boolean isDeclaredVariable(java.lang.String varName)
          From the Variables interface.
 java.util.Set keySet()
          Gets the keyset of the underlying Map
 void setMap(java.util.Map map)
          Sets the Map being used for SIF data mapping operations
 void setOverwriteValues(boolean overwriteValues)
          This setting influences inbound mapping operations.
 void setSIFValue(java.lang.String fieldName, SIFSimpleType resultingValue, FieldMapping mapping)
          Sets a value that has been retrieved from a SIF Element in an inbound field mapping operation.
 void undeclareVariable(java.lang.String varName)
          Removes the underlying variable from the Map for JXPath support
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectMapAdaptor

public ObjectMapAdaptor(java.util.Map map)
Creates an instance of ObjectMapAdaptor that uses the specified Map

Parameters:
map - The Map to use for SIF Data mapping operations
Method Detail

getValue

public java.lang.Object getValue(java.lang.String fieldName)
Description copied from interface: FieldAdaptor
Returns the underlying value being stored for the field.

This method is not called during Mappings operations. It may be called by classes such as the ValueBuilder class

Specified by:
getValue in interface FieldAdaptor
Parameters:
fieldName - The field name to retrieve
Returns:
The underlying data object representing the field.
See Also:
FieldAdaptor.getValue(java.lang.String)

hasField

public boolean hasField(java.lang.String fieldName)
Description copied from interface: FieldAdaptor
Returns whether the field being requested for mapping has a value that can be mapped to SIF

Specified by:
hasField in interface FieldAdaptor
Parameters:
fieldName - The field name being mapped to SIF
Returns:
True if there is a value for the specified field that should be mapped to SIF
See Also:
FieldAdaptor.hasField(java.lang.String)

setSIFValue

public void setSIFValue(java.lang.String fieldName,
                        SIFSimpleType resultingValue,
                        FieldMapping mapping)
Description copied from interface: FieldAdaptor
Sets a value that has been retrieved from a SIF Element in an inbound field mapping operation.

Specified by:
setSIFValue in interface FieldAdaptor
Parameters:
fieldName - The field name that is mapped to a SIFElement
resultingValue - The value of the SIF element
mapping - The FieldMappings that will be used to set this value or null
See Also:
FieldAdaptor.setSIFValue(java.lang.String, com.edustructures.sifworks.SIFSimpleType, com.edustructures.sifworks.tools.mapping.FieldMapping)

getSIFValue

public SIFSimpleType getSIFValue(java.lang.String fieldName,
                                 SIFTypeConverter typeConverter,
                                 FieldMapping mapping)
Description copied from interface: FieldAdaptor
Gets a value from the underlying data store to be used in an outbound field mapping operation

Specified by:
getSIFValue in interface FieldAdaptor
Parameters:
fieldName - The field name that is mapped to a SIFElement
typeConverter - The converter class for the requested SIF data type
mapping - The FieldMapping this value was generated from or null
Returns:
The value to set to the SIF element. This value must contain the SIFSimpleType subclass represented by the SIFTypeConverter passed in to the method.
See Also:
FieldAdaptor.getSIFValue(java.lang.String, com.edustructures.sifworks.SIFTypeConverter, com.edustructures.sifworks.tools.mapping.FieldMapping)

getMap

public java.util.Map getMap()
Gets the Map being used for SIF data mapping operations

Returns:
The Map being used for SIF data mapping operations

setMap

public void setMap(java.util.Map map)
Sets the Map being used for SIF data mapping operations

Parameters:
map - The Map to be used for SIF data mapping operations

keySet

public java.util.Set keySet()
Gets the keyset of the underlying Map

Returns:
the keyset of the underlying Map

setOverwriteValues

public void setOverwriteValues(boolean overwriteValues)
This setting influences inbound mapping operations. If set to True, data coming from SIF can overwrite existing values in the Map. The default value is False

Parameters:
overwriteValues - True to overwrite existing values in the Map with data from SIF

getOverwriteValues

public boolean getOverwriteValues()
Returns whether this class will overwrite existing values in the Map during inbound mapping operations of data coming from SIF.

Returns:
True if this class should overwrite existing values in the Map

isDeclaredVariable

public boolean isDeclaredVariable(java.lang.String varName)
From the Variables interface. Always returns true because this class allows variables with any name to be tried

Specified by:
isDeclaredVariable in interface org.apache.commons.jxpath.Variables
Parameters:
varName -
Returns:
true

getVariable

public java.lang.Object getVariable(java.lang.String varName)
Get the specified field from the Map for a JXPath variable

Specified by:
getVariable in interface org.apache.commons.jxpath.Variables
Parameters:
varName - The name of the field
Returns:
The object or an empty string if the field does not exist

declareVariable

public void declareVariable(java.lang.String varName,
                            java.lang.Object value)
Declares a field for the JXPath variable and assigns the value

Specified by:
declareVariable in interface org.apache.commons.jxpath.Variables
Parameters:
varName - The name of the field
value - The value to assign to the field

undeclareVariable

public void undeclareVariable(java.lang.String varName)
Removes the underlying variable from the Map for JXPath support

Specified by:
undeclareVariable in interface org.apache.commons.jxpath.Variables
Parameters:
varName -


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.