You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Amila Suriarachchi <am...@gmail.com> on 2007/08/21 05:15:35 UTC

Generating Custom Schemas with Axis2 rmi.

hi,

There is no control to the user about the generated schema with the basic
Axis2 -rmi functionalities. but with the custom schema support users have a
lot of controll over the generated schema.

Specifiying java Bean properties as attributes and setting xml names.

(Please see the advanced-rmi sample which has a working sample)

Lets take this java bean.

public class TestClass {

private int param1;

private String param2;

private int param3;
}


 the generated complex type for this bean would be

<xsd:complexType name="TestClass">

<xsd:sequence>

<xsd:element name="param1" type="xsd:int"/>

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

<xsd:element name="param3" type="xsd:int"/>

</xsd:sequence>

</xsd:complexType>


 but what if some one needs to generate the sechma so that pama1 and param2
as attributes, and generate xml at runtime as it is. Further what if you
want to use as the xmlParam1 instead of java param name param1.

The only thing you have to do is to add declare the CustomClassInfo in
config.xml at the server side and load this data to configurator at client
side. (please see the advanced-rmi sample)


 eg.

<customClassInfo>

<classInfo className="TestClass1">

<fieldInfo isElement="false" javaName="param1" xmlName="xmlParam1"/>

<fieldInfo isElement="false" javaName="param3" xmlName="xmlParam3"/>

</classInfo>

</customClassInfo>


 this would generate the xmlschema with attributes and parse and serialize
the xml stream as it is.


 at client user has to load these details to configurator

ClassInfo classInfo = new ClassInfo(TestClass1.class);

classInfo.addFieldInfo(new FieldInfo("param1", "xmlParam1", false));

classInfo.addFieldInfo(new FieldInfo("param3", "xmlParam3", false));

this.configurator.addClassInfo(classInfo);


On the other hand this feature can be used to map an existing java object
structure to an xml stream. The only requrement is to have a same structure
on both xml document and java objects.

thanks,
Amila.

-- 
Amila Suriarachchi,
WSO2 Inc.