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 aj...@apache.org on 2005/10/09 19:15:20 UTC
svn commit: r312479 - in /webservices/axis2/trunk/java/modules/codegen:
src/org/apache/axis2/databinding/schema/
src/org/apache/axis2/wsdl/codegen/emitter/
src/org/apache/axis2/wsdl/codegen/extension/
src/org/apache/axis2/wsdl/util/ test-resources/xsd/...
Author: ajith
Date: Sun Oct 9 10:14:24 2005
New Revision: 312479
URL: http://svn.apache.org/viewcvs?rev=312479&view=rev
Log:
1.Moved the util stuff from WSDL to codegen
2.Added a test case to test the schema compiler
Added:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/
- copied from r306976, webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/util/
webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/
webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/testXsd1.xsd
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/Xsd1Test.java
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/WSDL2JavaTest.java (contents, props changed)
- copied, changed from r306976, webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/wsdl/codegen/WSDL2JavaTest.java
Removed:
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/wsdl/codegen/WSDL2JavaTest.java
Modified:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java?rev=312479&r1=312478&r2=312479&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/schema/SchemaCompiler.java Sun Oct 9 10:14:24 2005
@@ -4,6 +4,7 @@
import java.util.List;
import java.util.Iterator;
+import java.util.HashMap;
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -22,7 +23,8 @@
public class SchemaCompiler {
- CompilerOptions options;
+ private CompilerOptions options;
+ private HashMap processedTypemap;
/**
*
@@ -36,6 +38,8 @@
this.options = options;
}
+ this.processedTypemap = new HashMap();
+
}
/**
@@ -63,14 +67,22 @@
*/
public void compile(XmlSchema schema) throws SchemaCompilationException{
//write the code here to do the schema compilation
+ //select the types
+ XmlSchemaObjectTable types = schema.getSchemaTypes();
+ Iterator xmlSchemaTypeIterator = types.getValues();
+ while (xmlSchemaTypeIterator.hasNext()) {
+ processSchema((XmlSchemaType)xmlSchemaTypeIterator.next());
+ }
+
+ //select all the elements next
XmlSchemaObjectTable elements = schema.getElements();
XmlSchemaElement xsElt;
Iterator xmlSchemaElementIterator = elements.getValues();
while (xmlSchemaElementIterator.hasNext()) {
- xsElt = (XmlSchemaElement)xmlSchemaElementIterator.next();
- processElement(xsElt);
+ processElement((XmlSchemaElement)xmlSchemaElementIterator.next());
}
+ System.out.println("processedTypemap = " + processedTypemap);
}
/**
@@ -78,29 +90,44 @@
* @param xsElt
*/
private void processElement(XmlSchemaElement xsElt){
-
+ //The processing element logic seems to be quite simple. Look at the relevant schema type
+ //for each and every element and process that accordingly.
+ //this means that any unused type definitions would not be generated!
XmlSchemaType schemaType = xsElt.getSchemaType();
if (schemaType!=null){
- if (schemaType instanceof XmlSchemaComplexType){
- //write classes for complex types
- processComplexSchemaType((XmlSchemaComplexType)schemaType);
- }else if (schemaType instanceof XmlSchemaSimpleType){
- processSimpleSchemaType((XmlSchemaSimpleType)schemaType);
- }
+ processSchema(schemaType);
+ }
+
+ //write a class for this element
+
+ }
+
+ private void processSchema(XmlSchemaType schemaType) {
+ if (schemaType instanceof XmlSchemaComplexType){
+ //write classes for complex types
+ processComplexSchemaType((XmlSchemaComplexType)schemaType);
+ }else if (schemaType instanceof XmlSchemaSimpleType){
+ processSimpleSchemaType((XmlSchemaSimpleType)schemaType);
}
}
/**
- *
+ * handle the complex type
* @param complexType
*/
private void processComplexSchemaType(XmlSchemaComplexType complexType){
+
+ if (processedTypemap.containsKey(complexType.getQName())){
+ return;
+ }
+
//to start with we need to write a class to represent this
//
+
XmlSchemaParticle particle = complexType.getParticle();
if (particle!=null){
//check the particle
- if (particle instanceof XmlSchemaSequence){
+ if (particle instanceof XmlSchemaSequence ){
XmlSchemaObjectCollection items = ((XmlSchemaSequence)particle).getItems();
int count = items.getCount();
for (int i = 0; i < count; i++) {
@@ -108,18 +135,28 @@
if (item instanceof XmlSchemaElement){
//recursively process the element
processElement((XmlSchemaElement)item);
+ }else{
+ //handle the other types here
}
+ }
+ }else if (particle instanceof XmlSchemaAll){
+ //handle the all !
- //process the items here. Usually the complex type needs to be represented as a bean class
+ }else if (particle instanceof XmlSchemaChoice){
+ //handle the choice!
+ }
- //populate a type map
+ }
- }
- }
+ //write the class. This type mapping would have been populated right now
+
+ processedTypemap.put(complexType.getQName(),"");
- }
+
+
+ //populate the type mapping with the elements
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java?rev=312479&r1=312478&r2=312479&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java Sun Oct 9 10:14:24 2005
@@ -590,7 +590,6 @@
*/
private Element getInputParamElement(Document doc,
WSDLOperation operation) {
- //todo this should go in a loop
Element param = doc.createElement("param");
MessageReference inputMessage = operation.getInputMessage();
if (inputMessage!=null){
@@ -598,6 +597,7 @@
"name",
this.mapper.getParameterName(inputMessage.getElement()),
param);
+ //todo modify the code here to unwrap if requested
String typeMapping = this.mapper.getTypeMapping(
inputMessage.getElement());
String typeMappingStr = typeMapping == null ? "org.apache.axis2.om.OMElement" : typeMapping;
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java?rev=312479&r1=312478&r2=312479&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SimpleDBExtension.java Sun Oct 9 10:14:24 2005
@@ -19,6 +19,8 @@
import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
import org.apache.axis2.wsdl.databinding.DefaultTypeMapper;
import org.apache.axis2.wsdl.databinding.JavaTypeMapper;
+import org.apache.axis2.databinding.schema.SchemaCompiler;
+import org.apache.axis2.databinding.schema.CompilerOptions;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.wsdl.WSDLExtensibilityElement;
@@ -34,9 +36,9 @@
import java.util.Vector;
/**
- * Work in progress to test simple DataBinding with the XmlSchema lib
- *
- */
+ * Work in progress to test simple DataBinding with the XmlSchema lib
+ *
+ */
public class SimpleDBExtension extends AbstractCodeGenerationExtension {
public void init(CodeGenConfiguration configuration) {
this.configuration = configuration;
@@ -55,10 +57,10 @@
List typesArray = typesList.getExtensibilityElements();
WSDLExtensibilityElement extensiblityElt = null;
-
+ Vector xmlSchemaTypeVector = new Vector();
for (int i = 0; i < typesArray.size(); i++) {
extensiblityElt = (WSDLExtensibilityElement) typesArray.get(i);
- Vector xmlObjectsVector = new Vector();
+
XmlSchemaCollection schemaColl = new XmlSchemaCollection();
Schema schema = null;
@@ -68,7 +70,7 @@
for (Iterator it = inScopeNS.keySet().iterator(); it.hasNext();) {
String prefix = (String) it.next();
schemaColl.mapNamespace(prefix,
- (String)inScopeNS.get(prefix));
+ (String)inScopeNS.get(prefix));
}
Stack importedSchemaStack = schema.getImportedSchemaStack();
@@ -76,10 +78,17 @@
while (!importedSchemaStack.isEmpty()) {
Element el = ((javax.wsdl.extensions.schema.Schema)importedSchemaStack.pop()).getElement();
XmlSchema thisSchema = schemaColl.read(el);
- xmlObjectsVector.add(thisSchema);
+ xmlSchemaTypeVector.add(thisSchema);
}
}
+ //call the schema compiler
+ CompilerOptions options = new CompilerOptions().setOutputLocation(configuration.getOutputLocation());
+ new SchemaCompiler(options)
+ .compile(xmlSchemaTypeVector);
+
+ //the schema compiler needs to populate a typemap also
+
//create the type mapper
JavaTypeMapper mapper = new JavaTypeMapper();
//set the type mapper to the config
Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/testXsd1.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/testXsd1.xsd?rev=312479&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/testXsd1.xsd (added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/testXsd1.xsd Sun Oct 9 10:14:24 2005
@@ -0,0 +1,51 @@
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
+
+ <complexType name="SOAPStruct">
+ <sequence>
+ <element name="varString" type="xsd:string"/>
+ <element name="varInt" type="xsd:int"/>
+ <element name="varFloat" type="xsd:float"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="SOAPStructFault">
+ <sequence>
+ <element name="soapStruct" type="tns:SOAPStruct"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="BaseStruct">
+ <sequence>
+ <element name="structMessage" type="tns:SOAPStruct"/>
+ <element name="shortMessage" type="xsd:short"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="ExtendedStruct">
+ <complexContent>
+ <extension base="tns:BaseStruct">
+ <sequence>
+ <element name="stringMessage" type="xsd:string"/>
+ <element name="intMessage" type="xsd:int"/>
+ <element name="anotherIntMessage" type="xsd:int"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="MoreExtendedStruct">
+ <complexContent>
+ <extension base="tns:ExtendedStruct">
+ <sequence>
+ <element name="booleanMessage" type="xsd:boolean"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ </schema>
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java?rev=312479&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/AbstractSchemaCompilerTester.java Sun Oct 9 10:14:24 2005
@@ -0,0 +1,58 @@
+package org.apache.axis2.databinding.schema;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Maven is a little dumb when it comes to executing test cases. It tries to run everything
+ that ends with 'test' even if the class is abstract or non junit!!!!!
+ Rather than putting an explicit exclude, this is a cheaper way out
+*/
+public abstract class AbstractSchemaCompilerTester extends TestCase {
+
+ //this should be an xsd name in the test-resource directory
+ protected String fileName = "";
+ protected XmlSchema currentSchema;
+
+ protected void setUp() throws Exception {
+ //load the current Schema through a file
+ //first read the file into a DOM
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document doc = builder.parse(new File(fileName));
+
+ //now read it to a schema
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ currentSchema = schemaCol.read(doc,null);
+ }
+
+
+ public void testSchema() throws Exception{
+ SchemaCompiler compiler = new SchemaCompiler(null);
+ compiler.compile(currentSchema);
+ }
+
+
+}
Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/Xsd1Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/Xsd1Test.java?rev=312479&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/Xsd1Test.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/schema/Xsd1Test.java Sun Oct 9 10:14:24 2005
@@ -0,0 +1,26 @@
+package org.apache.axis2.databinding.schema;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Xsd1Test extends AbstractSchemaCompilerTester {
+
+ protected void setUp() throws Exception {
+ this.fileName = "test-resources/xsd/testXsd1.xsd";
+ super.setUp();
+ }
+
+
+}
Copied: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/WSDL2JavaTest.java (from r306976, webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/wsdl/codegen/WSDL2JavaTest.java)
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/WSDL2JavaTest.java?p2=webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/WSDL2JavaTest.java&p1=webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/wsdl/codegen/WSDL2JavaTest.java&r1=306976&r2=312479&rev=312479&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/wsdl/codegen/WSDL2JavaTest.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/WSDL2JavaTest.java Sun Oct 9 10:14:24 2005
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.apache.axis2.databinding.wsdl.codegen;
+package org.apache.axis2.wsdl;
import org.apache.axis2.wsdl.codegen.CodeGenerationEngine;
import org.apache.axis2.wsdl.codegen.CodeGenerationException;
Propchange: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/WSDL2JavaTest.java
------------------------------------------------------------------------------
svn:eol-style = native