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 di...@apache.org on 2006/12/13 16:48:04 UTC

svn commit: r486695 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: deployment/ deployment/repository/util/ description/ util/

Author: dims
Date: Wed Dec 13 07:48:03 2006
New Revision: 486695

URL: http://svn.apache.org/viewvc?view=rev&rev=486695
Log:
use utility methods instead of peppering same code everywhere

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DescriptionBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL2.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLUtils.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DescriptionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DescriptionBuilder.java?view=diff&rev=486695&r1=486694&r2=486695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DescriptionBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DescriptionBuilder.java Wed Dec 13 07:48:03 2006
@@ -16,20 +16,23 @@
 
 package org.apache.axis2.deployment;
 
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.*;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Flow;
+import org.apache.axis2.description.HandlerDescription;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.ParameterInclude;
+import org.apache.axis2.description.PolicyInclude;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.MessageReceiver;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.util.Loader;
+import org.apache.axis2.util.XMLUtils;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -39,7 +42,6 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import java.io.InputStream;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -85,14 +87,8 @@
      *
      */
     public OMElement buildOM() throws XMLStreamException {
-        XMLStreamReader xmlReader = StAXUtils
-                .createXMLStreamReader(descriptionStream);
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-        StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac, xmlReader);
-        OMElement element = staxOMBuilder.getDocumentElement();
-
+        OMElement element = (OMElement) XMLUtils.toOM(descriptionStream);
         element.build();
-
         return element;
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?view=diff&rev=486695&r1=486694&r2=486695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Wed Dec 13 07:48:03 2006
@@ -16,9 +16,9 @@
 
 
 package org.apache.axis2.deployment.repository.util;
+
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.DeploymentConstants;
@@ -39,6 +39,7 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.namespace.Constants;
+import org.apache.axis2.util.XMLUtils;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -56,6 +57,7 @@
 import java.util.HashMap;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
+
 public class ArchiveReader implements DeploymentConstants {
     private static final Log log = LogFactory.getLog(ArchiveReader.class);
 
@@ -290,7 +292,7 @@
                         // lets check the namespace of the root element and decide. But since we are
                         // using axiom (dude, you are becoming handy here :)), we will not build the
                         // whole thing.
-                        OMNamespace documentElementNS = new StAXOMBuilder(in).getDocumentElement().getNamespace();
+                        OMNamespace documentElementNS = ((OMElement)XMLUtils.toOM(in)).getNamespace();
                         if (documentElementNS != null) {
                             WSDLToAxisServiceBuilder wsdlToAxisServiceBuilder = null;
                             if (WSDLConstants.WSDL20_2006Constants.DEFAULT_NAMESPACE_URI.equals(documentElementNS.getNamespaceURI())) {
@@ -343,7 +345,7 @@
                 // lets check the namespace of the root element and decide. But since we are
                 // using axiom (dude, you are becoming handy here :)), we will not build the
                 // whole thing.
-                OMNamespace documentElementNS = new StAXOMBuilder(in).getDocumentElement().getNamespace();
+                OMNamespace documentElementNS = ((OMElement)XMLUtils.toOM(in)).getNamespace();
                 if (documentElementNS != null) {
                     WSDLToAxisServiceBuilder wsdlToAxisServiceBuilder = null;
                     if (WSDLConstants.WSDL20_2006Constants.DEFAULT_NAMESPACE_URI.equals(documentElementNS.getNamespaceURI())) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java?view=diff&rev=486695&r1=486694&r2=486695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java Wed Dec 13 07:48:03 2006
@@ -1,13 +1,17 @@
 package org.apache.axis2.description;
 
-import org.apache.axiom.om.*;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.namespace.Constants;
 import org.apache.axis2.util.ExternalPolicySerializer;
 import org.apache.axis2.util.PolicyUtil;
+import org.apache.axis2.util.XMLUtils;
 import org.apache.axis2.wsdl.SOAPHeaderMessage;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.neethi.Policy;
@@ -18,11 +22,14 @@
 import org.apache.ws.java2wsdl.Java2WSDLConstants;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
 
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -178,13 +185,8 @@
                 schema.write(writer);
                 String schemaString = writer.toString();
                 if (!"".equals(schemaString)) {
-                    XMLStreamReader xmlReader = StAXUtils
-                            .createXMLStreamReader(new StringReader(
-                                    schemaString));
-
-                    StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac,
-                            xmlReader);
-                    wsdlTypes.addChild(staxOMBuilder.getDocumentElement());
+                    wsdlTypes.addChild(XMLUtils.toOM(new StringReader(
+                                    schemaString)));
                 }
             }
         }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL2.java?view=diff&rev=486695&r1=486694&r2=486695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL2.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL2.java Wed Dec 13 07:48:03 2006
@@ -4,14 +4,12 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axis2.namespace.Constants;
+import org.apache.axis2.util.XMLUtils;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchema;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayInputStream;
 import java.io.StringWriter;
 import java.net.URL;
@@ -96,11 +94,7 @@
                 String schemaString = writer.toString();
 
                 if (!"".equals(schemaString)) {
-                    XMLStreamReader xmlReader = StAXUtils
-                            .createXMLStreamReader(new ByteArrayInputStream(schemaString.getBytes()));
-
-                    StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac, xmlReader);
-                    wsdlTypes.addChild(staxOMBuilder.getDocumentElement());
+                    wsdlTypes.addChild(XMLUtils.toOM(new ByteArrayInputStream(schemaString.getBytes())));
                 }
             }
         }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java?view=diff&rev=486695&r1=486694&r2=486695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java Wed Dec 13 07:48:03 2006
@@ -16,18 +16,7 @@
 
 package org.apache.axis2.util;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.neethi.Constants;
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyComponent;
@@ -36,6 +25,13 @@
 import org.apache.woden.internal.util.dom.DOM2Writer;
 import org.w3c.dom.Element;
 
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
 public class PolicyUtil {
 
     public static String getSafeString(String unsafeString) {
@@ -89,10 +85,7 @@
         }
 
         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        return OMXMLBuilderFactory.createStAXOMBuilder(
-                OMAbstractFactory.getOMFactory(),
-                XMLInputFactory.newInstance().createXMLStreamReader(bais))
-                .getDocumentElement();
+        return (OMElement) XMLUtils.toOM(bais);
 
     }
 
@@ -108,10 +101,7 @@
         writer.flush();
 
         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        return OMXMLBuilderFactory.createStAXOMBuilder(
-                OMAbstractFactory.getOMFactory(),
-                XMLInputFactory.newInstance().createXMLStreamReader(bais))
-                .getDocumentElement();
+        return (OMElement) XMLUtils.toOM(bais);
     }
 
     public static PolicyComponent getPolicyComponentFromOMElement(

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLUtils.java?view=diff&rev=486695&r1=486694&r2=486695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/XMLUtils.java Wed Dec 13 07:48:03 2006
@@ -19,6 +19,9 @@
 import com.ibm.wsdl.Constants;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
 import org.w3c.dom.Attr;
@@ -41,6 +44,7 @@
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
@@ -53,6 +57,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.io.Reader;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.ProtocolException;
@@ -531,5 +536,36 @@
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             factory.setNamespaceAware(true);
             return factory.newDocumentBuilder().parse(bais).getDocumentElement();
+    }
+
+
+    /**
+     * Converts a given inputstream to an OMNode
+     *
+     * @param inputStream
+     * @return
+     * @throws javax.xml.stream.XMLStreamException
+     */
+    public static OMNode toOM(InputStream inputStream) throws XMLStreamException {
+        XMLStreamReader xmlReader = StAXUtils
+                .createXMLStreamReader(inputStream);
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac, xmlReader);
+        return staxOMBuilder.getDocumentElement();
+    }
+
+    /**
+     * Converts a given Reader to an OMNode
+     *
+     * @param reader
+     * @return
+     * @throws XMLStreamException
+     */
+    public static OMNode toOM(Reader reader) throws XMLStreamException {
+        XMLStreamReader xmlReader = StAXUtils
+                .createXMLStreamReader(reader);
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac, xmlReader);
+        return staxOMBuilder.getDocumentElement();
     }
 }



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