axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r429238 [4/4] - in /webservices/axis2/trunk/java/modules/adb-codegen: src/org/apache/axis2/schema/ src/org/apache/axis2/schema/template/ src/org/apache/axis2/schema/writer/ test-resources/xsd/ test/org/apache/axis2/schema/compile/
Date Mon, 07 Aug 2006 04:49:11 GMT
Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=429238&r1=429237&r2=429238&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Sun Aug  6 21:49:10 2006
@@ -469,6 +469,11 @@
                     .getExtensionClassName(), rootElt);
 
         }
+        if (metainf.isRestriction()) {
+            XSLTUtils.addAttribute(model, "restriction", metainf
+                    .getRestrictionClassName(), rootElt);
+
+        }
         //add the mapper class name
         XSLTUtils.addAttribute(model, "mapperClass", getFullyQualifiedMapperClassName(),
rootElt);
 
@@ -525,18 +530,33 @@
                                     Document model, Element rootElt, ArrayList propertyNames,
                                     Map typeMap, boolean isInherited) throws SchemaCompilationException
{
         // go in the loop and add the part elements
-        QName[] qNames;
+    	QName[] qName;
+    	String javaClassNameForElement;
+        ArrayList missingQNames = new ArrayList();
+        ArrayList qNames = new ArrayList();
+        
+        BeanWriterMetaInfoHolder parentMetaInf = metainf.getParent();
+        
         if (metainf.isOrdered()) {
-            qNames = metainf.getOrderedQNameArray();
+            qName = metainf.getOrderedQNameArray();
         } else {
-            qNames = metainf.getQNameArray();
+            qName= metainf.getQNameArray();
+        }
+        
+        for (int i = 0; i < qName.length; i++) {
+        	qNames.add(qName[i]);
+        }
+        //adding missing QNames to the end, including elements & attributes.
+        if (metainf.isRestriction()) {
+        	addMissingQNames(metainf, qNames, missingQNames);
         }
-
         QName name;
-        for (int i = 0; i < qNames.length; i++) {
+
+        for (int i = 0; i < qNames.size(); i++) {
+        	name = (QName) qNames.get(i);
             Element property = XSLTUtils.addChildElement(model, "property",
                     rootElt);
-            name = qNames[i];
+            name = (QName)qNames.get(i);
             String xmlName = name.getLocalPart();
             XSLTUtils.addAttribute(model, "name", xmlName, property);
             XSLTUtils.addAttribute(model, "nsuri", name.getNamespaceURI(),
@@ -544,13 +564,23 @@
             String javaName = makeUniqueJavaClassName(propertyNames, xmlName);
             XSLTUtils.addAttribute(model, "javaname", javaName, property);
 
-            String javaClassNameForElement = metainf.getClassNameForQName(name);
-
+            if (metainf.isRestriction() && missingQNames.contains(name)) {
+            	javaClassNameForElement = parentMetaInf.getClassNameForQName(name);
+            }
+            else {
+            	javaClassNameForElement = metainf.getClassNameForQName(name);
+            }
+            
             if (javaClassNameForElement == null) {
                 throw new SchemaCompilationException(SchemaCompilerMessages
                         .getMessage("schema.typeMissing"));
             }
-
+            
+            if (metainf.isRestriction() && typeChanged(name, missingQNames, metainf))
{
+            	XSLTUtils.addAttribute(model, "typeChanged", "yes", property);
+            	//XSLTUtils.addAttribute(model, "restricted", "yes", property);
+            }
+            
             XSLTUtils.addAttribute(model, "type", javaClassNameForElement,
                     property);
 
@@ -590,6 +620,11 @@
             XSLTUtils.addAttribute(model, "shorttypename", shortTypeName,
                     property);
 
+            if (metainf.isRestriction() && missingQNames.contains(name)) {
+            	//XSLTUtils.addAttribute(model, "restricted", "yes", property);
+            	XSLTUtils.addAttribute(model, "removed", "yes", property);
+            }
+            
             if (isInherited) {
                 XSLTUtils.addAttribute(model, "inherited", "yes", property);
             }
@@ -606,6 +641,18 @@
             long minOccurs = metainf.getMinOccurs(name);
             XSLTUtils
                     .addAttribute(model, "minOccurs", minOccurs + "", property);
+            
+            //in the case the original element is an array but the derived one is not.
+            if (metainf.isRestriction() && !missingQNames.contains(name) &&
+               (parentMetaInf.getArrayStatusForQName(name) && !metainf.getArrayStatusForQName(name)))
{
+            	XSLTUtils.addAttribute(model, "rewrite", "yes", property);
+            	XSLTUtils.addAttribute(model, "occuranceChanged", "yes", property);
+            }
+            else if (metainf.isRestriction() && !missingQNames.contains(name) &&
+            		(minOccursChanged(name, missingQNames, metainf) || maxOccursChanged(name, missingQNames,
metainf))) {
+            	XSLTUtils.addAttribute(model, "restricted", "yes", property);
+            	XSLTUtils.addAttribute(model, "occuranceChanged", "yes", property);
+            }
 
             if (metainf.getArrayStatusForQName(name)) {
 
@@ -627,6 +674,162 @@
         }
     }
 
+    private void addMissingQNames(BeanWriterMetaInfoHolder metainf, ArrayList qName, ArrayList
missingQNames) {
+    	
+    	QName[] qNames;
+        QName[] pQNames;
+        //ArrayList missingQNames = new ArrayList();
+            		
+        BeanWriterMetaInfoHolder parentMetaInf = metainf.getParent();
+        
+        if (metainf.isOrdered()) {
+            qNames = metainf.getOrderedQNameArray();
+        } else {
+            qNames = metainf.getQNameArray();
+        }
+        
+        if (parentMetaInf.isOrdered()) {
+            pQNames = parentMetaInf.getOrderedQNameArray();
+        } else {
+            pQNames = parentMetaInf.getQNameArray();
+        }
+        
+        
+        for (int i=0; i < pQNames.length; i++) {
+       		if (qNameNotFound(pQNames[i], metainf)) {
+       			missingQNames.add(pQNames[i]);
+       		}
+       	}
+       	//adding missing QNames to the end of list.
+        if (!missingQNames.isEmpty()) {
+       		for (int i=0; i < missingQNames.size(); i++) {
+       			qName.add(missingQNames.get(i));
+       		}
+       	}
+        //return qName;
+    }
+    
+    private boolean qNameNotFound(QName qname, BeanWriterMetaInfoHolder metainf) {
+    	
+    	boolean found = false;
+    	QName[] qNames;
+    	
+    	if (metainf.isOrdered()) {
+        	qNames = metainf.getOrderedQNameArray();
+        } else {
+        	qNames = metainf.getQNameArray();
+        }
+        
+        for (int j = 0; j < qNames.length; j++) {
+        	if (qname.getLocalPart().equals(qNames[j].getLocalPart())) {
+        			found = true;
+        	}
+        }
+        return !found;
+    }
+    
+    private boolean typeChanged(QName qname, ArrayList missingQNames, BeanWriterMetaInfoHolder
metainf) {
+    	
+    	boolean typeChanged = false;
+    	QName[] pQNames;
+    	
+    	BeanWriterMetaInfoHolder parentMetainf = metainf.getParent(); 
+        
+    	if (!missingQNames.contains(qname)) {
+    		
+    		if (parentMetainf.isOrdered()) {
+    			pQNames = parentMetainf.getOrderedQNameArray();
+    		} else {
+    			pQNames = parentMetainf.getQNameArray();
+    		}
+    		
+    		for (int j = 0; j < pQNames.length; j++) {
+    			if (qname.getLocalPart().equals(pQNames[j].getLocalPart())) {
+    				
+    				String javaClassForParentElement = parentMetainf.getClassNameForQName(pQNames[j]);
+    				String javaClassForElement = metainf.getClassNameForQName(qname);
+    				
+    				if (!javaClassForParentElement.equals(javaClassForElement)) {
+    					if (javaClassForParentElement.endsWith("[]")) {
+    						if ((javaClassForParentElement.substring(0,javaClassForParentElement.indexOf('['))).equals(javaClassForElement))
{
+    						continue;
+    						}
+    					}
+    					else if (javaClassForElement.endsWith("[]")) {
+    						if ((javaClassForElement.substring(0,javaClassForElement.indexOf('['))).equals(javaClassForParentElement))
{
+    							continue;
+    						}
+    					}
+    					else {
+    						typeChanged = true;
+    					}
+    				}
+    			}
+    		}
+    	}
+        return typeChanged;
+    }
+    
+    private boolean minOccursChanged(QName qname, ArrayList missingQNames, BeanWriterMetaInfoHolder
metainf) throws SchemaCompilationException {
+    	
+    	boolean minChanged = false;
+    	QName[] pQNames;
+    	
+    	BeanWriterMetaInfoHolder parentMetainf = metainf.getParent(); 
+        	
+    	if (!missingQNames.contains(qname)) {
+    		
+    		if (parentMetainf.isOrdered()) {
+    			pQNames = parentMetainf.getOrderedQNameArray();
+    		} else {
+    			pQNames = parentMetainf.getQNameArray();
+    		}
+    		
+    		for (int j = 0; j < pQNames.length; j++) {
+    			if (qname.getLocalPart().equals(pQNames[j].getLocalPart())) {
+    				
+    				if (metainf.getMinOccurs(qname) > parentMetainf.getMinOccurs(pQNames[j])) {
+    					minChanged = true;
+    				}
+    				else if(metainf.getMinOccurs(qname) < parentMetainf.getMinOccurs(pQNames[j]))
{
+    					throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("minOccurs
Wrong!")); 
+    				}
+    				
+    			}
+    		}
+    	}
+        return minChanged;
+    }
+    
+    private boolean maxOccursChanged(QName qname, ArrayList missingQNames, BeanWriterMetaInfoHolder
metainf) throws SchemaCompilationException {
+    	
+    	boolean maxChanged = false;
+    	QName[] pQNames;
+    	
+    	BeanWriterMetaInfoHolder parentMetainf = metainf.getParent();
+    	
+    	if (!missingQNames.contains(qname)) {	
+    		if (parentMetainf.isOrdered()) {
+    			pQNames = parentMetainf.getOrderedQNameArray();
+    		} else {
+    			pQNames = parentMetainf.getQNameArray();
+    		}
+    		
+    		for (int j = 0; j < pQNames.length; j++) {
+    			if (qname.getLocalPart().equals(pQNames[j].getLocalPart())) {
+    				
+    				if (metainf.getMaxOccurs(qname) < parentMetainf.getMaxOccurs(pQNames[j])) {
+    					maxChanged = true;
+    				}
+    				else if(metainf.getMaxOccurs(qname) > parentMetainf.getMaxOccurs(pQNames[j]))
{
+    					throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("maxOccurs
Wrong!")); 
+    				}
+    			}
+    		}
+    	}
+        return maxChanged;
+    }
+    
     /**
      * Test whether the given class name matches the default
      * 
@@ -899,4 +1102,7 @@
 
 
     }
+    
 }
+
+

Added: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/xsd/simple_content_extension.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/xsd/simple_content_extension.xsd?rev=429238&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/xsd/simple_content_extension.xsd
(added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/xsd/simple_content_extension.xsd
Sun Aug  6 21:49:10 2006
@@ -0,0 +1,26 @@
+<schema elementFormDefault="qualified"
+        xmlns:xs="http://www.w3.org/2001/XMLSchema"
+        xmlns="http://www.w3.org/2001/XMLSchema"
+        xmlns:tns="org.apache.axis2.test5"
+        targetNamespace="org.apache.axis2.test5">
+
+<xs:complexType name="type">
+	<xs:sequence>
+          <xs:element name="first" type="xs:string" />
+          <xs:element name="middle" type="xs:string" />
+          <xs:element name="last" type="xs:string" />
+        </xs:sequence>
+</xs:complexType>
+
+<xs:element name="fullName">
+  <xs:complexType>
+    <xs:simpleContent>
+      <xs:extension base="tns:type">
+        <xs:attribute name="language" type="xs:language"/>
+      </xs:extension>
+    </xs:simpleContent>
+  </xs:complexType>
+ </xs:element>
+
+
+</schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/compile/SimpleContentExtensionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/compile/SimpleContentExtensionTest.java?rev=429238&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/compile/SimpleContentExtensionTest.java
(added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/compile/SimpleContentExtensionTest.java
Sun Aug  6 21:49:10 2006
@@ -0,0 +1,23 @@
+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 SimpleContentExtensionTest extends AbstractSchemaCompilerTester{
+    protected void setUp() throws Exception {
+        this.fileName = "test-resources/xsd/simple_content_extension.xsd";
+        super.setUp();
+    }
+}



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


Mime
View raw message