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/09/06 17:24:45 UTC

svn commit: r1381640 [1/2] - in /axis/axis2/java/core/trunk/modules: json/src/org/apache/axis2/json/gson/ json/src/org/apache/axis2/json/gson/factory/ json/src/org/apache/axis2/json/gson/rpc/ json/src/org/apache/axis2/json/impl/ json/test/org/apache/ax...

Author: amilas
Date: Thu Sep  6 15:24:44 2012
New Revision: 1381640

URL: http://svn.apache.org/viewvc?rev=1381640&view=rev
Log:
applying the patch for AXIS2-5411

Added:
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonNamespaceConext.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamReader.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonBuilder.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonFormatter.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JSONType.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonConstant.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonObject.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonUtils.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/XmlNode.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/XmlNodeGenerator.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonInOnlyRPCMessageReceiver.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonRpcMessageReceiver.java
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/GsonXMLStreamReaderTest.java
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/GsonXMLStreamWriterTest.java
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JsonBuilderTest.java
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JsonFormatterTest.java
Removed:
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/impl/
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/impl/
Modified:
    axis/axis2/java/core/trunk/modules/samples/json/README.txt
    axis/axis2/java/core/trunk/modules/samples/json/resources/axis2.xml
    axis/axis2/java/core/trunk/modules/samples/json/src/META-INF/services.xml

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonNamespaceConext.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonNamespaceConext.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonNamespaceConext.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonNamespaceConext.java Thu Sep  6 15:24:44 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.gson;
+
+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; 
+    }
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamReader.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamReader.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamReader.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamReader.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,748 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson;
+
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.json.gson.factory.JSONType;
+import org.apache.axis2.json.gson.factory.JsonConstant;
+import org.apache.axis2.json.gson.factory.JsonObject;
+import org.apache.axis2.json.gson.factory.XmlNode;
+import org.apache.axis2.json.gson.factory.XmlNodeGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+import java.util.Stack;
+
+
+public class GsonXMLStreamReader implements XMLStreamReader {
+
+    private static final Log log = LogFactory.getLog(GsonXMLStreamReader.class);
+
+    private JsonReader jsonReader;
+
+    private JsonState state = JsonState.StartState;
+
+    private JsonToken tokenType;
+
+    private String localName;
+
+    private String value;
+
+    private boolean isProcessed;
+
+    private ConfigurationContext configContext;
+
+    private QName elementQname;
+
+    private XmlNode mainXmlNode;
+
+    private List<XmlSchema> xmlSchemaList;
+
+    private Queue<JsonObject> queue = new LinkedList<JsonObject>();
+
+    private XmlNodeGenerator xmlNodeGenerator;
+
+    private Stack<JsonObject> stackObj = new Stack<JsonObject>();
+    private Stack<JsonObject> miniStack = new Stack<JsonObject>();
+    private JsonObject topNestedArrayObj = null;
+    private Stack<JsonObject> processedJsonObject = new Stack<JsonObject>();
+
+    private String namespace;
+
+
+    public GsonXMLStreamReader(JsonReader jsonReader) {
+        this.jsonReader = jsonReader;
+    }
+
+    public GsonXMLStreamReader(JsonReader jsonReader, QName elementQname, List<XmlSchema> xmlSchemaList,
+                               ConfigurationContext configContext) {
+        this.jsonReader = jsonReader;
+        initXmlStreamReader(elementQname, xmlSchemaList, configContext);
+    }
+
+    public JsonReader getJsonReader() {
+        return jsonReader;
+    }
+
+    public void initXmlStreamReader(QName elementQname, List<XmlSchema> xmlSchemaList, ConfigurationContext configContext) {
+        this.elementQname = elementQname;
+        this.xmlSchemaList = xmlSchemaList;
+        this.configContext = configContext;
+        process();
+        isProcessed = true;
+
+    }
+
+    private void process() {
+        Object ob = configContext.getProperty(JsonConstant.XMLNODES);
+        if (ob != null) {
+            Map<QName, XmlNode> nodeMap = (Map<QName, XmlNode>) ob;
+            XmlNode requesNode = nodeMap.get(elementQname);
+            if (requesNode != null) {
+                xmlNodeGenerator = new XmlNodeGenerator();
+                queue = xmlNodeGenerator.getQueue(requesNode);
+            } else {
+                xmlNodeGenerator = new XmlNodeGenerator(xmlSchemaList, elementQname);
+                mainXmlNode = xmlNodeGenerator.getMainXmlNode();
+                queue = xmlNodeGenerator.getQueue(mainXmlNode);
+                nodeMap.put(elementQname, mainXmlNode);
+                configContext.setProperty(JsonConstant.XMLNODES, nodeMap);
+            }
+        } else {
+            Map<QName, XmlNode> newNodeMap = new HashMap<QName, XmlNode>();
+            xmlNodeGenerator = new XmlNodeGenerator(xmlSchemaList, elementQname);
+            mainXmlNode = xmlNodeGenerator.getMainXmlNode();
+            queue = xmlNodeGenerator.getQueue(mainXmlNode);
+            newNodeMap.put(elementQname, mainXmlNode);
+            configContext.setProperty(JsonConstant.XMLNODES, newNodeMap);
+        }
+        isProcessed = true;
+    }
+
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return null;
+    }
+
+
+    public int next() throws XMLStreamException {
+        if (hasNext()) {
+            try {
+                stateTransition();
+            } catch (IOException e) {
+                throw new XMLStreamException("I/O error while reading JSON input Stream");
+            }
+            return getEventType();
+        } else {
+            throw new NoSuchElementException("There is no any next event");
+        }
+    }
+
+
+    public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getElementText() throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public int nextTag() throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public boolean hasNext() throws XMLStreamException {
+        try {
+            tokenType = jsonReader.peek();
+            if (tokenType == JsonToken.END_DOCUMENT) {
+                return false;
+            } else {
+                return true;
+            }
+        } catch (IOException e) {
+            throw new XMLStreamException("Unexpected end of json stream");
+        }
+    }
+
+
+    public void close() throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getNamespaceURI(String prefix) {
+        if (isStartElement() || isEndElement()) {
+            return namespace;
+        } else {
+            return null;
+        }
+    }
+
+
+    public boolean isStartElement() {
+        if (state == JsonState.NameName
+                || state == JsonState.NameValue
+                || state == JsonState.ValueValue_CHAR
+                || state == JsonState.EndObjectBeginObject_START) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
+    public boolean isEndElement() {
+        if (state == JsonState.ValueValue_START
+                || state == JsonState.EndArrayName
+                || state == JsonState.ValueEndObject_END_2
+                || state == JsonState.ValueName_START
+                || state == JsonState.EndObjectName
+                || state == JsonState.EndObjectBeginObject_END
+                || state == JsonState.EndArrayEndObject
+                || state == JsonState.EndObjectEndObject) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
+    public boolean isCharacters() {
+        if (state == JsonState.ValueValue_END
+                || state == JsonState.ValueEndArray
+                || state == JsonState.ValueEndObject_END_1
+                || state == JsonState.ValueName_END) {
+            return true;
+        } else {
+            return false;
+        }
+
+    }
+
+
+    public boolean isWhiteSpace() {
+        return false;
+    }
+
+
+    public String getAttributeValue(String namespaceURI, String localName) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public int getAttributeCount() {
+        if (isStartElement()) {
+            return 0; // don't support attributes on tags  in JSON convention
+        } else {
+            throw new IllegalStateException("Only valid on START_ELEMENT state");
+        }
+    }
+
+
+    public QName getAttributeName(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getAttributeNamespace(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getAttributeLocalName(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getAttributePrefix(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getAttributeType(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getAttributeValue(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public boolean isAttributeSpecified(int index) {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public int getNamespaceCount() {
+        if (isStartElement() || isEndElement()) {
+            return 1; // we have one default namesapce
+        } else {
+            throw new IllegalStateException("only valid on a START_ELEMENT or END_ELEMENT state");
+        }
+    }
+
+
+    public String getNamespacePrefix(int index) {
+        if (isStartElement() || isEndElement()) {
+            return null;
+        } else {
+            throw new IllegalStateException("only valid on a START_ELEMENT or END_ELEMENT state");
+        }
+    }
+
+
+    public String getNamespaceURI(int index) {
+        if (isStartElement() || isEndElement()) {
+            return namespace;
+        } else {
+            throw new IllegalStateException("only valid on a START_ELEMENT or END_ELEMENT state");
+        }
+    }
+
+
+    public NamespaceContext getNamespaceContext() {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public int getEventType() {
+        if (state == JsonState.StartState) {
+            return START_DOCUMENT;
+        } else if (isStartElement()) {
+            return START_ELEMENT;
+        } else if (isCharacters()) {
+            return CHARACTERS;
+        } else if (isEndElement()) {
+            return END_ELEMENT;
+        } else if (state == JsonState.EndObjectEndDocument) {
+            return END_DOCUMENT;
+        } else {
+            return 0;  //To change body of implemented methods use File | Settings | File Templates.
+        }
+
+    }
+
+
+    public String getText() {
+        if (isCharacters()) {
+            return value;
+        } else {
+            return null;
+        }
+    }
+
+
+    public char[] getTextCharacters() {
+        if (isCharacters()) {
+            if (value == null) {
+                return new char[0];
+            } else {
+                return value.toCharArray();
+            }
+        } else {
+            throw new IllegalStateException("This is not a valid state");
+        }
+    }
+
+
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public int getTextStart() {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public int getTextLength() {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getEncoding() {
+        return null;
+    }
+
+
+    public boolean hasText() {
+        if (isCharacters()) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
+    public Location getLocation() {
+        return new Location() {          // Location is unKnown
+
+            public int getLineNumber() {
+                return -1;
+            }
+
+
+            public int getColumnNumber() {
+                return -1;
+            }
+
+
+            public int getCharacterOffset() {
+                return 0;  //To change body of implemented methods use File | Settings | File Templates.
+            }
+
+
+            public String getPublicId() {
+                return null;  //To change body of implemented methods use File | Settings | File Templates.
+            }
+
+
+            public String getSystemId() {
+                return null;  //To change body of implemented methods use File | Settings | File Templates.
+            }
+        };
+    }
+
+
+    public QName getName() {
+        if (isStartElement() || isEndElement()) {
+            return new QName(namespace, localName);
+        } else {
+            throw new IllegalStateException("getName method is valid only for the START_ELEMENT or END_ELEMENT event");
+        }
+
+    }
+
+
+    public String getLocalName() {
+        int i = getEventType();
+        if (i == XMLStreamReader.START_ELEMENT || i == XMLStreamReader.END_ELEMENT) {
+            return localName;
+        } else {
+            throw new IllegalStateException("To get local name state should be START_ELEMENT or END_ELEMENT");
+        }
+    }
+
+
+    public boolean hasName() {
+        return (isStartElement() || isEndElement());
+    }
+
+
+    public String getNamespaceURI() {
+        if (isStartElement() || isEndElement()) {
+            return namespace;
+        } else {
+            return null;
+        }
+    }
+
+
+    public String getPrefix() {
+        return null;
+    }
+
+
+    public String getVersion() {
+        return null;
+    }
+
+
+    public boolean isStandalone() {
+        return false;
+    }
+
+
+    public boolean standaloneSet() {
+        return false;
+    }
+
+
+    public String getCharacterEncodingScheme() {
+        return null;
+    }
+
+
+    public String getPITarget() {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+
+    public String getPIData() {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    private void stateTransition() throws XMLStreamException, IOException {
+        if (state == JsonState.StartState) {
+            beginObject();
+            JsonObject topElement = new JsonObject("StackTopElement", JSONType.NESTED_OBJECT,
+                    null, "http://axis2.apache.org/axis/json");
+            stackObj.push(topElement);
+            readName();
+        } else if (state == JsonState.NameName) {
+            readName();
+        } else if (state == JsonState.NameValue) {
+            readValue();
+        } else if (state == JsonState.ValueEndObject_END_1) {
+            state = JsonState.ValueEndObject_END_2;
+            removeStackObj();
+        } else if (state == JsonState.ValueEndObject_END_2) {
+            readEndObject();
+        } else if (state == JsonState.ValueName_END) {
+            state = JsonState.ValueName_START;
+            removeStackObj();
+        } else if (state == JsonState.ValueName_START) {
+            readName();
+        } else if (state == JsonState.ValueValue_END) {
+            state = JsonState.ValueValue_START;
+        } else if (state == JsonState.ValueValue_START) {
+            value = null;
+            state = JsonState.ValueValue_CHAR;
+        } else if (state == JsonState.ValueValue_CHAR) {
+            readValue();
+        } else if (state == JsonState.ValueEndArray) {
+            readEndArray();
+            removeStackObj();
+        } else if (state == JsonState.EndArrayName) {
+            readName();
+        } else if (state == JsonState.EndObjectEndObject) {
+            readEndObject();
+        } else if (state == JsonState.EndObjectName) {
+            readName();
+        } else if (state == JsonState.EndObjectBeginObject_END) {
+            state = JsonState.EndObjectBeginObject_START;
+            fillMiniStack();
+        } else if (state == JsonState.EndObjectBeginObject_START) {
+            readBeginObject();
+        } else if (state == JsonState.EndArrayEndObject) {
+            readEndObject();
+        }
+
+    }
+
+    private void removeStackObj() throws XMLStreamException {
+        if (!stackObj.empty()) {
+            if (topNestedArrayObj == null) {
+                stackObj.pop();
+            } else {
+                if (stackObj.peek().equals(topNestedArrayObj)) {
+                    topNestedArrayObj = null;
+                    processedJsonObject.clear();
+                    stackObj.pop();
+                } else {
+                    processedJsonObject.push(stackObj.pop());
+                }
+            }
+            if (!stackObj.empty()) {
+                localName = stackObj.peek().getName();
+            } else {
+                localName = "";
+            }
+        } else {
+            System.out.println("stackObj is empty");
+            throw new XMLStreamException("Error while processing input JSON stream, JSON request may not valid ," +
+                    " it may has more end object characters ");
+        }
+    }
+
+    private void fillMiniStack() {
+        miniStack.clear();
+        JsonObject nestedArray = stackObj.peek();
+        while (!processedJsonObject.peek().equals(nestedArray)) {
+            miniStack.push(processedJsonObject.pop());
+        }
+    }
+
+    private void readName() throws IOException, XMLStreamException {
+        nextName();
+        tokenType = jsonReader.peek();
+        if (tokenType == JsonToken.BEGIN_OBJECT) {
+            beginObject();
+            state = JsonState.NameName;
+        } else if (tokenType == JsonToken.BEGIN_ARRAY) {
+            beginArray();
+            tokenType = jsonReader.peek();
+            if (tokenType == JsonToken.BEGIN_OBJECT) {
+                beginObject();
+                state = JsonState.NameName;
+            } else {
+                state = JsonState.NameValue;
+            }
+        } else if (tokenType == JsonToken.STRING || tokenType == JsonToken.NUMBER || tokenType == JsonToken.BOOLEAN
+                || tokenType == JsonToken.NULL) {
+            state = JsonState.NameValue;
+        }
+    }
+
+    private void readValue() throws IOException {
+        nextValue();
+        tokenType = jsonReader.peek();
+        if (tokenType == JsonToken.NAME) {
+            state = JsonState.ValueName_END;
+        } else if (tokenType == JsonToken.STRING || tokenType == JsonToken.NUMBER || tokenType == JsonToken.BOOLEAN
+                || tokenType == JsonToken.NULL) {
+            state = JsonState.ValueValue_END;
+        } else if (tokenType == JsonToken.END_ARRAY) {
+            state = JsonState.ValueEndArray;
+        } else if (tokenType == JsonToken.END_OBJECT) {
+            state = JsonState.ValueEndObject_END_1;
+        }
+    }
+
+    private void readBeginObject() throws IOException, XMLStreamException {
+        beginObject();
+        readName();
+    }
+
+    private void readEndObject() throws IOException, XMLStreamException {
+        endObject();
+        tokenType = jsonReader.peek();
+        if (tokenType == JsonToken.END_OBJECT) {
+            removeStackObj();
+            state = JsonState.EndObjectEndObject;
+        } else if (tokenType == JsonToken.END_ARRAY) {
+            readEndArray();
+            removeStackObj();
+        } else if (tokenType == JsonToken.NAME) {
+            removeStackObj();
+            state = JsonState.EndObjectName;
+        } else if (tokenType == JsonToken.BEGIN_OBJECT) {
+            state = JsonState.EndObjectBeginObject_END;
+        } else if (tokenType == JsonToken.END_DOCUMENT) {
+            removeStackObj();
+            state = JsonState.EndObjectEndDocument;
+        }
+    }
+
+    private void readEndArray() throws IOException {
+        endArray();
+        tokenType = jsonReader.peek();
+        if (tokenType == JsonToken.END_OBJECT) {
+            state = JsonState.EndArrayEndObject;
+        } else if (tokenType == JsonToken.NAME) {
+            state = JsonState.EndArrayName;
+        }
+    }
+
+    private void nextName() throws IOException, XMLStreamException {
+        String name = jsonReader.nextName();
+        if (!miniStack.empty()) {
+            JsonObject jsonObj = miniStack.peek();
+            if (jsonObj.getName().equals(name)) {
+                namespace = jsonObj.getNamespaceUri();
+                stackObj.push(miniStack.pop());
+            } else {
+                throw new XMLStreamException(JsonConstant.IN_JSON_MESSAGE_NOT_VALID + "expected : " + jsonObj.getName() + " but found : " + name);
+            }
+        } else if (!queue.isEmpty()) {
+            JsonObject jsonObj = queue.peek();
+            if (jsonObj.getName().equals(name)) {
+                namespace = jsonObj.getNamespaceUri();
+                stackObj.push(queue.poll());
+            } else {
+                throw new XMLStreamException(JsonConstant.IN_JSON_MESSAGE_NOT_VALID + "expected : " + jsonObj.getName() + " but found : " + name);
+            }
+        } else {
+            throw new XMLStreamException(JsonConstant.IN_JSON_MESSAGE_NOT_VALID);
+        }
+
+        localName = stackObj.peek().getName();
+        value = null;
+    }
+
+    private String nextValue() {
+        try {
+            tokenType = jsonReader.peek();
+
+            if (tokenType == JsonToken.STRING) {
+                value = jsonReader.nextString();
+            } else if (tokenType == JsonToken.BOOLEAN) {
+                value = String.valueOf(jsonReader.nextBoolean());
+            } else if (tokenType == JsonToken.NUMBER) {
+                JsonObject peek = stackObj.peek();
+                String valueType = peek.getValueType();
+                if (valueType.equals("int")) {
+                    value = String.valueOf(jsonReader.nextInt());
+                } else if (valueType.equals("long")) {
+                    value = String.valueOf(jsonReader.nextLong());
+                } else if (valueType.equals("double")) {
+                    value = String.valueOf(jsonReader.nextDouble());
+                } else if (valueType.equals("float")) {
+                    value = String.valueOf(jsonReader.nextDouble());
+                }
+            } else if (tokenType == JsonToken.NULL) {
+                jsonReader.nextNull();
+                value = null;
+            } else {
+                log.error("Couldn't read the value, Illegal state exception");
+                throw new RuntimeException("Couldn't read the value, Illegal state exception");
+            }
+        } catch (IOException e) {
+            log.error("IO error while reading json stream");
+            throw new RuntimeException("IO error while reading json stream");
+        }
+        return value;
+    }
+
+    private void beginObject() throws IOException {
+        jsonReader.beginObject();
+    }
+
+    private void beginArray() throws IOException {
+        jsonReader.beginArray();
+        if (stackObj.peek().getType() == JSONType.NESTED_ARRAY) {
+            if (topNestedArrayObj == null) {
+                topNestedArrayObj = stackObj.peek();
+            }
+            processedJsonObject.push(stackObj.peek());
+        }
+    }
+
+    private void endObject() throws IOException {
+        jsonReader.endObject();
+    }
+
+    private void endArray() throws IOException {
+        jsonReader.endArray();
+        if (stackObj.peek().equals(topNestedArrayObj)) {
+            topNestedArrayObj = null;
+        }
+    }
+
+    public enum JsonState {
+        StartState,
+        NameValue,
+        NameName,
+        ValueValue_END,
+        ValueValue_START,
+        ValueValue_CHAR,
+        ValueEndArray,
+        ValueEndObject_END_1,
+        ValueEndObject_END_2,
+        ValueName_END,
+        ValueName_START,
+        EndObjectEndObject,
+        EndObjectName,
+        EndArrayName,
+        EndArrayEndObject,
+        EndObjectBeginObject_END,
+        EndObjectBeginObject_START,
+        EndObjectEndDocument,
+    }
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,801 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson;
+
+import com.google.gson.stream.JsonWriter;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.json.gson.factory.JSONType;
+import org.apache.axis2.json.gson.factory.JsonConstant;
+import org.apache.axis2.json.gson.factory.JsonObject;
+import org.apache.axis2.json.gson.factory.XmlNode;
+import org.apache.axis2.json.gson.factory.XmlNodeGenerator;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Stack;
+
+
+public class GsonXMLStreamWriter implements XMLStreamWriter {
+
+    private JsonWriter jsonWriter;
+
+    /**
+     * queue is used to keep the outgoing response structure according to the response XMLSchema
+     */
+    private Queue<JsonObject> queue = new LinkedList<JsonObject>();
+
+    /**
+     * This stacks use to process the outgoing response
+     */
+    private Stack<JsonObject> stack = new Stack<JsonObject>();
+    private Stack<JsonObject> miniStack = new Stack<JsonObject>();
+
+    private JsonObject flushObject;
+
+    /**
+     * topNestedArrayObj is use to keep the most top nested array object
+     */
+    private JsonObject topNestedArrayObj;
+
+    /**
+     * processedJsonObject stack is used to keep processed JsonObject for future reference
+     */
+    private Stack<JsonObject> processedJsonObjects = new Stack<JsonObject>();
+
+    private List<XmlSchema> xmlSchemaList;
+
+    /**
+     * Element QName of outgoing message , which is get from the outgoing message context
+     */
+    private QName elementQName;
+
+    /**
+     * Intermediate representation of XmlSchema
+     */
+    private XmlNode mainXmlNode;
+
+    private ConfigurationContext configContext;
+
+    private XmlNodeGenerator xmlNodeGenerator;
+
+    private boolean isProcessed;
+
+    /**
+     * This map is used to keep namespace uri with prefixes
+     */
+    private Map<String, String> uriPrefixMap = new HashMap<String, String>();
+
+
+    public GsonXMLStreamWriter(JsonWriter jsonWriter, QName elementQName, List<XmlSchema> xmlSchemaList,
+                               ConfigurationContext context) {
+        this.jsonWriter = jsonWriter;
+        this.elementQName = elementQName;
+        this.xmlSchemaList = xmlSchemaList;
+        this.configContext = context;
+    }
+
+    private void process() throws IOException {
+        Object ob = configContext.getProperty(JsonConstant.XMLNODES);
+        if (ob != null) {
+            Map<QName, XmlNode> nodeMap = (Map<QName, XmlNode>) ob;
+            XmlNode resNode = nodeMap.get(elementQName);
+            if (resNode != null) {
+                xmlNodeGenerator = new XmlNodeGenerator();
+                queue = xmlNodeGenerator.getQueue(resNode);
+            } else {
+                xmlNodeGenerator = new XmlNodeGenerator(xmlSchemaList, elementQName);
+                mainXmlNode = xmlNodeGenerator.getMainXmlNode();
+                queue = xmlNodeGenerator.getQueue(mainXmlNode);
+                nodeMap.put(elementQName, mainXmlNode);
+                configContext.setProperty(JsonConstant.XMLNODES, nodeMap);
+            }
+        } else {
+            Map<QName, XmlNode> newNodeMap = new HashMap<QName, XmlNode>();
+            xmlNodeGenerator = new XmlNodeGenerator(xmlSchemaList, elementQName);
+            mainXmlNode = xmlNodeGenerator.getMainXmlNode();
+            queue = xmlNodeGenerator.getQueue(mainXmlNode);
+            newNodeMap.put(elementQName, mainXmlNode);
+            configContext.setProperty(JsonConstant.XMLNODES, newNodeMap);
+        }
+        isProcessed = true;
+        this.jsonWriter.beginObject();
+    }
+
+
+    private void writeStartJson(JsonObject jsonObject) throws IOException {
+
+        if (jsonObject.getType() == JSONType.OBJECT) {
+            jsonWriter.name(jsonObject.getName());
+        } else if (jsonObject.getType() == JSONType.ARRAY) {
+            jsonWriter.name(jsonObject.getName());
+            jsonWriter.beginArray();
+
+        } else if (jsonObject.getType() == JSONType.NESTED_ARRAY) {
+            jsonWriter.name(jsonObject.getName());
+            jsonWriter.beginArray();
+            jsonWriter.beginObject();
+            if (topNestedArrayObj == null) {
+                topNestedArrayObj = jsonObject;
+                processedJsonObjects.push(jsonObject);
+            }
+        } else if (jsonObject.getType() == JSONType.NESTED_OBJECT) {
+            jsonWriter.name(jsonObject.getName());
+            jsonWriter.beginObject();
+
+        }
+
+    }
+
+    private void writeEndJson(JsonObject endJson) throws IOException {
+        if (endJson.getType() == JSONType.OBJECT) {
+            // nothing write to json writer
+        } else if (endJson.getType() == JSONType.ARRAY) {
+            jsonWriter.endArray();
+        } else if (endJson.getType() == JSONType.NESTED_ARRAY) {
+            jsonWriter.endArray();
+        } else if (endJson.getType() == JSONType.NESTED_OBJECT) {
+            jsonWriter.endObject();
+        }
+
+    }
+
+
+    private JsonObject popStack() {
+        if (topNestedArrayObj == null || stack.peek().getType() == JSONType.NESTED_OBJECT
+                || stack.peek().getType() == JSONType.NESTED_ARRAY) {
+            return stack.pop();
+        } else {
+            processedJsonObjects.push(stack.peek());
+            return stack.pop();
+        }
+    }
+
+    private void fillMiniStack(JsonObject nestedJsonObject) {
+
+        while (!processedJsonObjects.peek().getName().equals(nestedJsonObject.getName())) {
+            miniStack.push(processedJsonObjects.pop());
+        }
+        processedJsonObjects.pop();
+    }
+
+
+    /**
+     * Writes a start tag to the output.  All writeStartElement methods
+     * open a new scope in the internal namespace context.  Writing the
+     * corresponding EndElement causes the scope to be closed.
+     *
+     * @param localName local name of the tag, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeStartElement(String localName) throws XMLStreamException {
+        if (!isProcessed) {
+            try {
+                process();
+            } catch (IOException e) {
+                throw new XMLStreamException("Error occours while write first begin object ");
+            }
+        }
+        JsonObject stackObj = null;
+        try {
+            if (miniStack.isEmpty()) {
+                if (!queue.isEmpty()) {
+                    JsonObject queObj = queue.peek();
+                    if (queObj.getName().equals(localName)) {
+                        if (flushObject != null) {
+                            if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY
+                                    && flushObject.getName().equals(topNestedArrayObj.getName())) {
+                                topNestedArrayObj = null;
+                                processedJsonObjects.clear();
+                            }
+                            popStack();
+                            writeEndJson(flushObject);
+                            flushObject = null;
+                        }
+
+                        if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_ARRAY ||
+                                queObj.getType() == JSONType.NESTED_OBJECT)) {
+                            processedJsonObjects.push(queObj);
+                        }
+                        writeStartJson(queObj);
+                        stack.push(queue.poll());
+                    } else if (!stack.isEmpty()) {
+                        stackObj = stack.peek();
+                        if (stackObj.getName().equals(localName)) {
+                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
+                                fillMiniStack(stackObj);
+                                jsonWriter.beginObject();
+                                processedJsonObjects.push(stackObj);
+                            }
+                            flushObject = null;
+                        } else {
+                            throw new XMLStreamException("Invalid Staring element");
+                        }
+                    }
+                } else {
+                    if (!stack.isEmpty()) {
+                        stackObj = stack.peek();
+                        if (stackObj.getName().equals(localName)) {
+                            flushObject = null;
+                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
+                                fillMiniStack(stackObj);
+                                jsonWriter.beginObject();
+                                processedJsonObjects.push(stackObj);
+                            }
+                        } else {
+                            throw new XMLStreamException("Invalid Staring element");
+                        }
+                    } else {
+                        throw new XMLStreamException("Invalid Starting  element");
+                    }
+                }
+            } else {
+                JsonObject queObj = miniStack.peek();
+                if (queObj.getName().equals(localName)) {
+                    if (flushObject != null) {
+                        popStack();
+                        writeEndJson(flushObject);
+                        flushObject = null;
+                    }
+                    if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_OBJECT
+                            || queObj.getType() == JSONType.NESTED_ARRAY)) {
+                        processedJsonObjects.push(queObj);
+                    }
+                    writeStartJson(queObj);
+                    stack.push(miniStack.pop());
+                } else if (!stack.isEmpty()) {
+                    stackObj = stack.peek();
+                    if (stackObj.getName().equals(localName)) {
+                        flushObject = null;
+                        if (stackObj.getType() == JSONType.NESTED_ARRAY) {
+                            fillMiniStack(stackObj);
+                            jsonWriter.beginObject();
+                            processedJsonObjects.push(stackObj);
+                        }
+                    } else {
+                        throw new XMLStreamException("Invalid Staring element");
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new XMLStreamException(" Json Writer throw an error");
+        }
+    }
+
+    /**
+     * Writes a start tag to the output
+     *
+     * @param namespaceURI the namespaceURI of the prefix to use, may not be null
+     * @param localName    local name of the tag, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *          if the namespace URI has not been bound to a prefix and
+     *          javax.xml.stream.isRepairingNamespaces has not been set to true
+     */
+
+    public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
+        writeStartElement(localName);
+    }
+
+    /**
+     * Writes a start tag to the output
+     *
+     * @param localName    local name of the tag, may not be null
+     * @param prefix       the prefix of the tag, may not be null
+     * @param namespaceURI the uri to bind the prefix to, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+        writeStartElement(localName);
+    }
+
+    /**
+     * Writes an empty element tag to the output
+     *
+     * @param namespaceURI the uri to bind the tag to, may not be null
+     * @param localName    local name of the tag, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *          if the namespace URI has not been bound to a prefix and
+     *          javax.xml.stream.isRepairingNamespaces has not been set to true
+     */
+
+    public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes an empty element tag to the output
+     *
+     * @param prefix       the prefix of the tag, may not be null
+     * @param localName    local name of the tag, may not be null
+     * @param namespaceURI the uri to bind the tag to, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes an empty element tag to the output
+     *
+     * @param localName local name of the tag, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeEmptyElement(String localName) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes an end tag to the output relying on the internal
+     * state of the writer to determine the prefix and local name
+     * of the event.
+     *
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeEndElement() throws XMLStreamException {
+        if (!isProcessed) {
+            try {
+                process();
+            } catch (IOException e) {
+                throw new XMLStreamException("Error occours while write first begin object ");
+            }
+        }
+        JsonObject stackObj = null;
+        try {
+            if (flushObject != null) {
+                if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY &&
+                        flushObject.equals(topNestedArrayObj.getName())) {
+                    topNestedArrayObj = null;
+                    processedJsonObjects.clear();
+                }
+                popStack();
+                writeEndJson(flushObject);
+                flushObject = null;
+                writeEndElement();
+            } else {
+                if (stack.peek().getType() == JSONType.ARRAY) {
+                    flushObject = stack.peek();
+                } else if (stack.peek().getType() == JSONType.NESTED_ARRAY) {
+                    flushObject = stack.peek();
+                    jsonWriter.endObject();
+                } else {
+                    stackObj = popStack();
+                    writeEndJson(stackObj);
+                }
+            }
+        } catch (IOException e) {
+            throw new XMLStreamException("Json writer throw an exception");
+        }
+    }
+
+    /**
+     * Closes any start tags and writes corresponding end tags.
+     *
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeEndDocument() throws XMLStreamException {
+        if (!isProcessed) {
+            try {
+                process();
+            } catch (IOException e) {
+                throw new XMLStreamException("Error occours while write first begin object ");
+            }
+        }
+        if (queue.isEmpty() && stack.isEmpty()) {
+            try {
+                if (flushObject != null) {
+                    writeEndJson(flushObject);
+                }
+                jsonWriter.endObject();
+                jsonWriter.flush();
+                jsonWriter.close();
+            } catch (IOException e) {
+                throw new XMLStreamException("JsonWriter threw an exception", e);
+            }
+        } else {
+            throw new XMLStreamException("Invalid xml element");
+        }
+    }
+
+    /**
+     * Close this writer and free any resources associated with the
+     * writer.  This must not close the underlying output stream.
+     *
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void close() throws XMLStreamException {
+        try {
+            jsonWriter.close();
+        } catch (IOException e) {
+            throw new RuntimeException("Error occur while closing JsonWriter");
+        }
+    }
+
+    /**
+     * Write any cached data to the underlying output mechanism.
+     *
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+    
+    public void flush() throws XMLStreamException {
+    }
+
+    /**
+     * Writes an attribute to the output stream without
+     * a prefix.
+     *
+     * @param localName the local name of the attribute
+     * @param value     the value of the attribute
+     * @throws IllegalStateException if the current state does not allow Attribute writing
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeAttribute(String localName, String value) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes an attribute to the output stream
+     *
+     * @param prefix       the prefix for this attribute
+     * @param namespaceURI the uri of the prefix for this attribute
+     * @param localName    the local name of the attribute
+     * @param value        the value of the attribute
+     * @throws IllegalStateException if the current state does not allow Attribute writing
+     * @throws javax.xml.stream.XMLStreamException
+     *                               if the namespace URI has not been bound to a prefix and
+     *                               javax.xml.stream.isRepairingNamespaces has not been set to true
+     */
+
+    public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
+        // GsonXMLStreamReader doesn't write Attributes
+    }
+
+    /**
+     * Writes an attribute to the output stream
+     *
+     * @param namespaceURI the uri of the prefix for this attribute
+     * @param localName    the local name of the attribute
+     * @param value        the value of the attribute
+     * @throws IllegalStateException if the current state does not allow Attribute writing
+     * @throws javax.xml.stream.XMLStreamException
+     *                               if the namespace URI has not been bound to a prefix and
+     *                               javax.xml.stream.isRepairingNamespaces has not been set to true
+     */
+
+    public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes a namespace to the output stream
+     * If the prefix argument to this method is the empty string,
+     * "xmlns", or null this method will delegate to writeDefaultNamespace
+     *
+     * @param prefix       the prefix to bind this namespace to
+     * @param namespaceURI the uri to bind the prefix to
+     * @throws IllegalStateException if the current state does not allow Namespace writing
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
+    }
+
+    /**
+     * Writes the default namespace to the stream
+     *
+     * @param namespaceURI the uri to bind the default namespace to
+     * @throws IllegalStateException if the current state does not allow Namespace writing
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
+        // do nothing
+    }
+
+    /**
+     * Writes an xml comment with the data enclosed
+     *
+     * @param data the data contained in the comment, may be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeComment(String data) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes a processing instruction
+     *
+     * @param target the target of the processing instruction, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeProcessingInstruction(String target) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes a processing instruction
+     *
+     * @param target the target of the processing instruction, may not be null
+     * @param data   the data contained in the processing instruction, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes a CData section
+     *
+     * @param data the data contained in the CData Section, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeCData(String data) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Write a DTD section.  This string represents the entire doctypedecl production
+     * from the XML 1.0 specification.
+     *
+     * @param dtd the DTD to be written
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeDTD(String dtd) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Writes an entity reference
+     *
+     * @param name the name of the entity
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeEntityRef(String name) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Write the XML Declaration. Defaults the XML version to 1.0, and the encoding to utf-8
+     *
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeStartDocument() throws XMLStreamException {
+        if (!isProcessed) {
+            try {
+                process();
+            } catch (IOException e) {
+                throw new XMLStreamException("Error occur while write first begin object ");
+            }
+        }
+    }
+
+    /**
+     * Write the XML Declaration. Defaults the XML version to 1.0
+     *
+     * @param version version of the xml document
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeStartDocument(String version) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Write the XML Declaration.  Note that the encoding parameter does
+     * not set the actual encoding of the underlying output.  That must
+     * be set when the instance of the XMLStreamWriter is created using the
+     * XMLOutputFactory
+     *
+     * @param encoding encoding of the xml declaration
+     * @param version  version of the xml document
+     * @throws javax.xml.stream.XMLStreamException
+     *          If given encoding does not match encoding
+     *          of the underlying stream
+     */
+
+    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
+        if (!isProcessed) {
+            xmlNodeGenerator.getMainXmlNode();
+            queue = xmlNodeGenerator.getQueue(mainXmlNode);
+            isProcessed = true;
+        }
+    }
+
+    /**
+     * Write text to the output
+     *
+     * @param text the value to write
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeCharacters(String text) throws XMLStreamException {
+        if (!isProcessed) {
+            try {
+                process();
+            } catch (IOException e) {
+                throw new XMLStreamException("Error occur while trying to write first begin object ");
+            }
+        }
+        try {
+            JsonObject peek = stack.peek();
+            String valueType = peek.getValueType();
+            if (valueType.equals("string")) {
+                jsonWriter.value(text);
+            } else if (valueType.equals("int")) {
+                Number num = new Integer(text);
+                jsonWriter.value(num);
+            } else if (valueType.equals("long")) {
+                jsonWriter.value(Long.valueOf(text));
+            } else if (valueType.equals("double")) {
+                jsonWriter.value(Double.valueOf(text));
+            } else if (valueType.equals("boolean")) {
+                jsonWriter.value(Boolean.valueOf(text));
+            } else {
+                jsonWriter.value(text);
+            }
+        } catch (IOException e) {
+            throw new XMLStreamException("JsonWriter throw an exception");
+        }
+    }
+
+    /**
+     * Write text to the output
+     *
+     * @param text  the value to write
+     * @param start the starting position in the array
+     * @param len   the number of characters to write
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Gets the prefix the uri is bound to
+     *
+     * @return the prefix or null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public String getPrefix(String uri) throws XMLStreamException {
+        return uriPrefixMap.get(uri);
+    }
+
+    /**
+     * Sets the prefix the uri is bound to.  This prefix is bound
+     * in the scope of the current START_ELEMENT / END_ELEMENT pair.
+     * If this method is called before a START_ELEMENT has been written
+     * the prefix is bound in the root scope.
+     *
+     * @param prefix the prefix to bind to the uri, may not be null
+     * @param uri    the uri to bind to the prefix, may be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void setPrefix(String prefix, String uri) throws XMLStreamException {
+        uriPrefixMap.put(uri, prefix);
+    }
+
+    /**
+     * Binds a URI to the default namespace
+     * This URI is bound
+     * in the scope of the current START_ELEMENT / END_ELEMENT pair.
+     * If this method is called before a START_ELEMENT has been written
+     * the uri is bound in the root scope.
+     *
+     * @param uri the uri to bind to the default namespace, may be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void setDefaultNamespace(String uri) throws XMLStreamException {
+        //do nothing. 
+    }
+
+    /**
+     * Sets the current namespace context for prefix and uri bindings.
+     * This context becomes the root namespace context for writing and
+     * will replace the current root namespace context.  Subsequent calls
+     * to setPrefix and setDefaultNamespace will bind namespaces using
+     * the context passed to the method as the root context for resolving
+     * namespaces.  This method may only be called once at the start of
+     * the document.  It does not cause the namespaces to be declared.
+     * If a namespace URI to prefix mapping is found in the namespace
+     * context it is treated as declared and the prefix may be used
+     * by the StreamWriter.
+     *
+     * @param context the namespace context to use for this writer, may not be null
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+
+    public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
+        throw new UnsupportedOperationException("Method is not implemented");
+    }
+
+    /**
+     * Returns the current namespace context.
+     *
+     * @return the current NamespaceContext
+     */
+
+    public NamespaceContext getNamespaceContext() {
+        return new GsonNamespaceConext();
+    }
+
+    /**
+     * Get the value of a feature/property from the underlying implementation
+     *
+     * @param name The name of the property, may not be null
+     * @return The value of the property
+     * @throws IllegalArgumentException if the property is not supported
+     * @throws NullPointerException     if the name is null
+     */
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return null;
+    }
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver;
+import org.apache.axis2.json.gson.factory.JsonConstant;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+
+
+public class JSONMessageHandler extends AbstractHandler {
+    /**
+     * This method will be called on each registered handler when a message
+     * needs to be processed.  If the message processing is paused by the
+     * handler, then this method will be called again for the handler that
+     * paused the processing once it is resumed.
+     * <p/>
+     * This method may be called concurrently from multiple threads.
+     * <p/>
+     * Handlers that want to determine the type of message that is to be
+     * processed (e.g. response vs request, inbound vs. outbound, etc.) can
+     * retrieve that information from the MessageContext via
+     * MessageContext.getFLOW() and
+     * MessageContext.getAxisOperation().getMessageExchangePattern() APIs.
+     *
+     * @param msgContext the <code>MessageContext</code> to process with this
+     *                   <code>Handler</code>.
+     * @return An InvocationResponse that indicates what
+     *         the next step in the message processing should be.
+     * @throws org.apache.axis2.AxisFault if the handler encounters an error
+     */
+
+    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+        MessageReceiver messageReceiver = msgContext.getAxisOperation().getMessageReceiver();
+        if (messageReceiver instanceof JsonRpcMessageReceiver) {
+            // do not need to parse XMLSchema list, as  this message receiver will not use GsonXMLStreamReader  to read the inputStream.
+        } else {
+            Object tempObj = msgContext.getProperty(JsonConstant.IS_JSON_STREAM);
+            if (tempObj != null) {
+                boolean isJSON = Boolean.valueOf(tempObj.toString());
+                Object o = msgContext.getProperty(JsonConstant.GSON_XML_STREAM_READER);
+                if (o != null) {
+                    GsonXMLStreamReader gsonXMLStreamReader = (GsonXMLStreamReader) o;
+                    QName elementQname = msgContext.getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE).getElementQName();
+                    List<XmlSchema> schemas = msgContext.getAxisService().getSchema();
+                    gsonXMLStreamReader.initXmlStreamReader(elementQname, schemas, msgContext.getConfigurationContext());
+                    StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(gsonXMLStreamReader);
+                    OMElement omElement = stAXOMBuilder.getDocumentElement();
+                    msgContext.getEnvelope().getBody().addChild(omElement);
+                } else {
+                    throw new AxisFault("GsonXMLStreamReader should not be null");
+                }
+            } else {
+                // request is not a JSON request so don't need to initialize GsonXMLStreamReader
+            }
+        }
+        return InvocationResponse.CONTINUE;
+    }
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonBuilder.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonBuilder.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonBuilder.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonBuilder.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson;
+
+import com.google.gson.stream.JsonReader;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.builder.Builder;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.json.gson.factory.JsonConstant;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
+public class JsonBuilder implements Builder {
+    public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext) throws AxisFault {
+        messageContext.setProperty(JsonConstant.IS_JSON_STREAM , true);
+        JsonReader jsonReader = null;
+        String charSetEncoding=null;
+           try {
+               charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+               jsonReader = new JsonReader(new InputStreamReader(inputStream , charSetEncoding));
+               GsonXMLStreamReader gsonXMLStreamReader = new GsonXMLStreamReader(jsonReader);
+               messageContext.setProperty(JsonConstant.GSON_XML_STREAM_READER , gsonXMLStreamReader);
+               // dummy envelop
+               SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
+               SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
+               return soapEnvelope;
+           } catch (UnsupportedEncodingException e) {
+               throw new AxisFault(charSetEncoding + " encoding is may not supported by json inputStream ", e);
+           } catch (IOException e) {
+               throw new AxisFault("IOException while processing JsonReader ", e);
+           }
+    }
+
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonFormatter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonFormatter.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonFormatter.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JsonFormatter.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson;
+
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonWriter;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.json.gson.factory.JsonConstant;
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Type;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+
+public class JsonFormatter implements MessageFormatter {
+    private static final Log log = LogFactory.getLog(JsonFormatter.class);
+
+    public byte[] getBytes(MessageContext messageContext, OMOutputFormat omOutputFormat) throws AxisFault {
+        return new byte[0];
+    }
+
+    public void writeTo(MessageContext outMsgCtxt, OMOutputFormat omOutputFormat, OutputStream outputStream, boolean b) throws AxisFault {
+        String charSetEncoding = (String) outMsgCtxt.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+        JsonWriter jsonWriter = null;
+        String msg;
+
+        try {
+            jsonWriter = new JsonWriter(new OutputStreamWriter(outputStream, charSetEncoding));
+            Object retObj = outMsgCtxt.getProperty(JsonConstant.RETURN_OBJECT);
+
+            if (outMsgCtxt.isProcessingFault()) {
+                OMElement element = outMsgCtxt.getEnvelope().getBody().getFirstElement();
+                try {
+                    jsonWriter.beginObject();
+                    jsonWriter.name(element.getLocalName());
+                    jsonWriter.beginObject();
+                    Iterator childrenIterator = element.getChildElements();
+                    while (childrenIterator.hasNext()) {
+                        Object next = childrenIterator.next();
+                        OMElement omElement = (OMElement) next;
+                        jsonWriter.name(omElement.getLocalName());
+                        jsonWriter.value(omElement.getText());
+                    }
+                    jsonWriter.endObject();
+                    jsonWriter.endObject();
+                    jsonWriter.flush();
+                    jsonWriter.close();
+                } catch (IOException e) {
+                    throw new AxisFault("Error while processing fault code in JsonWriter");
+                }
+
+            } else if (retObj == null) {
+                OMElement element = outMsgCtxt.getEnvelope().getBody().getFirstElement();
+                QName elementQname = outMsgCtxt.getAxisOperation().getMessage
+                        (WSDLConstants.MESSAGE_LABEL_OUT_VALUE).getElementQName();
+
+                ArrayList<XmlSchema> schemas = outMsgCtxt.getAxisService().getSchema();
+                GsonXMLStreamWriter xmlsw = new GsonXMLStreamWriter(jsonWriter,
+                                                                    elementQname,
+                                                                    schemas,
+                                                                    outMsgCtxt.getConfigurationContext());
+                try {
+                    xmlsw.writeStartDocument();
+                    if (b) {
+                        element.serialize(xmlsw);
+                    } else {
+                        element.serializeAndConsume(xmlsw);
+                    }
+                    xmlsw.writeEndDocument();
+                } catch (XMLStreamException e) {
+                    throw new AxisFault("Error while writing to the output stream using JsonWriter", e);
+                }
+
+            } else {
+                try {
+                    Gson gson = new Gson();
+                    jsonWriter.beginObject();
+                    jsonWriter.name(JsonConstant.RESPONSE);
+                    Type returnType = (Type) outMsgCtxt.getProperty(JsonConstant.RETURN_TYPE);
+                    gson.toJson(retObj, returnType, jsonWriter);
+                    jsonWriter.endObject();
+                    jsonWriter.flush();
+
+                } catch (IOException e) {
+                    msg = "Exception occur while writting to JsonWriter at the JsonFormatter ";
+                    log.error(msg, e);
+                    throw AxisFault.makeFault(e);
+                }
+            }
+        } catch (UnsupportedEncodingException e) {
+            msg = "Exception occur when try to encode output stream usig  " +
+                    Constants.Configuration.CHARACTER_SET_ENCODING + " charset";
+            log.error(msg, e);
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    public String getContentType(MessageContext outMsgCtxt, OMOutputFormat omOutputFormat, String s) {
+        String contentType = (String)outMsgCtxt.getProperty(Constants.Configuration.CONTENT_TYPE);
+        return contentType;
+    }
+
+    public URL getTargetAddress(MessageContext messageContext, OMOutputFormat omOutputFormat, URL url) throws AxisFault {
+        return null;
+    }
+
+    public String formatSOAPAction(MessageContext messageContext, OMOutputFormat omOutputFormat, String s) {
+        return null;
+    }
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JSONType.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JSONType.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JSONType.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JSONType.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson.factory;
+
+public enum JSONType {
+    ARRAY,
+    NESTED_ARRAY,
+    NESTED_OBJECT,
+    OBJECT,
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonConstant.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonConstant.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonConstant.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonConstant.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson.factory;
+
+
+public class JsonConstant {
+
+
+    public static final String RESPONSE = "response";
+
+    public static final String RETURN_OBJECT = "returnObject";
+    public static final String RETURN_TYPE = "returnType";
+
+    public static final String IS_JSON_STREAM = "isJsonStream";
+
+    public static final String GSON_XML_STREAM_READER = "GsonXMLStreamReader";
+
+    public static final String XMLNODES = "xmlnodes";
+
+
+//    error messages
+
+    public static final String IN_JSON_MESSAGE_NOT_VALID = "Input JSON message is not valid ";
+
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonObject.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonObject.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonObject.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonObject.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson.factory;
+
+
+public class JsonObject {
+    private String name;
+    private JSONType type;
+    private String valueType;
+    private String namespaceUri;
+
+    public JsonObject(String name, JSONType type, String valueType , String namespaceUri) {
+        this.name = name;
+        this.type = type;
+        this.valueType = valueType;
+        this.namespaceUri = namespaceUri;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public JSONType getType() {
+        return type;
+    }
+
+    public String getValueType() {
+        return valueType;
+    }
+
+    public String getNamespaceUri() {
+        return namespaceUri;
+    }
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonUtils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonUtils.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonUtils.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonUtils.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson.factory;
+
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+
+public class JsonUtils {
+
+    public static Object invokeServiceClass(JsonReader jsonReader,
+                                            Object service,
+                                            Method operation ,
+                                            Class[] paramClasses ,
+                                            int paramCount ) throws InvocationTargetException,
+            IllegalAccessException, IOException  {
+
+        Object[] methodParam = new Object[paramCount];
+        Gson gson = new Gson();
+        String[] argNames = new String[paramCount];
+
+        if( ! jsonReader.isLenient()){
+            jsonReader.setLenient(true);
+        }
+        jsonReader.beginObject();
+        String messageName=jsonReader.nextName();     // get message name from input json stream
+        jsonReader.beginArray();
+
+        int i = 0;
+        for (Class paramType : paramClasses) {
+            jsonReader.beginObject();
+            argNames[i] = jsonReader.nextName();
+            methodParam[i] = gson.fromJson(jsonReader, paramType);   // gson handle all types well and return an object from it
+            jsonReader.endObject();
+            i++;
+        }
+
+        jsonReader.endArray();
+        jsonReader.endObject();
+
+        return  operation.invoke(service, methodParam);
+
+    }
+
+    public static Method getOpMethod(String methodName, Method[] methodSet) {
+        for (Method method : methodSet) {
+            String mName = method.getName();
+            if (mName.equals(methodName)) {
+                return method;
+            }
+        }
+        return null;
+    }
+
+}

Added: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/XmlNode.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/XmlNode.java?rev=1381640&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/XmlNode.java (added)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/XmlNode.java Thu Sep  6 15:24:44 2012
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.gson.factory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class XmlNode {
+
+    private String name;
+    private boolean isAttribute;
+    private boolean isArray;
+    private List<XmlNode> childrenList = new ArrayList<XmlNode>();
+    private String valueType;
+    private String namespaceUri;
+
+    public XmlNode(String name,String namespaceUri, boolean attribute, boolean array , String valueType) {
+        this.name = name;
+        this.namespaceUri = namespaceUri;
+        isAttribute = attribute;
+        isArray = array;
+        this.valueType = valueType;
+    }
+
+
+    public void addChildtoList(XmlNode child) {
+        childrenList.add(child);
+    }
+
+
+    public String getName() {
+        return name;
+    }
+
+    public boolean isAttribute() {
+        return isAttribute;
+    }
+
+    public boolean isArray() {
+        return isArray;
+    }
+
+    public List<XmlNode> getChildrenList() {
+        return childrenList;
+    }
+
+    public String getValueType() {
+        return valueType;
+    }
+
+    public String getNamespaceUri() {
+        return namespaceUri;
+    }
+}