axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r372091 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/schema/ src/org/apache/axis2/schema/i18n/ test-resources/xsd/ test/org/apache/axis2/schema/compile/
Date Wed, 25 Jan 2006 03:44:20 GMT
Author: ajith
Date: Tue Jan 24 19:44:08 2006
New Revision: 372091

URL: http://svn.apache.org/viewcvs?rev=372091&view=rev
Log:
Fixed the schemaCompiler to handle element references
1. Modified the SchemaCompiler.java
2. Added a new test and the test resource.
3. Added properly internationlized messages

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element_reference.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleElementReferenceTest.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=372091&r1=372090&r2=372091&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/SchemaCompiler.java
Tue Jan 24 19:44:08 2006
@@ -3,6 +3,7 @@
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
 import org.apache.axis2.schema.writer.BeanWriter;
+import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAll;
 import org.apache.ws.commons.schema.XmlSchemaAny;
@@ -68,6 +69,9 @@
     //The writing to the processedElementList happens when an outer element is processed.
     private HashMap processedElementMap;
     private HashMap processedAnonymousComplexTypesMap;
+    //we need this map to keep the referenced elements. these elements need to be kept seperate
+    //to avoid conflicts
+    private HashMap processedElementRefMap;
     private HashMap simpleTypesMap;
     private HashMap changedTypeMap;
 
@@ -129,6 +133,7 @@
         processedAnonymousComplexTypesMap = new HashMap();
         changedTypeMap = new HashMap();
         processedTypeMetaInfoMap = new HashMap();
+        processedElementRefMap = new HashMap();
 
         //load the writer a nd initiliaze the base type
         writer = SchemaPropertyLoader.getBeanWriterInstance();
@@ -255,9 +260,9 @@
 
 
             }else if (xsElt.getRefName()!= null){
-
-                // todo We need to handle the references here
-
+                //Since top level elements would not have references
+                // and we only write toplevel elements, this should
+                // not be a problem , atleast should not occur in a legal schema
             }else{
 
                 //we are going to special case the anonymous complex type. Our algorithm
for dealing
@@ -296,7 +301,7 @@
      * @param isArray-  flag saying whether the elements represents an array
      * @throws SchemaCompilationException
      */
-    private void processElement(XmlSchemaElement xsElt, boolean isOuter, boolean isArray,XmlSchema
parenSchema) throws SchemaCompilationException {
+    private void processElement(XmlSchemaElement xsElt, boolean isOuter, boolean isArray,XmlSchema
parentSchema) throws SchemaCompilationException {
         //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!
@@ -306,20 +311,42 @@
 
         XmlSchemaType schemaType = xsElt.getSchemaType();
         if (schemaType != null) {
-            processSchema(xsElt, schemaType,parenSchema);
+            processSchema(xsElt, schemaType,parentSchema);
             //at this time it is not wise to directly write the class for the element
             //so we push the complete element to an arraylist and let the process
             //pass through. We'll be iterating through the elements writing them
             //later
-        }
 
-        //There can be instances where the SchemaType is null but the schemaTypeName is not
-        //this specifically happens with xsd:anyType.
-        if (!isOuter) {
-            String className = findClassName(xsElt.getSchemaTypeName(), isArray(xsElt));
-            this.processedElementMap.put(xsElt.getQName(), className);
+            //There can be instances where the SchemaType is null but the schemaTypeName
is not
+            //this specifically happens with xsd:anyType.
+            if (!isOuter) {
+                String className = findClassName(xsElt.getSchemaTypeName(), isArray(xsElt));
+                this.processedElementMap.put(xsElt.getQName(), className);
+            }
+
+            this.processedElementList.add(xsElt.getQName());
+        }else if (xsElt.getRefName()!=null){
+
+            //process the referenced type. It could be thought that the referenced element
replaces this
+            //element
+
+            XmlSchemaElement referencedElement = parentSchema.getElementByName(xsElt.getRefName());
+            processElement(referencedElement,
+                    true, //if the element is referenced, then it should be one of the outer
(global) ones
+                    parentSchema);
+
+            //no outer check required here. If the element is having a ref, then it is definitely
+            //not an outer element.
+            //Also we are sure that it should have a type reference
+            String className = findClassName(referencedElement.getSchemaTypeName(), isArray(xsElt));
+            //if this element is referenced, there's no QName for this element
+            this.processedElementRefMap.put(referencedElement.getQName(), className);
+
+
         }
-        this.processedElementList.add(xsElt.getQName());
+
+
+
 
     }
 
@@ -541,7 +568,7 @@
     private void copyMetaInfoHierarchy(BeanWriterMetaInfoHolder metaInfHolder,
                                        QName baseTypeName,
                                        XmlSchema parentSchema)
-                                                throws SchemaCompilationException {
+            throws SchemaCompilationException {
         XmlSchemaType type = parentSchema.getTypeByName(baseTypeName);
         BeanWriterMetaInfoHolder baseMetaInfoHolder = (BeanWriterMetaInfoHolder)
                 processedTypeMetaInfoMap.get(baseTypeName);
@@ -566,7 +593,7 @@
                                     parentSchema);
 
                         }else  if (complexContent.getContent() instanceof XmlSchemaComplexContentRestriction){
-                            
+
                             XmlSchemaComplexContentRestriction restriction =
                                     (XmlSchemaComplexContentRestriction)complexContent.getContent();
                             //recursively call the copyMetaInfoHierarchy method
@@ -575,13 +602,15 @@
                                     parentSchema);
 
                         }else{
-                            throw new SchemaCompilationException(); //todo put the right
message
+                            throw new SchemaCompilationException(
+                                    SchemaCompilerMessages.getMessage("schema.unknowncontenterror"));
                         }
 
                     }else if (content instanceof XmlSchemaSimpleContent){
                         //todo
                     }else{
-                        throw new SchemaCompilationException();
+                       throw new SchemaCompilationException(
+                                    SchemaCompilerMessages.getMessage("schema.unknowncontenterror"));
                     }
                 }
 
@@ -682,19 +711,12 @@
                     //hashmap with the order number
                     elementOrderMap.put(xsElt, new Integer(i));
                 }
-            } else if (item instanceof XmlSchemaComplexContent) {
-                // process the extension
-                XmlSchemaContent content = ((XmlSchemaComplexContent) item).getContent();
-
-                if (content instanceof XmlSchemaComplexContentExtension) {
-                    //todo  handle the complex content extension (at top level)
-                } else if (content instanceof XmlSchemaComplexContentRestriction) {
-                    //todo  handle complex content restriction (at top level)
-                }
 
                 //handle xsd:any ! We place an OMElement in the generated class
             } else if (item instanceof XmlSchemaAny) {
                 processAny((XmlSchemaAny) item, metainfHolder);
+            } else {
+                //there are other types to be handled
             }
 
 
@@ -705,14 +727,29 @@
         int startingItemNumberOrder = metainfHolder.getOrderStartPoint();
         while (processedElementsIterator.hasNext()) {
             XmlSchemaElement elt = (XmlSchemaElement) processedElementsIterator.next();
-            QName qName = elt.getQName();
-            String clazzName = (String) processedElementMap.get(qName);
-            metainfHolder.registerMapping(qName,
-                    elt.getSchemaTypeName()
-                    , clazzName,
-                    ((Boolean) processedElements.get(elt)).booleanValue() ?
-                            SchemaConstants.ANY_ARRAY_TYPE :
-                            SchemaConstants.ELEMENT_TYPE);
+            String clazzName;
+            QName qName = null;
+            if (elt.getQName()!=null){ //probably this is referenced
+                clazzName = (String) processedElementMap.get(elt.getQName());
+                qName = elt.getQName();
+                metainfHolder.registerMapping(qName,
+                        elt.getSchemaTypeName()
+                        , clazzName,
+                        ((Boolean) processedElements.get(elt)).booleanValue() ?
+                                SchemaConstants.ANY_ARRAY_TYPE :
+                                SchemaConstants.ELEMENT_TYPE);
+            }else{
+                clazzName = (String)processedElementRefMap.get(elt.getRefName());
+                qName = elt.getRefName();
+                metainfHolder.registerMapping(qName,
+                        parentSchema.getElementByName(elt.getRefName()).getSchemaTypeName()
+                        , clazzName,
+                        ((Boolean) processedElements.get(elt)).booleanValue() ?
+                                SchemaConstants.ANY_ARRAY_TYPE :
+                                SchemaConstants.ELEMENT_TYPE);
+            }
+
+
 
             //register the occurence counts
             metainfHolder.addMaxOccurs(qName, elt.getMaxOccurs());

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties?rev=372091&r1=372090&r2=372091&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/i18n/resource.properties
Tue Jan 24 19:44:08 2006
@@ -20,7 +20,7 @@
 
 ###################Schema compiler ###########################################
 schema.unsupportedcontenterror=Unsupported content!
-
+schema.unknowncontenterror=Unknown content!
 ################## Options ###################################################
 schema.unsupportedvalue=Unsupported value!
 

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element_reference.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element_reference.xsd?rev=372091&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element_reference.xsd
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_element_reference.xsd
Tue Jan 24 19:44:08 2006
@@ -0,0 +1,16 @@
+<schema elementFormDefault="qualified"
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+        xmlns="http://www.w3.org/2001/XMLSchema"
+        xmlns:tns="urn:sobject.enterprise.soap.sforce.com"
+        targetNamespace="urn:sobject.enterprise.soap.sforce.com">
+    <complexType name="sObject">
+        <sequence>
+            <element ref="tns:fieldsToNull" />
+            <element ref="tns:Id" />
+        </sequence>
+    </complexType>
+    <element name="fieldsToNull"  type="xsd:string" />
+    <element name="Id"  type="xsd:string" />
+    <element name="Account" type="tns:sObject"/>
+    
+</schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleElementReferenceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleElementReferenceTest.java?rev=372091&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleElementReferenceTest.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/compile/SimpleElementReferenceTest.java
Tue Jan 24 19:44:08 2006
@@ -0,0 +1,27 @@
+package org.apache.axis2.schema.compile;
+/*
+ * 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 SimpleElementReferenceTest extends AbstractSchemaCompilerTester {
+    protected void setUp() throws Exception {
+        this.fileName = "test-resources/xsd/simple_element_reference.xsd";
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        
+    }
+}



Mime
View raw message