AnySimpleType is handled no differently from any other simple type (string, int, boolean, and so on) by the SDO APIs.
The only differences between anySimpleType and the other simple types are in its instance data and serialization/deserialization. These should be internal concepts to business object only, and used to determine if data being mapped to or from the field is valid. If a string type were to have a set(...) method called on it, the data would first be converted to a string and the original data type would be lost:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://StringType"> <xsd:complexType name="StringType"> <xsd:sequence> <xsd:element name="foo" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> DataObject stringType = ... // Set the data to a String stringType.set("foo", "bar"); // The instance data will always be type String, regardless of the data set // Displays "java.lang.String" System.out.println(stringType.get("foo").getClass().getName()); // Set the data to an Integer stringType.set("foo", new Integer(42)); // The instance data will always be type String, regardless of the data set // Displays "java.lang.String" System.out.println(stringType.get("foo").getClass().getName());
An anySimpleType instead does not loose the original data type of what is being set:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://AnySimpleType"> <xsd:complexType name="AnySimpleType"> <xsd:sequence> <xsd:element name="foo" type="xsd:anySimpleType"/> </xsd:sequence> </xsd:complexType> </xsd:schema> DataObject anySimpleType = ... // Set the data to a String stringType.set("foo", "bar"); // The instance data will always be of the type of date used in the set // Displays "java.lang.String" System.out.println(stringType.get("foo").getClass().getName()); // Set the data to an Integer stringType.set("foo", new Integer(42)); // The instance data will always be of the type of date used in the set // Displays "java.lang.Integer" System.out.println(stringType.get("foo").getClass().getName());
This data type is also preserved across serialization and deserialization by xsi:type. Consequently, any time you serialize an anySimpleType element, it will have an xsi:type that matches that defined in the SDO specification based on its Java™ type:
In the following example, you serialize the business object above so that the data would look like this:
<?xml version="1.0" encoding="UTF-8"?> <p:StringType xsi:type="p:StringType" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:p="http://StringType"> <foo xsi:type="xsd:int">42</foo> <p:StringType></p:StringType>
The xsi:type will be used during deserialization to load the data as the appropriate Java instance class. If no xsi:type is specified, then the default deserialization type will be string.
For the other simple types, determining mappability is a constant. For instance, A boolean can always map to a string. AnySimpleType can contain any of the simple types, however, so a mapping may or may not be possible based on the instance data in the field.
Use the property Type's URI and Name to determine if a property is of type anySimpleType. They will be "commonj.sdo" and "Object". To determine if data is valid to be inserted into anySimpleType, check to see if it is not an instance of a DataObject. All data that can be represented as a String and is not a DataObject is allowed to be set into an anySimpleType field.
This leads to the following mapping rules: