This recipe explains how to access simple types through XML facade.
To complete the recipe, we will amend the example BPEL process from our previous recipe, Accessing complex types through XML facade.
for (org.packt.cashflowfacade.PrincipalExchange pe: princEx) { addAuditTrailEntry("Received cashflow with id: " + pe.getId() + " " + " Unadj. Principal Exch. Date ...: " + pe.getUnadjustedPrincipalExchangeDate() + " " + " Adj. Principal Exch. Date .....: " + pe.getAdjustedPrincipalExchangeDate() + " " + " Discount factor ...............: " + pe.getDiscountFactor() + " " + " Principal Exch. Amount ........: " + pe.getPrincipalExchangeAmount() + " " ); }
The XML schema simple types are mapped to Java classes as members. If we check our example, we have three simple types in the XML schema:
<xsd:complexType name="PrincipalExchange"> <xsd:sequence> <xsd:element minOccurs="0" name="unadjustedPrincipalExchangeDate" type="xsd:date"/> <xsd:element minOccurs="0" name="adjustedPrincipalExchangeDate" type="xsd:date"/> <xsd:element minOccurs="0" name="principalExchangeAmount" type="xsd:decimal"/> <xsd:element minOccurs="0" name="discountFactor" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="id" type="xsd:int"/> </xsd:complexType>
The simple types defined in the XML schema are <xsd:date>
, <xsd:decimal>
, and <xsd:int>
. Let us find the corresponding Java class member definitions. Open the PrincipalExchange.java
file. The definition of members we can see is as follows:
@XmlSchemaType(name = "date") protected XMLGregorianCalendar unadjustedPrincipalExchangeDate; @XmlSchemaType(name = "date") protected XMLGregorianCalendar adjustedPrincipalExchangeDate; protected BigDecimal principalExchangeAmount; protected BigDecimal discountFactor; @XmlAttribute protected Integer id;
We can see that the mapping between the XML content and the Java classes was performed as shown in the following table:
XML schema simple type |
Java class member |
---|---|
|
|
|
|
|
|
Also, we can identify that the XML simple type definitions as well as the XML attributes are always mapped as members in corresponding Java class representations.