You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by am...@apache.org on 2006/11/11 13:50:02 UTC

svn commit: r473709 - /webservices/axis2/branches/java/1_1/xdocs/1_1/adb/adb-advanced.html

Author: amilas
Date: Sat Nov 11 04:50:02 2006
New Revision: 473709

URL: http://svn.apache.org/viewvc?view=rev&rev=473709
Log:
added the same sample code as in the previous part. added a new code to show how an adb framwork user can gereate 
code progamatically.

Modified:
    webservices/axis2/branches/java/1_1/xdocs/1_1/adb/adb-advanced.html

Modified: webservices/axis2/branches/java/1_1/xdocs/1_1/adb/adb-advanced.html
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/xdocs/1_1/adb/adb-advanced.html?view=diff&rev=473709&r1=473708&r2=473709
==============================================================================
--- webservices/axis2/branches/java/1_1/xdocs/1_1/adb/adb-advanced.html (original)
+++ webservices/axis2/branches/java/1_1/xdocs/1_1/adb/adb-advanced.html Sat Nov 11 04:50:02 2006
@@ -20,57 +20,65 @@
 <h2><a name="typeSupport">xsi:type Support</a></h2>
 
 <p>This is implemented by adding a extension maping class. The code that
-calls the extension mapper is generated inside the deserialization method of
+calls the extension mapper is generated inside the Factory.parse method of
 the beans and gets active when the xsi:type attribute is present. The
 following code fragment shows how the generated type mapper looks like</p>
-<pre> public static java.lang.Object getTypeObject(
-java.lang.String namespaceURI, java.lang.String typeName,
-javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception {
-if ("http://new.webservice.namespace/types".equals(namespaceURI) &amp;&amp;                 "derivedType2".equals(typeName)) {
-        return namespace.webservice._new.types.DerivedType2Helper.parse(reader);
-} 
-
-......
-
-        return namespace.webservice._new.types.BaseTypeHelper.parse(reader);
-} else if ("http://new.webservice.namespace/types".equals(namespaceURI) &amp;&amp;                 "derivedType1".equals(typeName)) {
-        return namespace.webservice._new.types.DerivedType1Helper.parse(reader);
-}
+<pre>            public static java.lang.Object getTypeObject(java.lang.String namespaceURI,
+                                java.lang.String typeName,
+                                javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
+              
+                  if (
+                  "http://soapinterop.org/types".equals(namespaceURI) &&
+                  "SOAPStruct".equals(typeName)){
+                            return  com.test.SOAPStruct.Factory.parse(reader);
+                  }
+              throw new java.lang.RuntimeException("Unsupported type " + namespaceURI + " " + typeName);
+            }</pre>
 
-throw new java.lang.RuntimeException("Unsupported type " +
-        namespaceURI + " " + typeName);
-
-}</pre>
-
-<p>Inside every deserialize method, the extension mapper gets called when a
+<p>Inside every Factory.parse method, the extension mapper gets called when a
 xsi:type attribute is encountered <strong>and</strong> that type is not the
 type that is being parsed</p>
 
 <p>The following code fragment shows how the ADB deserialize method calls the
 mapper class</p>
-<pre>if (reader.getAttributeValue(
-                        "http://www.w3.org/2001/XMLSchema-instance", "type") != null) {
-        java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
+<pre>
+	     if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","type")!=null){
+                  java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
                         "type");
-        if (fullTypeName != null) {
-                java.lang.String nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
-                nsPrefix = (nsPrefix == null) ? "" : nsPrefix;
-                java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":") + 1);
-                if (!"derivedType2".equals(type)) {
+                  if (fullTypeName!=null){
+                    java.lang.String nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
+                    nsPrefix = nsPrefix==null?"":nsPrefix;
+
+                    java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":")+1);
+                    if (!"SOAPStruct".equals(type)){
                         //find namespace for the prefix
                         java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
-                        <strong>return (DerivedType2) namespace.webservice._new.types.ExtensionMapper.getTypeObject(nsUri,
-                                type, reader);</strong>
-                }
-        }
-}</pre>
+                        return (SOAPStruct)org.soapinterop.types.ExtensionMapper.getTypeObject(
+                             nsUri,type,reader);
+                      }
+
+                  }
+	      }</pre>
 
-<p>This should make the xsi:type based deserialization possible and should
+<p>This should make the xsi:type based parsing possible and should
 result in proper xsi:type based serializations at runtime</p>
 
 <p>This is automatically done but the package name for the mapper class can
-be controlled by using the <strong>mp</strong> flag (with a preceding -E)</p>
-<pre> WSDL2Code -uri .... -Emp org.example.web.map</pre>
+be set as an CompilerOption.</p>
+<pre>   
+	CompilerOptions compilerOptions = new CompilerOptions();
+        compilerOptions.setWriteOutput(true);
+        <strong>compilerOptions.setMapperClassPackage("com.test");</strong>
+        compilerOptions.setOutputLocation(new File("src"));
+        try {
+            SchemaCompiler schemaCompiler = new SchemaCompiler(compilerOptions);
+            XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
+            XmlSchema xmlSchema =xmlSchemaCollection.read(new FileReader("schema/sample.xsd"),null);
+            schemaCompiler.compile(xmlSchema);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+</pre>
 
 <p>When the mapping package is not specified it is derived from the
 targetnamespace of the first schema that is encountered</p>
@@ -93,10 +101,9 @@
 Also note that the helper mode is available only if you are in the unpacked
 mode. The code generator by default does not expand the classes</p>
 
-<p>Helper mode can be switched on by the <strong>h</strong> flag (Passed with
-a -E infront to indicate that it is an extra switch undertood by ADB). Also
-the <strong>-u</strong> flag should be present to indicate the unpacking</p>
-<pre> WSDL2Code -uri .... -u -Eh</pre>
+<p>Helper mode can be switched on by using the setHelperMode method  
+in CompilerOptions</p>
+<pre><strong>compilerOptions.setHelperMode(true);</strong></pre>
 
 <h2><a name="more">More Stuff on ADB?</a></h2>
 <ul>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org