|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.edustructures.sifworks.Element
com.edustructures.sifworks.SIFElement
com.edustructures.sifworks.SIFDataObject
public abstract class SIFDataObject
The abstract base class for all root-level SIF Data Object classes.
SIFDataObject encapsulates top-level data objects defined by SIF Working
Groups, including <StudentPersonal>,
<LibraryPatronStatus>, <BusInfo>,
and so on.
Setting Elements & Attributes of a SIF Data Object
There are two general approaches to getting and setting the element/attribute values of a SIFDataObject. First, you can call the getXxx and setXxx methods of the subclass to manipulate the elements and attributes in an object-oriented fashion. For example, to assign a first and last name to a StudentPersonal object, create a Name object and attach it to the StudentPersonal with the setName method:
// Build a StudentPersonal object
StudentPersonal sp = new StudentPersonal();
sp.setRefId( ADK.makeGUID() );
sp.setName( new Name( "Davis", "Alan" ) );
The second approach to getting and setting element/attribute values is to
call the setElementOrAttribute and getElementOrAttribute
methods, which accept an XPath-like query string that identifies a specific
SIF element or attribute relative to the SIFDataObject. (See also the
Mappings class for a higher-level mechanism that performs much of the work
involved in dynamically mapping application fields to SIF elements and
attributes).
// Build a StudentPersonal object
StudentPersonal sp = new StudentPersonal();
sp.setRefId( ADK.makeGUID() );
sp.setElementOrAttribute( "Name[@Type='02']/LastName", "Davis", null );
sp.setElementOrAttribute( "Name[@Type='02']/FirstName", "Brian", null );
XPath-like query strings can include substitution tokens and can even call
static Java methods. For example, the following uses name/value pairs defined
in a Map to select the first and last name. The static capitalize
method of the "MyFunctions" class is called to capitalize the last name:
// Prepare a table with field values
HashMap values = new HashMap();
values.put( "LASTNAME", "Davis" );
values.put( "FIRSTNAME", "Brian" );
// Build a StudentPersonal object
StudentPersonal sp = new StudentPersonal();
sp.setRefId( ADK.makeGUID() );
sp.setElementOrAttribute( "Name[@Type='02']/LastName=@MyFunctions.capitalize( $(LASTNAME) )", null, values );
sp.setElementOrAttribute( "Name[@Type='02']/FirstName=$(FIRSTNAME)", null, values );
Object Type
The getObjectType method returns the an ElementDef constant
from the SIFDTD class that identifies the SIF Data Object. The the
getObjectTag convenience method returns the element tag name of
the object for the version of SIF associated with the instance. For example,
// Lookup a Topic instance
SIFDataObject data = new SIFDataObject( ADK.DTD().STUDENTPERSONAL );
TopicFactory factory = myAgent.getTopicFactory();
Topic t = factory.getInstance( data.getObjectType() );
SIF Version
Each SIFDataObject is associated with a SIFVersion instance. The version
is used by the SIFWriter class when rendering the object as XML. By default,
it is assumed to be the version of SIF in effect for this agent; that is,
the value passed to the ADK.initialize method. However, to
support mixed environments where an agent may send and receive objects
using different versions of SIF, the version may be changed by the ADK
during message processing:
<SIF_Message>
envelope.setSIFVersion method.
| Field Summary |
|---|
| Fields inherited from class com.edustructures.sifworks.Element |
|---|
CURRENT_SERIALIZE_VERSION |
| Constructor Summary | |
|---|---|
SIFDataObject(SIFVersion version,
ElementDef def)
Constructs a SIFDataObject |
|
| Method Summary | |
|---|---|
void |
addSIFExtendedElement(java.lang.String name,
java.lang.String value)
Sets a SIF_ExtendedElement. |
java.lang.Object |
clone()
|
Element |
getElementOrAttribute(java.lang.String xpath)
Gets an element or attribute value identified by an XPath-like query string. |
java.lang.String |
getObjectTag()
Gets the element tag name of this object |
ElementDef |
getObjectType()
Gets the ElementDef that identifies this SIF Data Object type |
java.lang.String |
getRefId()
Gets this object's RefId. |
SIF_ExtendedElement |
getSIFExtendedElement(java.lang.String name)
Gets the SIF_ExtendedElement with the specified Name attribute. |
SIF_ExtendedElement[] |
getSIFExtendedElements()
Gets all SIF_ExtendedElements/SIF_ExtendedElement children of this object. |
SIF_ExtendedElements |
getSIFExtendedElementsContainer()
Gets the SIF_ExtendedElements container in which all child SIF_ExtendedElement elements are placed by the addSIFExtendedElement(String, String)
method. |
SIF_Metadata |
getSIFMetadata()
Gets the SIF_Metadata for this object. |
SIFVersion |
getSIFVersion()
Gets the version of SIF that should be used to render this SIFDataObject and its child elements |
void |
setElementOrAttribute(java.lang.String xpath,
java.lang.String value)
Sets an element or attribute value |
void |
setElementOrAttribute(java.lang.String xpath,
java.lang.String value,
FieldAdaptor adaptor)
Sets an element or attribute value identified by an XPath-like query string. |
void |
setElementOrAttribute(java.lang.String xpath,
java.lang.String value,
ValueBuilder valueBuilder)
Sets an element or attribute value identified by an XPath-like query string. |
void |
setSIFExtendedElements(SIF_ExtendedElement[] elements)
Sets an array of SIF_ExtendedElement objects. |
void |
setSIFExtendedElementsContainer(SIF_ExtendedElements container)
Sets the SIF_ExtendedElements container for this object. |
void |
setSIFMetadata(SIF_Metadata metadata)
Sets the SIF_Metadata for this object. |
void |
setSIFVersion(SIFVersion version)
Changes the version of SIF that should be used to render this SIFDataObject and its children. |
java.lang.String |
toXML()
Returns the XML representation of this SIF Data Object |
| Methods inherited from class com.edustructures.sifworks.SIFElement |
|---|
addChild, addChild, compareGraphTo, create, effectiveSIFVersion, getChild, getChild, getChild, getChild, getChild, getChildCount, getChildList, getChildList, getChildList, getChildren, getChildren, getContent, getContent, getField, getField, getFieldCount, getFields, getFieldValue, getKey, getSIFValue, getTextValue, getXmlId, hasTextValue, removeChild, removeChild, removeChild, removeChild, restoreImplementationDef, setChanged, setChildren, setEmpty, setField, setField, setField, setField, setSIFValue, setTextValue, setXmlId, tag |
| Methods inherited from class com.edustructures.sifworks.Element |
|---|
compareTo, getElementDef, getParent, getRoot, isChanged, isDoNotEncode, isEmpty, setChanged, setDoNotEncode, setElementDef, setEmpty, setParent, toString |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SIFDataObject(SIFVersion version,
ElementDef def)
version - The version of SIF that should be used to render this
SIFDataObject and its child elements. If this SIFDataObject is the
result of parsing a SIF message, this is the version of SIF
identified by the message envelope.def - The ElementDef that provides metadata for this element| Method Detail |
|---|
public java.lang.String getRefId()
Most SIF Data Object elements define a RefId value to uniquely identify the object. However, some objects such as SIF_ZoneStatus and StudentMeal do not have a RefId. For these, a blank string will be returned.
public ElementDef getObjectType()
public java.lang.String getObjectTag()
public SIFVersion getSIFVersion()
getSIFVersion in class SIFElementpublic void setSIFVersion(SIFVersion version)
setSIFVersion in class SIFElementversion - The version of SIF that should be used
public void setElementOrAttribute(java.lang.String xpath,
java.lang.String value)
throws ADKSchemaException
xpath - An XPath-like query string that identifies identifies
the element or attribute to set. The string must reference elements
and attributes by their version-independent names.value - The value of the element or attribute
ADKSchemaException - IF the xpath is not valid
public void setElementOrAttribute(java.lang.String xpath,
java.lang.String value,
FieldAdaptor adaptor)
throws ADKSchemaException
xpath - An XPath-like query string that identifies the element or
attribute to set. The string must reference elements and attributes
by their version-independent names.value - The value to assign to the element or attribute if the
query string does not set a value; may be nulladaptor - A data source may be used for variable
substitutions within the query string
ADKSchemaException - If the xpath is not valid
public void setElementOrAttribute(java.lang.String xpath,
java.lang.String value,
ValueBuilder valueBuilder)
throws ADKSchemaException
xpath - An XPath-like query string that identifies the element or
attribute to set. The string must reference elements and attributes
by their version-independent names.value - The value to assign to the element or attribute if the
query string does not set a value; may be nullvalueBuilder - a ValueBuilder implementation that evaluates
expressions in XPath-like query strings using name/value pairs in
the variables map
ADKSchemaException - If the xpath is not valid
public Element getElementOrAttribute(java.lang.String xpath)
throws ADKSchemaException
xpath - An XPath-like query string that identifies the element or
attribute to get. The string must reference elements and attributes
by their version-independent names.
null is returned. To retrieve the
value of the Element, call its getTextValue method.
ADKSchemaException - If the xpath is not valid
public void addSIFExtendedElement(java.lang.String name,
java.lang.String value)
name - The element namevalue - The element valuepublic SIF_ExtendedElement[] getSIFExtendedElements()
public void setSIFExtendedElements(SIF_ExtendedElement[] elements)
SIF_ExtendedElement objects. All existing
SIF_ExtendedElement instances
are removed and replaced with this list. Calling this method with the
parameter value set to null removes all SIF_ExtendedElements.
elements - The SIF_Extended elements instances to set on this objectpublic SIF_ExtendedElements getSIFExtendedElementsContainer()
addSIFExtendedElement(String, String)
method. Note if there is currently no container element, one is created and
added as a child of the SIFDataObject.
This method is provided as a convenience to agents that wish to obtain the
SIF_ExtendedElements container element in order to manually add extended
elements to it. This is useful, for example, if you need to call methods on
the extended element before adding it to the container (e.g. the setDoNotEncode
method). The equivalent functionality is possible by making this call:
SIF_ExtendedElements container = (SIF_ExtendedElements)getChild( SIFDTD.SIF_EXTENDEDELEMENTS );
public void setSIFExtendedElementsContainer(SIF_ExtendedElements container)
Normally, agents can just call addSIFExtendedElement(String, String),
which automatically creates a SIF_ExtendedElements container, if necessary and
allows for easy addition of SIF_ExtendedElements.
This method is provided as a convenience to agents that need more control or wish to set or completely replace the existing SIF_ExtendedElements container.
container - The new SIF_ExtendedElements containerpublic SIF_Metadata getSIFMetadata()
public void setSIFMetadata(SIF_Metadata metadata)
metadata - The new SIF_Metadata objectpublic SIF_ExtendedElement getSIFExtendedElement(java.lang.String name)
name - The value of the SIF_ExtendedElement/@Name attribute to search for
public java.lang.String toXML()
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class SIFElementjava.lang.CloneNotSupportedException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||