Thursday 11 July 2013

Oracle Business Rules : Generating Xml Facts from schema - JAXB Restriction

PROBLEM STATEMENT:
-----------------
Consider the following schema structure:
<xsd:element name="Airport" type="Airport_Type"/>
<xsd:complexType name="Airport_Type">
<xsd:sequence>
      <xsd:element ref="AirportTypeCd" minOccurs="0" maxOccurs="1"/>
      </xsd:sequence>
</xsd:complexType>
<xsd:element name="AirportTypeCd" type="AirportType"/>
 <xsd:complexType name="AirportType">
<xsd:sequence>
  <xsd:element name="input" type="xsd:string"/>
 </xsd:sequence>
</xsd:complexType>


From Jdeveloper  , create business rule based on the above schema.
Click on the "Create" XML Facts Icon in Business Rules.
Add the above schema
In the "Target Classes" frame , expand the tree structure.The structure would be : 
org->test-> xml
    -> AirportType
    -> OjectFactory

Notice that the JAXB Class corresponding to element "Airport_Type" is missing.

EXPLANATION:
-------------------
The rules engine (and SOA in general) rely on glass-fish JAXB libraries for
converting XML facts to Java and vice-verse.
As per the default JAXB implementation , the JAXB engine  ignores underscore
characters in the element's name when converting XML elements to JAXB classes.
(i.e)
An element like <xsd:complexType name="Airport_Type">
would be converted to a JAXB class "AirportType.class"

In general this default behavior should not be an issue , however in this case , the schema also contains another element with name  <xsd:complexType name="AirportType">

When JAXB attempts to convert element "AirportType" into a JAXB class , it fails with the error
An error was encountered while migrating JAXB
A class/interface with the same name "org.test.AirportType" is already in use

This happens because the element Airport_Type was converted to AirportType.class as well.

The solution would  be to use a custom binding and inform JAXB to retain
underscore elements as-is when converting them to JAXB classes.

This binding customizes JAXB's default implementation to not ignore
underscore's via : <jaxb:globalBindings underscoreBinding="asCharInWord"/>

[Refer to
http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html
for more details]

No comments:

Post a Comment