You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by am...@apache.org on 2012/08/25 18:59:40 UTC

svn commit: r1377324 - in /axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl: GsonNamespaceConext.java GsonXMLStreamWriter.java JsonFormatter.java utils/XmlNodeGenerator.java

Author: amilas
Date: Sat Aug 25 16:59:39 2012
New Revision: 1377324

URL: http://svn.apache.org/viewvc?rev=1377324&view=rev
Log:
apply the patch for AXIS2-5400

Added:
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonNamespaceConext.java
Modified:
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonXMLStreamWriter.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/JsonFormatter.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/utils/XmlNodeGenerator.java

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonNamespaceConext.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonNamespaceConext.java?rev=1377324&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonNamespaceConext.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonNamespaceConext.java Sat Aug 25 16:59:39 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.json.impl;
+
+import javax.xml.namespace.NamespaceContext;
+import java.util.Iterator;
+
+public class GsonNamespaceConext implements NamespaceContext {
+
+    public String getNamespaceURI(String prefix) {
+        return null;
+    }
+
+    public String getPrefix(String namespaceURI) {
+        return null;
+    }
+
+    public Iterator getPrefixes(String namespaceURI) {
+        return null; 
+    }
+}

Modified: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonXMLStreamWriter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonXMLStreamWriter.java?rev=1377324&r1=1377323&r2=1377324&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonXMLStreamWriter.java (original)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/GsonXMLStreamWriter.java Sat Aug 25 16:59:39 2012
@@ -300,7 +300,7 @@ public class GsonXMLStreamWriter impleme
      */
 
     public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
-        throw new UnsupportedOperationException("Method is not implemented");
+        writeStartElement(localName);
     }
 
     /**
@@ -532,7 +532,7 @@ public class GsonXMLStreamWriter impleme
      */
 
     public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
-        throw new UnsupportedOperationException("Method is not implemented");
+        // do nothing
     }
 
     /**
@@ -752,7 +752,7 @@ public class GsonXMLStreamWriter impleme
      */
 
     public void setDefaultNamespace(String uri) throws XMLStreamException {
-        throw new UnsupportedOperationException("Method is not implemented");
+        //do nothing. 
     }
 
     /**
@@ -783,7 +783,7 @@ public class GsonXMLStreamWriter impleme
      */
 
     public NamespaceContext getNamespaceContext() {
-        return null;
+        return new GsonNamespaceConext();
     }
 
     /**

Modified: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/JsonFormatter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/JsonFormatter.java?rev=1377324&r1=1377323&r2=1377324&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/JsonFormatter.java (original)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/JsonFormatter.java Sat Aug 25 16:59:39 2012
@@ -101,7 +101,7 @@ public class JsonFormatter implements Me
                     }
                     xmlsw.writeEndDocument();
                 } catch (XMLStreamException e) {
-                    throw new AxisFault("Error while writing to the output stream using JsonWriter");
+                    throw new AxisFault("Error while writing to the output stream using JsonWriter", e);
                 }
 
             } else {

Modified: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/utils/XmlNodeGenerator.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/utils/XmlNodeGenerator.java?rev=1377324&r1=1377323&r2=1377324&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/utils/XmlNodeGenerator.java (original)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/utils/XmlNodeGenerator.java Sat Aug 25 16:59:39 2012
@@ -23,6 +23,7 @@ package org.apache.axis2.json.impl.utils
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaParticle;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
@@ -54,120 +55,92 @@ public class XmlNodeGenerator {
     }
 
     private void processSchemaList() {
-        // get the response schema and find the type then process.
-        XmlSchema responseSchema = getXmlSchema(elementQname);
-        XmlSchemaElement methodElement = responseSchema.getElementByName(elementQname.getLocalPart());
-        QName methodSchemaTypeName = methodElement.getSchemaTypeName();
+        // get the operation schema and process.
+        XmlSchema operationSchema = getXmlSchema(elementQname);
+        XmlSchemaElement methodElement = operationSchema.getElementByName(elementQname.getLocalPart());
         mainXmlNode = new XmlNode(elementQname.getLocalPart(), elementQname.getNamespaceURI() , false, (methodElement.getMaxOccurs() == 1 ? false : true) , "");
-        XmlSchemaParticle particle = ((XmlSchemaComplexType) methodElement.getSchemaType()).getParticle();
-        XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
-        XmlSchemaObjectCollection xmlSchemaObjectCollection = sequence.getItems();
-
-        Iterator iterator = xmlSchemaObjectCollection.getIterator();
-        while (iterator.hasNext()) {
-            Object nextEle = iterator.next();
-            if (nextEle instanceof XmlSchemaElement) {
-                XmlSchemaElement innerElement = ((XmlSchemaElement) nextEle);   // todo add to xml node
-                XmlSchemaType innerEleType = innerElement.getSchemaType();
-                if (innerEleType == null) {
-                    processSchemaTypeName(innerElement, mainXmlNode);
-                } else if (innerEleType instanceof XmlSchemaComplexType) {
-                    processComplexType(innerElement , mainXmlNode);
-                } else if (innerEleType instanceof XmlSchemaSimpleType) {
-                    processSimpleType(innerElement , mainXmlNode);
-                }
-            }
-        }
-
-/*        XmlSchemaElement argElement = (XmlSchemaElement) xmlSchemaObjectCollection.getItem(0);
-        XmlSchemaType schemaType = argElement.getSchemaType();
-        QName argQname = argElement.getQName();
-        QName schemaTypeName = argElement.getSchemaTypeName();
-        XmlNode temp;
-        if (argQname == null) {
-            temp = new XmlNode(argElement.getName(),elementQname.getNamespaceURI(), false, (argElement.getMaxOccurs() == 1 ? false : true) ,schemaTypeName.getLocalPart());
+        QName methodSchemaTypeName = methodElement.getSchemaTypeName();
+        XmlSchemaType schemaType = null;
+        if (methodSchemaTypeName != null){
+            schemaType = getXmlSchema(methodSchemaTypeName).getTypeByName(methodSchemaTypeName.getLocalPart());
         } else {
-            temp = new XmlNode(argQname.getLocalPart(),argQname.getNamespaceURI(), false, (argElement.getMaxOccurs() == 1 ? false : true) ,schemaTypeName.getLocalPart());
-
+            schemaType = methodElement.getSchemaType();
         }
-        mainXmlNode.addChildtoList(temp);
-        String pref = schemaTypeName.getPrefix();
-        if (("xs").equals(pref)) {
-        } else {
-            XmlSchema tempXmlSchema = getXmlSchema(schemaTypeName);
-            processXmlSchema(tempXmlSchema, schemaTypeName,temp);
-        }*/
-    }
 
-    private XmlSchema getXmlSchema(QName qName) {
-        for (XmlSchema xmlSchema : xmlSchemaList) {
-            if (xmlSchema.getTargetNamespace().equals(qName.getNamespaceURI())) {
-                return xmlSchema;
-            }
+        if (schemaType != null) {
+            processSchemaType(schemaType, mainXmlNode , operationSchema);
+        } else {
+            // nothing to do
         }
-        return null;
     }
 
-    private void processSchemaTypeName(XmlSchemaElement element, XmlNode parentNode) {
+    private void processElement(XmlSchemaElement element, XmlNode parentNode , XmlSchema schema) {
         QName schemaTypeName = element.getSchemaTypeName();
         QName qName = element.getQName();
         String pref = schemaTypeName.getPrefix();
-        XmlNode temp;
+        XmlNode tempNode;
         if (qName == null) {
-            temp = new XmlNode(element.getName(), parentNode.getNamespaceUri(), false, (element.getMaxOccurs() == 1 ? false : true), schemaTypeName.getLocalPart());
+            tempNode = new XmlNode(element.getName(), parentNode.getNamespaceUri(), false, (element.getMaxOccurs() == 1 ? false : true), schemaTypeName.getLocalPart());
 
         } else {
-            temp = new XmlNode(qName.getLocalPart(), qName.getNamespaceURI(), false, (element.getMaxOccurs() == 1 ? false : true), schemaTypeName.getLocalPart());
+            tempNode = new XmlNode(qName.getLocalPart(), qName.getNamespaceURI(), false, (element.getMaxOccurs() == 1 ? false : true), schemaTypeName.getLocalPart());
         }
-        parentNode.addChildtoList(temp);
+        parentNode.addChildtoList(tempNode);
         if (("xs").equals(pref)) {
+            // this element doesn't has child elements
         } else {
-            XmlSchema tempXmlSchema = getXmlSchema(schemaTypeName);
-            processXmlSchema(tempXmlSchema, schemaTypeName, temp);
+            XmlSchema childSchema = null;
+            XmlSchemaElement childEle = schema.getElementByName(schemaTypeName);
+            XmlSchemaType childType = schema.getTypeByName(schemaTypeName);
+            if (childEle == null && childType == null) {
+                childSchema = getXmlSchema(schemaTypeName);
+                childEle = childSchema.getElementByName(schemaTypeName);
+                childType = childSchema.getTypeByName(schemaTypeName);
+            } else {
+                childSchema = schema;
+            }
+
+            if (childEle == null) {
+                processSchemaType(childType, tempNode, childSchema);
+            } else {
+                processElement(childEle, tempNode, childSchema);
+            }
         }
+
     }
 
-    private void processXmlSchema(XmlSchema schema, QName elementQName, XmlNode xmlNode) {
-        XmlSchemaElement element = schema.getElementByName(elementQName);
-        if (element != null) {
-            XmlNode temp = new XmlNode(elementQName.getLocalPart(), elementQName.getNamespaceURI(), false, (element.getMaxOccurs() == 1 ? false : true) , element.getSchemaTypeName().getLocalPart());
-            xmlNode.addChildtoList(temp);
-        } else {
-            XmlSchemaObjectCollection schemaObjectCollection = schema.getItems();
-            if (schemaObjectCollection.getCount() != 0) {
-                Iterator schemaObjIterator = schemaObjectCollection.getIterator();
-                while (schemaObjIterator.hasNext()) {
-                    Object next = schemaObjIterator.next();
-                    if (next instanceof XmlSchemaComplexType) {
-                        XmlSchemaComplexType comtype = (XmlSchemaComplexType) next;
-                        if (elementQName.getLocalPart().equals(comtype.getName())) {
-                            XmlSchemaParticle particle = comtype.getParticle();
-                            if (particle instanceof XmlSchemaSequence) {
-                                XmlSchemaSequence schemaSequence = (XmlSchemaSequence) particle;
-                                XmlSchemaObjectCollection InnerSchemaObjectCollection = schemaSequence.getItems();
-                                Iterator iterator = InnerSchemaObjectCollection.getIterator();
-                                while (iterator.hasNext()) {
-                                    Object nextEle = iterator.next();
-                                    if (nextEle instanceof XmlSchemaElement) {
-                                        XmlSchemaElement innerElement = ((XmlSchemaElement) nextEle);   // todo add to xml node
-                                        XmlSchemaType innerEleType = innerElement.getSchemaType();
-                                        if (innerEleType == null) {
-                                            processSchemaTypeName(innerElement, xmlNode);
-                                        } else if (innerEleType instanceof XmlSchemaComplexType) {
-                                            processComplexType(innerElement , xmlNode);
-                                        } else if (innerEleType instanceof XmlSchemaSimpleType) {
-                                            processSimpleType(innerElement , xmlNode);
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    } else {
-                        // process simpletype
+
+    private void processSchemaType(XmlSchemaType xmlSchemaType , XmlNode parentNode , XmlSchema schema) {
+        if (xmlSchemaType instanceof XmlSchemaComplexType) {
+            XmlSchemaComplexType complexType = (XmlSchemaComplexType)xmlSchemaType;
+            XmlSchemaParticle particle = complexType.getParticle();
+            if (particle instanceof XmlSchemaSequence) {
+                XmlSchemaSequence sequence = (XmlSchemaSequence)particle;
+                XmlSchemaObjectCollection objectCollection = sequence.getItems();
+                Iterator objectIterator = objectCollection.getIterator();
+                while (objectIterator.hasNext()) {
+                    Object obj = objectIterator.next();
+                    if (obj instanceof XmlSchemaElement) {
+                        processElement((XmlSchemaElement)obj , parentNode , schema);
+                    }else if (obj instanceof XmlSchemaComplexType || obj instanceof  XmlSchemaSimpleType) {     // never come to this
+                        XmlSchemaType schemaType = (XmlSchemaType)obj;
+                        processSchemaType(schemaType , parentNode , schema);
                     }
                 }
             }
+        }else if (xmlSchemaType instanceof XmlSchemaSimpleType) {
+            // nothing to do with simpleType
+        }
+    }
+
+
+    private XmlSchema getXmlSchema(QName qName) {
+        for (XmlSchema xmlSchema : xmlSchemaList) {
+            if (xmlSchema.getTargetNamespace().equals(qName.getNamespaceURI())) {
+                return xmlSchema;
+            }
         }
+        return null;
     }
 
     private void generateQueue(XmlNode node) {
@@ -188,45 +161,13 @@ public class XmlNodeGenerator {
         }
     }
 
-    private void processComplexType(XmlSchemaElement xmlSchemaElement , XmlNode parentNode) {
-        QName schemaTypeName = xmlSchemaElement.getSchemaTypeName();
-        QName qName = xmlSchemaElement.getQName();
-        XmlNode temp = new XmlNode(qName.getLocalPart(), qName.getNamespaceURI(), false, (xmlSchemaElement.getMaxOccurs() == 1 ? false : true) , schemaTypeName.getLocalPart());
-        parentNode.addChildtoList(temp);
-        XmlSchemaSequence schemaSequence;
-        XmlSchemaParticle particle = ((XmlSchemaComplexType)xmlSchemaElement.getSchemaType()).getParticle();
-        if (particle instanceof XmlSchemaSequence) {
-            schemaSequence = (XmlSchemaSequence) particle;
-            XmlSchemaObjectCollection schemaObjectCollection = schemaSequence.getItems();
-            Iterator iterator = schemaObjectCollection.getIterator();
-            while (iterator.hasNext()) {
-                Object element = iterator.next();
-                if (element instanceof XmlSchemaElement) {
-                    XmlSchemaElement innerElement = ((XmlSchemaElement) element);
-                    XmlSchemaType innerEleType = innerElement.getSchemaType();
-                    if (innerEleType instanceof XmlSchemaComplexType) {
-                        processComplexType(innerElement , temp);
-                    } else if(innerEleType instanceof XmlSchemaSimpleType){
-                        processSimpleType(innerElement , temp);
-                    }
-                }
-            }
-        }
-    }
-
-    private void processSimpleType(XmlSchemaElement xmlSchemaElement , XmlNode parentNode) {
-        QName schemaTypeName= xmlSchemaElement.getSchemaTypeName();
-        QName qName = xmlSchemaElement.getQName();
-        XmlNode temp = new XmlNode(qName.getLocalPart(), qName.getNamespaceURI(), false, (xmlSchemaElement.getMaxOccurs() == 1 ? false : true) , schemaTypeName.getLocalPart());
-        parentNode.addChildtoList(temp);
-    }
-
     private void processXmlNodeChildren(List<XmlNode> childrenNodes) {
         for (int i = 0; i < childrenNodes.size(); i++) {
             generateQueue(childrenNodes.get(i));
         }
     }
 
+
     public XmlNode getMainXmlNode() {
         if (mainXmlNode == null) {
             processSchemaList();