Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 7 Java Palette : Java To XML

Java To XML
Activity
The Java To XML activity allows you to convert a Java object’s data members into an XML document. See Java Schema for the conversion rules.
For example, the Java object has a method declared as public int setID(), but there is no method for getting the ID, and the data member ID is not public. In this case, there is an element named ID in this activity’s output schema, but that element has no value because there is no public mechanism for getting the data.
Enumeration
Java enum type elements can be mapped to a simple type schema with enumeration facets. You can use the following annotations in your Java classes to use Java enums :
XmlEnum and XmlEnumValue together provide a mapping of type enum to the XML representation.
For more details and for the usage of these annotations, see, https://jaxb.java.net/nonav/2.2.4/docs/api/javax/xml/bind/annotation/XmlEnum.html
and https://jaxb.java.net/nonav/2.2.4/docs/api/javax/xml/bind/annotation/XmlEnumValue.html
 
Example 1
 
@XmlEnum(String.class)
public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
<xs:simpleType name="Card">
<xs:restriction base="xs:string"/>
<xs:enumeration value="CLUBS"/>
<xs:enumeration value="DIAMONDS"/>
<xs:enumeration value="HEARTS"/>
<xs:enumeration value="SPADES"/>
</xs:simpleType>
 
Example 2
 
@XmlEnum(Integer.class)
public enum Coin {
@XmlEnumValue("1") PENNY(1),
@XmlEnumValue("5") NICKEL(5),
@XmlEnumValue("10") DIME(10),
@XmlEnumValue("25") QUARTER(25) }
 
<!-- Example: XML Schema fragment -->
<xs:simpleType name="Coin">
<xs:restriction base="xs:int">
<xs:enumeration value="1"/>
<xs:enumeration value="5"/>
<xs:enumeration value="10"/>
<xs:enumeration value="25"/>
</xs:restriction>
</xs:simpleType>
Sequenced Elements
For a Java schema to generate the schema of complex type element having a sequence order indicator in the right sequence, use XMLType annotations in the Java classes.
This change in behavior is enabled by a system property java.property.com.tibco.xml.conversion.SequencingViaAnnotation=true.
BusinessWorks tries to get the order of the element through annotations when the property is set to true. The default value is false.
Use the following annotation:
javax.xml.bind.annotation.XmlType
Properties and fields mapped to elements are mapped to a content model within a complex type.
The annotation element propOrder() can be used to customize content model to xs:sequence. This is used to specify the order of the XML elements in xs:sequence.
For example, map a class to a complex type element with xs:sequence with a customized ordering of JavaBean properties.
 
@XmlType(propOrder={"street", "city" , "state", "zip", "name" })
public class USAddress {
private String name;
private String street;
private String city;
private String state;
private long zip;
public String getName() {..};
public void setName(String) {..};
public String getStreet() {..};
public void setStreet(String) {..};
 
public String getCity() {..};
public void setCity(String) {..};
public String getState() {..};
public void setState(String) {..};
 
public long getZip() {..};
public void setZip(long zip) {..};
}
 
<!-- XML Schema mapping for USAddress -->
<xs:complexType name="USAddress">
<xs:sequence>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="state" type="xs:string"/>
<xs:element name="zip" type="xs:decimal"/>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
 
An exception is thrown if any of the following conditions are true:
a.
b.
 
Configuration
The Configuration tab has the following fields.
Advanced
The Advanced tab has the following fields:.
See Caching the Java Class for more information about caching the declared class.
Input
See TIBCO ActiveMatrix BusinessWorks Process Design for more information about mapping and transforming input data.
The input for the activity is the following.
<declaringClass>
Output
The output for the activity is the following.
Error Output
The Error Output tab lists the possible exceptions that can be thrown by this activity. See TIBCO ActiveMatrix BusinessWorks Error Codes for more information about error codes and corrective action to take.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved