IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Defining and transforming data > Transforming data > Transforming data using a business object map
Mapping with XSD wildcards
You can use the business object map editor to map XSD wildcards (xsd:any, xsd:anyType, xsd:anyAttribute, and xsd:anySimpleType).
To create a business object map using XSD wildcards, follow these steps
Procedure
- Select the wildcard field from the source.
- Draw a connection to the target.
Results
The table below describes which element types can be mapped using Move or Custom transforms:
Support for Move or Custom transforms Source Target is xsd:any Target is xsd:anyType Target is xsd:anySimpleType Target is a regular complex type Target is a regular simple type xsd:any (complex type in the runtime instance) Supported Supported Supported xsd:any (simple type in the runtime instance) Supported Supported Supported Supported xsd:anyType (complex type in the runtime instance) Supported Supported Supported xsd:anyType (simple type in the runtime instance) Supported Supported Supported Supported xsd:anySimpleType Supported Supported Supported Supported Regular complex type Supported Supported Supported Regular simple type Supported Supported Supported Supported Only Custom transforms are supported for attributes of type xsd:anyAttribute. The business object map editor allows direct Move transform connections involving XSD wildcards, however, you must be cautious of the data being mapped with XSD wildcards. Server runtime exceptions will occur if the source data is incompatible with the target data.
Below are samples of Java™ code for use when writing Custom transforms using the Java Editor:
- Code sample for Custom transform between xsd:any input parameter and regular simple type output parameter
- After you draw a Custom transform between the xsd:any input parameter and a regular simple type output parameter, open the Properties and click the Details tab. Switch to the Java Editor and type the Java code (below is the sample of the code):
if (<<input parameter variable>> instanceof Integer) { Integer intObject = (Integer)<<input parameter variable>>; int intValue = intObject.intValue(); int newValue = intValue + 100; <<output parameter variable>> = newValue;}
- Code sample for Custom transform between xsd:any input parameter and regular complex type output parameter
if (<<input parameter variable>> instanceof DataObject) { DataObject dObject = (DataObject) <<input parameter variable>>; String value = (String)dObject.get("field"); ServiceManager serviceManager = new ServiceManager(); BOFactory bofactory = (BOFactory)serviceManager.locateService("com/ibm/websphere/bo/BOFactory"); DataObject outObject = (DataObject)bofactory.create("http://anytest", "ComplexAny"); outObject.set("field", value.substring(0, 2)); <<output parameter variable>> = outObject;}
- Code sample for how to retrieve the value of xsd:any element from the input top-level business object
commonj.sdo.Sequence seq = <<input BO variable>>.getSequence(); for (int i = 0; i < seq.size(); i++) { commonj.sdo.Property prop = seq.getProperty(i); if (prop.isOpenContent()) { Object xsdAnyValue = seq.getValue(i);} }
- Code sample for how to set the xsd:any element in the output top-level business object
commonj.sdo.Sequence seq = <<output BO variable>>.getSequence(); com.ibm.websphere.bo.BOXSDHelper boXSDHelper = (BOXSDHelper) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOXSDHelper"); commonj.sdo.Property property = boXSDHelper.getGlobalProperty("http://anytest", "IntegerAny", true); seq.add(property, new Integer(123));
- Code sample for Custom transform between a regular simple type input parameter and xsd:any output parameter
String newString = ((String)<<input parameter variable>> ).substring(0,2); <<output parameter variable>> = newString;
- Code sample for Custom transform between a regular simple type input parameter and xsd:anyType output parameter
String newString = ((String) <<input parameter variable>> ).substring(0,2); com.ibm.websphere.bo.BOType boType = (com.ibm.websphere.bo.BOType)serviceManager.locateService("com/ibm/websphere/bo/BOType"); Type stringType = boType.getType("http://www.w3.org/2001/XMLSchema", "string"); DataObject stringWrapper = bofactory.createDataTypeWrapper(stringType,newString); <<output parameter variable>> = stringWrapper;
- Code sample for Custom transform between a regular complex type input parameter and xsd:anyType output parameter
<<output parameter variable>> = (commonj.sdo.DataObject)<<input parameter variable>>;
- Code sample for how to retrieve the value of xsd:anyType element from the input parameter variable
ServiceManager serviceManager = new ServiceManager(); DataObject anyTypeValue = (DataObject)<<input parameter variable>>; Object simpleValue = null; Object complexValue = null; com.ibm.websphere.bo.BOType boType = (com.ibm.websphere.bo.BOType)serviceManager.locateService("com/ibm/websphere/bo/BOType"); if (boType.isDataTypeWrapper(anyTypeValue)) simpleValue = anyTypeValue.get("value"); else complexValue = anyTypeValue;
- Code sample for how to set xsd:anyType element in the output top-level business object
ServiceManager sm = ServiceManager.INSTANCE; BOFactory bf = (BOFactory) sm.locateService("com/ibm/websphere/bo/BOFactory"); com.ibm.websphere.bo.BOType boType = (com.ibm.websphere.bo.BOType)sm.locateService("com/ibm/websphere/bo/BOType"); Type objectType = boType.getType("http://www.w3.org/2001/XMLSchema", "string"); DataObject wrapper = bf.createDataTypeWrapper(objectType, new String("abc")); <<output BO variable>>.set("anyTypeElement", wrapper);
- Code sample for Custom transform between input xsd:anyAttribute and output xsd:anyAttribute
List inputAnyAttributes = (List)<<input parameter variable>>; // iterate through the list or pick the one you want Property myProp = (Property)inputAnyAttributes.get(0); Sequence seq = <<output BO variable>>.getSequence(); seq.add(myProp, "abc");
- Code sample for how to set xsd:anyAttribute in the output top-level business object
ServiceManager sm = ServiceManager.INSTANCE; BOFactory bf = (BOFactory) sm.locateService("com/ibm/websphere/bo/BOFactory"); BOXSDHelper boXSDHelper = (BOXSDHelper) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOXSDHelper"); Property property = boXSDHelper.getGlobalProperty("http://anytest", "StringAnyAttr", false); // false indicates it's a global attribute <<output BO variable>>.setString(property, "abc");
xsd:any[] can be populated with a list of complex types that all belong to the same global property. To add multiple elements to the property, retrieve the sequence on the business object in which the global property is defined and add each element to the global property. To retrieve all of the elements that are set on the xsd:any[], a ' get' on the business object with the property name would return a list containing all of the defined elements.
- Code sample for setting multiple xsd:any[] elements in an input business object
commonj.sdo.Sequence seq = <<input BO variable>>.getSequence(); com.ibm.websphere.bo.BOXSDHelper boXSDHelper = (BOXSDHelper) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOXSDHelper"); Property prop = helper.getGlobalProperty("http://www.ibm.com/bo/SubMapAnyAnyType","myany",true); // Adding two Complex types to the any for list into the global property DataObject Branch1 = boFactory.create(boTNS, "Branch"); Branch1.set("fName","wilshire"); seq.add(prop, Branch1); DataObject Branch2 = boFactory.create(boTNS, "Branch"); Branch2.set("fName","poplar"); seq.add(prop, Branch2);
- Code sample for setting the output business objects to one of the xsd:any[] input elements
<<output parameter variable>> = (List)<<input parameter variable>>.getList.(0);
- Code sample for retrieving the list of all xsd:any[] elements
commonj.sdo.Sequence seq = <<input BO variable>>.getSequence(); com.ibm.websphere.bo.BOXSDHelper boXSDHelper = (BOXSDHelper) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOXSDHelper"); Property prop = helper.getGlobalProperty("http://www.ibm.com/bo/SubMapAnyAnyType","myany",true); // Adding two Complex types to the any for list into the global property DataObject Branch1 = boFactory.create(boTNS, "Branch"); Branch1.set("fName","wilshire"); seq.add(prop, Branch1); DataObject Branch2 = boFactory.create(boTNS, "Branch"); Branch2.set("fName","poplar"); seq.add(prop, Branch2); List properties = <<input BO variable>>.getProperty(prop); // use this list of properties as needed.
- Code sample for setting an element in an AnyType[] on the source business object
<<input BO variable>>; List anyTypeList = <<input BO variable>>.getList("anAnyType"); DataObject Address1 = boFactory.create(boTNS, "Address"); Address1.set("address1", "hillsboro"); anyTypeList.add(Address1); DataObject Address2 = boFactory.create(boTNS, "Address"); Address2.set("address1", "sandiego"); anyTypeList.add(Address2);
- Code sample for setting an AnyType[] element on the output
<<output parameter variable>> = (List)<<input parameter variable>>.getList.(“anAnyType”).get(0);
- The <any> element
The <any> element extends the XML document with elements not specified by the schema. The <any/> tag allows a complex type to have global elements set to it. The <any> element makes extensible documents and allows documents to contain additional elements that are not declared in the main XML schema.- The <anyType> element
The mapping of the <anyType> element is handled the same as any other complex type by the SDO APIs. Complex types are limited to a single type (that is, Customer, Address, and so on) but <anyType> allows any data object, regardless of type, to be set in the <anyType> element.- The <anySimpleType> element
From a mapping perspective, <anySimpleType> elements can be mapped in the same way as simple types.- Submaps with <any> and <anyType> elements
It is possible to create submaps with the <any> and <anyType> types provided that these types contain complex types as the instance data. A runtime exception will be thrown if they contain non-complex types.- Substitution group mappings
In XML 1.0, the name and content of an element had to correspond exactly to the element type referenced in the corresponding content model. Through substitution groups, XML schemas provide a more powerful model supporting substitution of one named element for another.