You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2005/03/17 09:20:00 UTC

svn commit: r157915 - in webservices/axis/trunk/archive/java/scratch/Ajith/src: ./ java/ java/org/ java/org/apache/ java/org/apache/axis/ java/org/apache/axis/om/ java/org/apache/axis/om/builder/ java/org/apache/axis/om/builder/impl/ test/ test/org/ test/org/apache/ test/org/apache/axis/ test/org/apache/axis/om/ test/org/apache/axis/om/builder/

Author: ajith
Date: Thu Mar 17 00:19:55 2005
New Revision: 157915

URL: http://svn.apache.org/viewcvs?view=rev&rev=157915
Log:
Adding the builder extensions proto

Added:
    webservices/axis/trunk/archive/java/scratch/Ajith/src/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/BuilderExtension.java
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtendedBuilder.java
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtensionRegistry.java
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/EnvelopeBuilderExtension.java
    webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/HeaderBuilderExtension.java
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/builder/
    webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/builder/ExtendedBuilderTest.java

Added: webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/BuilderExtension.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/BuilderExtension.java?view=auto&rev=157915
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/BuilderExtension.java (added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/BuilderExtension.java Thu Mar 17 00:19:55 2005
@@ -0,0 +1,27 @@
+package org.apache.axis.om.builder;
+
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMElement;
+
+import javax.xml.stream.XMLStreamReader;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public interface BuilderExtension {
+    public OMNode buildExtensibleElement(XMLStreamReader pullParser,OMNode parent);
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtendedBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtendedBuilder.java?view=auto&rev=157915
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtendedBuilder.java (added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtendedBuilder.java Thu Mar 17 00:19:55 2005
@@ -0,0 +1,119 @@
+package org.apache.axis.om.builder;
+
+import org.apache.axis.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis.om.impl.llom.OMDocument;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMElement;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamConstants;
+import java.util.List;
+
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+*/
+public class ExtendedBuilder extends StAXOMBuilder{
+
+    public ExtendedBuilder(OMFactory omFactory, XMLStreamReader xmlStreamReader) {
+        super(omFactory, xmlStreamReader);
+    }
+
+    public ExtendedBuilder(XMLStreamReader xmlStreamReader) {
+        super(xmlStreamReader);
+    }
+
+    public int next() throws OMException {
+        ExtensionRegistry registry = ExtensionRegistry.getInstance();
+        OMNode node = null;
+
+        try {
+            if (done) {
+                throw new OMException();
+            }
+            int token = parser.next();
+            if (!cache) {
+                return token;
+            }
+
+            if (!registry.isEmpty()){
+                BuilderExtension[] extensions = registry.getExtensions();
+                for (int i = 0; i < extensions.length; i++) {
+                    node = extensions[i].buildExtensibleElement(this.parser,this.lastNode);
+                    if (node!=null){
+                        break;
+                    }
+                }
+            }
+
+            if (node==null){
+                generateNextNode(token);
+            }else{
+                if (lastNode==null){
+                    //first element
+                    document.setRootElement((OMElement)node);
+                }
+                lastNode = node;
+            }
+
+            return token;
+
+        } catch (OMException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new OMException(e);
+        }
+
+
+    }
+
+    private void generateNextNode (int token){
+
+        switch (token) {
+            case XMLStreamConstants.START_ELEMENT:
+                lastNode = createOMElement();
+                break;
+            case XMLStreamConstants.START_DOCUMENT:
+                document = new OMDocument(this);
+                break;
+            case XMLStreamConstants.CHARACTERS:
+                lastNode = createOMText();
+                break;
+            case XMLStreamConstants.END_ELEMENT:
+                if (lastNode.isComplete()) {
+                    OMElement parent = lastNode.getParent();
+                    parent.setComplete(true);
+                    lastNode = parent;
+                } else {
+                    OMElement e = (OMElement) lastNode;
+                    e.setComplete(true);
+                }
+                break;
+            case XMLStreamConstants.END_DOCUMENT:
+                done = true;
+                break;
+            case XMLStreamConstants.SPACE:
+                next();
+                break;
+            default :
+                throw new OMException();
+        }
+
+
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtensionRegistry.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtensionRegistry.java?view=auto&rev=157915
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtensionRegistry.java (added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/ExtensionRegistry.java Thu Mar 17 00:19:55 2005
@@ -0,0 +1,59 @@
+package org.apache.axis.om.builder;
+
+import java.util.ArrayList;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public class ExtensionRegistry {
+    private ArrayList list;
+
+    private static ExtensionRegistry instance = null;
+
+    public static ExtensionRegistry getInstance(){
+        if (instance==null)
+            instance = new ExtensionRegistry();
+        return instance;
+    }
+
+    private ExtensionRegistry() {
+        this.list = new ArrayList();
+    }
+
+   public void registerExtension(BuilderExtension extension){
+       this.list.add(extension);
+   }
+
+    public void clearExtensions(){
+        this.list.clear();
+    }
+   public BuilderExtension[] getExtensions(){
+
+       if (list.isEmpty()) return null;
+       BuilderExtension[] returnArray = new BuilderExtension[list.size()];
+       for (int i = 0; i < returnArray.length; i++) {
+          returnArray[i]=(BuilderExtension)list.get(i);
+
+       }
+
+       return returnArray;
+   }
+
+    public boolean isEmpty(){
+        return this.list.isEmpty();
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/EnvelopeBuilderExtension.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/EnvelopeBuilderExtension.java?view=auto&rev=157915
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/EnvelopeBuilderExtension.java (added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/EnvelopeBuilderExtension.java Thu Mar 17 00:19:55 2005
@@ -0,0 +1,41 @@
+package org.apache.axis.om.builder.impl;
+
+import org.apache.axis.om.builder.BuilderExtension;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMElement;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamConstants;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public class EnvelopeBuilderExtension implements BuilderExtension{
+    private OMFactory omFactory = OMFactory.newInstance();
+    public OMNode buildExtensibleElement(XMLStreamReader pullParser,OMNode parent) {
+       if (pullParser.getEventType()==XMLStreamConstants.START_ELEMENT &&
+               pullParser.getLocalName().equals("Envelope")){
+
+           return omFactory.createSOAPEnvelope(
+                     omFactory.createOMNamespace(pullParser.getNamespaceURI(),
+                             pullParser.getPrefix())
+                   );
+       }
+       return null;
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/HeaderBuilderExtension.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/HeaderBuilderExtension.java?view=auto&rev=157915
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/HeaderBuilderExtension.java (added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/src/java/org/apache/axis/om/builder/impl/HeaderBuilderExtension.java Thu Mar 17 00:19:55 2005
@@ -0,0 +1,40 @@
+package org.apache.axis.om.builder.impl;
+
+import org.apache.axis.om.builder.BuilderExtension;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.SOAPEnvelope;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamConstants;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public class HeaderBuilderExtension implements BuilderExtension{
+     private OMFactory omFactory = OMFactory.newInstance();
+    public OMNode buildExtensibleElement(XMLStreamReader pullParser,OMNode parent) {
+       if (pullParser.getEventType()==XMLStreamConstants.START_ELEMENT &&
+               pullParser.getLocalName().equals("Header")){
+
+           return omFactory.createSOAPHeader((SOAPEnvelope)parent                    
+                   );
+       }
+       return null;
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/builder/ExtendedBuilderTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/builder/ExtendedBuilderTest.java?view=auto&rev=157915
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/builder/ExtendedBuilderTest.java (added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/src/test/org/apache/axis/om/builder/ExtendedBuilderTest.java Thu Mar 17 00:19:55 2005
@@ -0,0 +1,81 @@
+package org.apache.axis.om.builder;
+
+import junit.framework.TestCase;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayInputStream;
+
+import org.apache.axis.om.OMXMLParserWrapper;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.SOAPEnvelope;
+import org.apache.axis.om.builder.impl.EnvelopeBuilderExtension;
+import org.apache.axis.om.impl.llom.factory.OMXMLBuilderFactory;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public class ExtendedBuilderTest extends TestCase{
+     private String XMLText = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
+             "                  xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
+             "                  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+             "                  xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\">\n" +
+             "    <soapenv:Header>\n" +
+             "        <wsa:MessageID soapenv:mustUnderstand=\"0\">\n" +
+             "            uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>\n" +
+             "        <wsa:To soapenv:mustUnderstand=\"0\">\n" +
+             "            http://localhost:8081/axis/services/BankPort</wsa:To>\n" +
+             "        <wsa:From soapenv:mustUnderstand=\"0\">\n" +
+             "            <Address xmlns=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\">\n" +
+             "                http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous\n" +
+             "            </Address>\n" +
+             "        </wsa:From>\n" +
+             "    </soapenv:Header>\n" +
+             "    <soapenv:Body>\n" +
+             "        <axis2:echoVoid xmlns:axis2=\"http://ws.apache.org/axis2\">\n" +
+             "        </axis2:echoVoid>\n" +
+             "    </soapenv:Body>\n" +
+             "</soapenv:Envelope>";
+
+    private XMLStreamReader parser1;
+    private ExtendedBuilder builder;
+
+    protected void setUp() throws Exception {
+        parser1 = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(XMLText.getBytes()));
+        builder = new ExtendedBuilder(parser1);
+        ExtensionRegistry.getInstance().clearExtensions();
+
+    }
+
+     public void testExtendedBuilderForEnvelop(){
+         //register the SOAP extension
+        ExtensionRegistry.getInstance().registerExtension(new EnvelopeBuilderExtension());
+
+        OMElement elt =  builder.getDocumentElement();
+        assertTrue(elt instanceof SOAPEnvelope);
+
+
+     }
+      public void testExtendedBuilderForNoEnvelope(){
+
+        OMElement elt =  builder.getDocumentElement();
+        assertFalse(elt instanceof SOAPEnvelope);
+
+
+     }
+}