You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by hu...@apache.org on 2006/07/04 15:44:43 UTC
svn commit: r419005 - in /incubator/woden/java: .classpath build.properties
build.xml src/org/apache/woden/internal/util/om/
src/org/apache/woden/internal/util/om/OMUtils.java
src/org/apache/woden/internal/util/om/QNameUtils.java
Author: hughesj
Date: Tue Jul 4 06:44:42 2006
New Revision: 419005
URL: http://svn.apache.org/viewvc?rev=419005&view=rev
Log:
WODEN-37: add OMUtils QNameUtils. build.xml now downloads necessary dependencies.
Added:
incubator/woden/java/src/org/apache/woden/internal/util/om/
incubator/woden/java/src/org/apache/woden/internal/util/om/OMUtils.java (with props)
incubator/woden/java/src/org/apache/woden/internal/util/om/QNameUtils.java (with props)
Modified:
incubator/woden/java/.classpath
incubator/woden/java/build.properties
incubator/woden/java/build.xml
Modified: incubator/woden/java/.classpath
URL: http://svn.apache.org/viewvc/incubator/woden/java/.classpath?rev=419005&r1=419004&r2=419005&view=diff
==============================================================================
--- incubator/woden/java/.classpath (original)
+++ incubator/woden/java/.classpath Tue Jul 4 06:44:42 2006
@@ -10,5 +10,7 @@
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.apache.ant_1.6.5/lib/ant.jar"/>
<classpathentry kind="lib" path="downloads/lib/XmlSchema-1.0.jar"/>
<classpathentry kind="lib" path="downloads/lib/wsdl4j.jar"/>
+ <classpathentry kind="lib" path="downloads/lib/axiom-api-1.0.jar"/>
+ <classpathentry kind="lib" path="downloads/lib/stax-api-1.0.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: incubator/woden/java/build.properties
URL: http://svn.apache.org/viewvc/incubator/woden/java/build.properties?rev=419005&r1=419004&r2=419005&view=diff
==============================================================================
--- incubator/woden/java/build.properties (original)
+++ incubator/woden/java/build.properties Tue Jul 4 06:44:42 2006
@@ -27,6 +27,11 @@
AntJar = ant.jar
WSDL4JURL = http://superb-west.dl.sourceforge.net/sourceforge/wsdl4j/wsdl4j-bin-1.5.2.zip
WSDL4JFile = wsdl4j-bin-1.5.2.zip
+AxiomURL = http://www.apache.org/dist/ws/commons/axiom/1_0/axiom-1.0-bin.zip
+AxiomFile = axiom-1.0-bin.zip
+AxiomJar = axiom-api-1.0.jar
+StaxURL = http://www.ibiblio.org/maven/stax/jars/stax-api-1.0.1.jar
+StaxFile = stax-api-1.0.1.jar
! The location of the Woden build home
build.home = ${basedir}
Modified: incubator/woden/java/build.xml
URL: http://svn.apache.org/viewvc/incubator/woden/java/build.xml?rev=419005&r1=419004&r2=419005&view=diff
==============================================================================
--- incubator/woden/java/build.xml (original)
+++ incubator/woden/java/build.xml Tue Jul 4 06:44:42 2006
@@ -71,6 +71,11 @@
<echo message="AntJar=${AntJar}" />
<echo message="WSDL4JURL=${WSDL4JURL}" />
<echo message="WSDL4JFile=${WSDL4JFile}" />
+ <echo message="AxiomURL=${AxiomURL}" />
+ <echo message="AxiomFile=${AxiomFile}" />
+ <echo message="AxiomJar=${AxiomJar}" />
+ <echo message="StaxURL=${StaxURL}" />
+ <echo message="StaxFile=${StaxFile}" />
<echo message="build.home=${build.home}" />
<echo message="version=${version}" />
<echo message="milestone=${milestone}" />
@@ -112,11 +117,17 @@
<available file="${downloads}/${XercesFile}" property="Xerces.exists" />
<available file="${downloads}/${AntFile}" property="Ant.exists" />
<available file="${downloads}/${WSDL4JFile}" property="WSDL4J.exists" />
+ <available file="${downloads}/${AxiomFile}" property="Axiom.exists" />
+ <!-- The Stax 1.0.x API jar is only available in jar form, not zip
+ so we download it straight into the libraryDir -->
+ <available file="${libraryDir}/${StaxFile}" property="Stax.exists" />
<antcall target="getXmlSchema" />
<antcall target="getXerces" />
<antcall target="getAnt" />
<antcall target="getWSDL4J" />
+ <antcall target="getAxiom" />
+ <antcall target="getStax" />
<antcall target="extractXmlSchema" />
@@ -173,6 +184,22 @@
<include name="**/wsdl4j*.jar" />
</patternset>
</unzip>
+ </target>
+
+ <!-- Get the latest version of Axiom and unzip it -->
+ <target name="getAxiom" unless="Axiom.exists">
+ <get src="${AxiomURL}" dest="${downloads}/${AxiomFile}" />
+
+ <unzip src="${downloads}/${AxiomFile}" dest="${libraryDir}">
+ <patternset>
+ <include name="**/${AxiomJar}" />
+ </patternset>
+ </unzip>
+ </target>
+
+ <!-- Get the latest version of Stax API and unzip it -->
+ <target name="getStax" unless="Stax.exists">
+ <get src="${StaxURL}" dest="${libraryDir}/${StaxFile}" />
</target>
<!-- Copy the XmlSchema file to the lib dir -->
Added: incubator/woden/java/src/org/apache/woden/internal/util/om/OMUtils.java
URL: http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/util/om/OMUtils.java?rev=419005&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/om/OMUtils.java (added)
+++ incubator/woden/java/src/org/apache/woden/internal/util/om/OMUtils.java Tue Jul 4 06:44:42 2006
@@ -0,0 +1,240 @@
+/**
+ * Copyright 2006 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.woden.internal.util.om;
+
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.WSDLException;
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.internal.ErrorReporterImpl;
+import org.apache.woden.internal.ErrorLocatorImpl;
+import org.xml.sax.InputSource;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.namespace.QName;
+import java.io.*;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Iterator;
+
+/**
+ * This class contains utility methods required for parsing elements
+ * in a WSDL using AXIOM.
+ */
+public class OMUtils {
+
+ /**
+ * The namespaceURI represented by the prefix <code>xmlns</code>.
+ */
+ private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
+ private static final String ATTR_XMLNS = "xmlns";
+ private static final String emptyString = "";
+
+ /**
+ * @param strUri The URI where the WSDL can be found
+ * @return A StAXOMBuilder which could be used in obtaining the document object
+ */
+ public static StAXOMBuilder getOMBuilder(String strUri) {
+ StAXOMBuilder builder = null;
+ try {
+ URI uri = new URI(strUri);
+ URL url = uri.toURL();
+
+ InputStream in = url.openStream();
+ builder = new StAXOMBuilder(in);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (XMLStreamException e) {
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ return builder;
+ }
+
+
+ /**
+ * todo add validation
+ * @param uri of the OMDocument
+ * @return an OMElement representing the document just read
+ */
+ public static OMElement getElement(String uri){
+ StAXOMBuilder builder = OMUtils.getOMBuilder(uri);
+ OMElement elem = builder.getDocumentElement();
+ return elem;
+ }
+
+ /**
+ * Returns the value of an attribute of an element. Returns null
+ * if the attribute is not found
+ * @param omElement Element whose attrib is looked for
+ * @param attrName name of attribute to look for
+ * @return the attribute value
+ */
+ public static String getAttribute(OMElement omElement, String attrName) {
+ String val = null;
+ Iterator allAttr = omElement.getAllAttributes();
+ while(allAttr.hasNext()){
+ OMAttribute attr = (OMAttribute)allAttr.next();
+ if (attr.getLocalName().equals(attrName)){
+ val = attr.getAttributeValue();
+ }
+ }
+ return val;
+ }
+
+ /**
+ * @param element OMElement which would most probably contain <xs:schema>
+ * @return a SAX inputsource from the OMElement
+ */
+ public static InputSource getInputSource(OMElement element){
+
+ String elementString = null;
+
+ //Obtain the String value of the OMElement after building the OM tree
+ try {
+ elementString = element.toStringWithConsume();
+ } catch (XMLStreamException e) {
+ e.printStackTrace();
+ }
+ byte[] bytes = elementString.getBytes();
+
+ //Deserialize from a byte array
+ InputStream inputStream = new ByteArrayInputStream(bytes);
+ InputSource inputSource = new InputSource(inputStream);
+
+ return inputSource;
+ }
+
+ /**
+ * TODO: check if the QName returned is correct in all cases
+ * @param prefixedValue to which the QName is prefixed
+ * @param contextEl Element in which the QName is sought for
+ * @param desc The DescriptionElement which contains elements so far read from the WSDL
+ * @return The relevant QName for the prefix
+ * @throws WSDLException
+ */
+ public static QName getQName(String prefixedValue,
+ OMElement contextEl,
+ DescriptionElement desc) throws WSDLException {
+
+ int index = prefixedValue.indexOf(':');
+ String prefix = (index != -1)
+ ? prefixedValue.substring(0, index)
+ : null;
+ String localPart = prefixedValue.substring(index + 1);
+ String namespaceURI = getNamespaceURIFromPrefix(desc, prefix);
+
+ if (namespaceURI != null){
+ //TODO investigate changing the registration of namespaces and prefixes (i.e. namespace decls)
+ try {
+ registerUniquePrefix(prefix, namespaceURI, desc);
+ }
+ catch (WSDLException e) {
+ e.printStackTrace();
+ }
+
+ //TODO when passing prefix to QName ctor, what if it was modified by
+ //registerUniquePrefix because of a name clash (pass original or modification)?
+ return new QName( namespaceURI,
+ localPart,
+ prefix != null ? prefix : emptyString);
+ }
+ else{
+ //TODO use ErrorReporter here or in callers to report the problem
+ String faultCode = (prefix == null)
+ ? WSDLException.NO_PREFIX_SPECIFIED
+ : WSDLException.UNBOUND_PREFIX;
+
+ WSDLException wsdlExc = new WSDLException(faultCode,
+ "Unable to determine " +
+ "namespace of '" +
+ prefixedValue + "'.");
+
+ //TODO Get XPath from the node
+ //wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(contextEl));
+
+ throw wsdlExc;
+ }
+ }
+
+ /**
+ * TODO: might be a wrong approach to get the NamespaceURI!
+ * This method assumes that all the namespaces are registered with the DescriptionElement
+ * @param desc
+ * @param prefix the prefix to find an xmlns:prefix=uri for the relevant element
+ *
+ * @return the namespace URI or null if not found
+ */
+ public static String getNamespaceURIFromPrefix (DescriptionElement desc,
+ String prefix) {
+ return desc.getNamespaces().get(prefix).toString();
+ }
+
+ /**
+ * @param el Element whose attrib is looked for
+ * @param namespaceURI namespace URI of attribute to look for
+ * @param localPart local part of attribute to look for
+ * @return the attribute value
+ */
+ static public String getAttributeNS (OMElement el,
+ String namespaceURI,
+ String localPart) {
+ String sRet = null;
+ OMAttribute attr = el.getAttribute(new QName(namespaceURI, localPart));
+ if (attr != null) {
+ sRet = attr.getAttributeValue();
+ }
+ return sRet;
+ }
+
+
+ /*This is the same method taken from DOMUtils*/
+ public static void registerUniquePrefix(String prefix, String namespaceURI, DescriptionElement desc)
+ throws WSDLException {
+ URI nsUri = desc.getNamespace(prefix);
+ String tempNSUri = nsUri != null ? nsUri.toString() : null;
+
+ if (tempNSUri != null && tempNSUri.equals(namespaceURI)){
+ return;
+ }
+
+ while (tempNSUri != null && !tempNSUri.equals(namespaceURI)){
+ prefix += "_";
+ nsUri = desc.getNamespace(prefix);
+ tempNSUri = nsUri != null ? nsUri.toString() : null;
+ }
+
+ URI uri = null;
+ try {
+ uri = new URI(namespaceURI);
+ } catch (URISyntaxException e) {
+ //TODO make sure custom err handler is used, if configured
+ new ErrorReporterImpl().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL506",
+ new Object[] {namespaceURI},
+ ErrorReporter.SEVERITY_ERROR,
+ e);
+ }
+ desc.addNamespace(prefix, uri);
+ }
+}
+
+
Propchange: incubator/woden/java/src/org/apache/woden/internal/util/om/OMUtils.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/woden/java/src/org/apache/woden/internal/util/om/QNameUtils.java
URL: http://svn.apache.org/viewvc/incubator/woden/java/src/org/apache/woden/internal/util/om/QNameUtils.java?rev=419005&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/om/QNameUtils.java (added)
+++ incubator/woden/java/src/org/apache/woden/internal/util/om/QNameUtils.java Tue Jul 4 06:44:42 2006
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2006 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.woden.internal.util.om;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Class to handle some trivial functionality related to QNames.
+ */
+public class QNameUtils {
+
+ /**
+ * @param qname The relevant QName to be matched
+ * @param element
+ * @return true if the given QName matches the element's and false otherwise
+ */
+ public static boolean matches(QName qname, OMElement element){
+ return (element != null && qname.equals(newQName(element)));
+ }
+
+ /* TODO: this method could be unnecessary!
+ * @param element
+ * @return a QName based on the OMElement
+ */
+ public static QName newQName(OMElement element){
+ if (element != null){
+ OMNamespace namespace = element.getNamespace();
+ return new QName(namespace.getName(), element.getLocalName());
+ }
+ else{
+ return null;
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/woden/java/src/org/apache/woden/internal/util/om/QNameUtils.java
------------------------------------------------------------------------------
svn:executable = *
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org