When using information that is in a bidirectional language script,
it might be necessary to transform the format of the data. This is a step-by-step
example of the coding that performs a transformation on DataObject-type data.
Why and when to perform this task
The module requires that DataObject-type information
is transformed from one bidirectional format to another.
Steps for this task
- Include all bidirectional classes that contain the bidirectional
engine implementation.
import com.ibm.bidiTools.bdlayout.*;
- Include all the classes you need to manipulate the DataObject-type
object.
import commonj.sdo.DataObject;
import commonj.sdo.Type;
import commonj.sdo.Property;
- Define string variables to contain the different types of strings
that a DataObject-type object contains. This step facilitates filtering the
attributes of type String while transversing recursively
the DataObject.
String STRING_STR_TYPE = "String";
String NORM_STRING_STR_TYPE = "normalizedString";
String TOKEN_STR_TYPE = "token";
String LANG_STR_TYPE = "language";
String NAME_STR_TYPE = "Name";
String NMTOKEN_STR_TYPE = "NMTOKEN";
String NCNANE_STR_TYPE = "NCName";
String ID_STR_TYPE = "ID";
String IDREF_STR_TYPE = "IDREF";
String IDREFS_STR_TYPE = "IDREFS";
String ENTITY_STR_TYPE = "ENTITY";
String ENTITIES_STR_TYPE = "ENTITIES";
- Define the function that verifies if the type of a property is
String.
private static boolean isStringFamilyType (Property property) {
boolean rc = false;
if ((property.getType().getName().equalsIgnoreCase(STRING_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(NORM_STRING_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(TOKEN_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(LANG_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(NAME_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(NMTOKEN_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(NCNANE_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(ID_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(IDREF_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(IDREFS_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(ENTITY_STR_TYPE)) ||
(property.getType().getName().equalsIgnoreCase(ENTITIES_STR_TYPE)))
rc = true;
return rc;
}
- Define the recursive function that applies the bidirectional transformation
on the entire DataObject.
Note: The following explain basic assumptions
that code logic follows.
- bidirectional transformation is applied on properties of string type only
- the properties of type string in the DataObject are stored in one bidirectional
format
DataObject BiDiDataObjTransformationBO(DataObject boIn, String formatIn, String formatOut){
Type type;
Property property;
if (boIn == null) return null;
type = boIn.getType();
List propertyList = type.getProperties();
for (int propertyNumber = 0; propertyNumber < propertyList.size(); propertyNumber++){
property = (Property) propertyList.get(propertyNumber);
String propertyName = property.getName();
- Skip all non-string properties.
if (!isStringFamilyType(property))
continue;
if (property.isContainment()) {
if (property.isMany()) {
List childsList = boIn.getList(property);
- Recursively call the transformation to handle children objects.
for (int childNumber = 0; childNumber < childsList.size();
childNumber++){ BiDiDataObjTransformationBO(connectionContext,
((DataObject)childsList.get(childNumber)),formatIn, formatOut);
}
} else {
- Recursively call the transformation to handle children objects
of any contained business objects.
BiDiDataObjTransformationBO(connectionContext,
((DataObject)boIn.get(property)),formatIn, formatOut);
}
} else {
- Transform the simple string attributes.
String str = BiDiStringTransformation(
(boIn.getString(propertyName),formatIn, formatOut);
boIn.setString(propertyName, str);
}
}
return boIn;
}
Last updated: Thu 26 Oct 2006 10:30:05
(c) Copyright IBM Corporation 2005, 2006.
This information center is powered by Eclipse technology (http://www.eclipse.org)