Wednesday, December 21, 2011

Axis2 Databinding framework (ADB)


                           Check more helpful topics here

Axis2 Databinding framework (ADB)

     Schema compiler / Java bean generator for AXIS2.

Databinding helps in conversion between XML and application datastructure.

ADB utilizes the WS-Commons XmlSchema library for reading the Schema, the ASLT transformations are dependent on the JVM’s DOM implementation (Crimson / Xerces).

ADB is based on AXIOM (AXIS object model) so for parsing or unmarshaling, ADB generally needs XML stream to convert it into JAVA Object and for serializing or marshaling it writes object to XML stream.

Below is a sample xml to convert in Java object (By Command prompt):

File : ElementToConvert.xsd

        <schema targetNamespace="http://com.rtvk.axis2Samples/adb"

        xmlns="http://www.w3.org/2001/XMLSchema"

        xmlns:xsd="http://www.w3.org/2001/XMLSchema"      

        xmlns:tns="http://com.rtvk.axis2Samples/adb"

        elementFormDefault="qualified">

            <element name="ElementToConvert">

                <complexType>

                    <sequence>

                        <element name="StrMember" type="xsd:string"/>

                        <element name="IntMember" type="xsd:int"/>
<element 
       name="BooleanMember" type="xsd:boolean"/>
 
  </sequence>

</complexType>



             </element>

        </schema>

As a next step,  Update your Classpath environment variable.
You need to modify classpath variable for all .JARs of AXIS2, in case if you want to run it using ‘Java’ command in command prompt or in case if you want to run it through axis2 bat file then you need to specify AXIS2_HOME variable.
Option1 : Run Java Program
java org.apache.axis2.schema.XSD2Java C:\ElementToConvert.xsd C:\ADBGenerated
Option2 : Run axis2 bat/sh
axis2 org.apache.axis2.schema.XSD2Java C:\ElementToConvert.xsd C:\ADBGenerated
Option3 : Through Java Program

package com.rtvk.services;
import org.apache.axis2.schema.XSD2Java;
public class XSD2JavaCodeGenerator {
      public static void main(String[] args){
String[] strArr = new String[] {"C:\\ElementToConvert.xsd", "C:\\ADBGenerated"};
            try {
                  XSD2Java.main(strArr);
            } catch (Exception e) {
                        e.printStackTrace();
            }
}
}


This will generate files as per XSDs.

Option 4: Through plugins of Maven, ANT, IDEs or others...

No comments: