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 jk...@apache.org on 2007/08/12 23:51:43 UTC

svn commit: r565165 [2/2] - in /incubator/woden/trunk/java: src/org/apache/woden/internal/wsdl20/ src/org/apache/woden/wsdl20/ src/org/apache/woden/wsdl20/fragids/ src/org/apache/woden/xpointer/ test/org/apache/woden/internal/wsdl20/validation/ test/or...

Added: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java?view=auto&rev=565165
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java Sun Aug 12 14:51:41 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.woden.wsdl20.fragids;
+
+import javax.xml.namespace.QName;
+
+import org.apache.woden.xpointer.XPointer;
+
+import java.net.URI;
+
+/**
+ * <code>TypeDefinitionPart</code> is a Type Definition Pointer Part for the Type Definition WSDL 2.0 component.
+ * See the specification at <a href="http://www.w3.org/TR/wsdl20/#wsdl.typeDefinition">http://www.w3.org/TR/wsdl20/#wsdl.typeDefinition</a>
+ * 
+ * @author Dan Harvey (danharvey42@gmail.com)
+ *
+ */
+public class TypeDefinitionPart implements ComponentPart{
+    private QName type;   //Name of the Type Definition component.
+    private final URI system;   //Namespace absolute IRI of the extension type system used for the Type Definition component.
+
+    /**
+     * Constructs a TypeDefinitionPart class for an Type Definition component with an XMLScheme type system.
+     * 
+     * @param type the name of the Type Definition component.
+     * @param system namespace absolute IRI of the extension type system used for the Type Definition component.
+     * @throws IllegalArgumentException if type or system are null.
+     */
+    public TypeDefinitionPart(QName type, URI system) {
+        if (type == null | system == null) {
+            throw new IllegalArgumentException();
+        }
+        this.type = type;
+        this.system = system;
+    }
+    
+    /**
+     * Constructs an TypeDefinitionPart class for an Type Definition component with another type system.
+     * 
+     * @param type the name of the Definition component.
+     * @throws IllegalArgumentException if type is null.
+     */
+    public TypeDefinitionPart(QName type) {
+        if (type == null) {
+            throw new IllegalArgumentException();
+        }
+        this.type = type;
+        this.system = null;
+    }
+    
+    public void prefixNamespaces(XPointer xpointer) {
+        type = xpointer.prefixQNameNamespace(type);
+    }
+    
+    /**
+     * Returns a String of the serialised Type Definition Pointer Part.
+     * 
+     * @return a String the serialised Type Definition Pointer Part.
+     */
+    public String toString() {
+        String typeString = (type.getPrefix() != null && !type.getPrefix().equals("") ? type.getPrefix() + ":" + type.getLocalPart() : type.getLocalPart());
+        if (system == null) {
+            return "wsdl.typeDefinition(" + typeString + ")";
+        } else {
+            return "wsdl.typeDefinition(" + typeString + "," + system + ")";
+        }
+    }
+    
+}

Added: incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java?view=auto&rev=565165
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java Sun Aug 12 14:51:41 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.woden.xpointer;
+
+/**
+ * Interface to be implemented by pointer parts (XPointer schemes).
+ */
+
+public interface PointerPart {
+    
+    /**
+     * Returns a String serialisation of this xpointer PointerPart.
+     * 
+     * @return a String containing the serialisation of this xpointer PointerPart.
+     */
+    public String toString();
+    
+    /**
+     * Checks that the namespace prefixes used in this PointerPart are
+     * consistent with those in the XPointer.
+     * 
+     * This method is called by the add method on XPointer when PointerParts are added to it.
+     * 
+     * @param xpointer an XPointer which the namespace prefixes are checked against.
+     */
+    public void prefixNamespaces(XPointer xpointer);
+
+}

Added: incubator/woden/trunk/java/src/org/apache/woden/xpointer/XPointer.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/xpointer/XPointer.java?view=auto&rev=565165
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/xpointer/XPointer.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/xpointer/XPointer.java Sun Aug 12 14:51:41 2007
@@ -0,0 +1,165 @@
+/*
+ * 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.woden.xpointer;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.HashMap;
+
+import java.util.Iterator;
+import java.lang.StringBuffer;
+
+import org.apache.woden.types.NCName;
+import javax.xml.namespace.QName;
+import org.apache.woden.xpointer.XmlnsPart;
+
+
+/**
+ * Represents a fragment identifier conforming to the XML Pointer Language Framework.
+ * 
+ * This class is based upon a class of the same name in the Apache Cocoon.
+ *
+ * @author Dan Harvey (danharvey42@gmail.com)
+ * 
+ * TODO Add a constructor to create a XPointer from a String by deserialisation.
+ * 
+ */
+
+public class XPointer {
+    private final List pointerParts;
+    private final HashMap xmlnses;
+    private static final NCName emptyNCName = new NCName("");
+    private static String NS_URI_XML = "http://www.w3.org/XML/1998/namespace";
+    private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
+
+    /**
+     * Constructs a new Fragment Identifier.
+     * 
+     */
+    public XPointer() {
+        pointerParts = new LinkedList();
+        xmlnses = new HashMap();
+    }
+    
+    /**
+     * Appends a pointer part to the end of this XPointer.
+     * 
+     * @param pointerPart the Pointer Part to append.
+     */
+    public void addPart(PointerPart pointerPart) {
+        pointerParts.add(pointerPart);
+        //Make sure the PointerPart's namespaces are in line with this XPointer.
+        pointerPart.prefixNamespaces(this); 
+    }
+    
+    /**
+     * Returns a String serialisation of this XPointer.
+     * 
+     * @return a String containing the serialisation of this XPointer
+     */
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        Iterator parts = pointerParts.iterator();
+        while (parts.hasNext()) {
+            buffer.append(parts.next());
+        }
+        return buffer.toString();
+    }
+    
+    /** Namespace management code **/
+    
+    /**
+     * Returns the prefix for the Xml namespace of the QName in the XPointer.
+     * If the namespace does not have a prefix in the XPointer it will create a new prefix
+     * with the prefix from the QName or one of the form nsXX and add a xmlns Pointer Part, then return that.
+     * 
+     * @param qname The QName containing the namespace and a prefix.
+     * @return a NCName of the prefix for the namespace.
+     */
+    public NCName getXmlNamespacePrefix(QName qname) {
+        return getXmlNamespacePrefix(qname.getNamespaceURI() , new NCName(qname.getPrefix()));
+    }
+
+    /**
+     * Returns the prefix for the Xml namespace in the XPointer.
+     * If the namespace does not have a prefix in the XPointer it will create a new prefix
+     * of the form nsXX and add a xmlns Pointer Part, then return that.
+     * 
+     * @param namespace The namespace to get the prefix for.
+     * @return a NCName of the prefix for the namespace.
+     */
+    public NCName getXmlNamespacePrefix(String namespace) {
+        return getXmlNamespacePrefix(namespace, null);
+    }
+    
+    /**
+     * Returns the prefix for the Xml namespace in the XPointer.
+     * If the namespace does not have a prefix in the XPointer it will create a new prefix
+     * with the prefix given or one of the form nsXX and add a xmlns Pointer Part, then return that.
+     * 
+     * @param namespace The namespace to get the prefix for.
+     * @param defaultPrefix The default prefix name to use if a prefix does not already exist.
+     * @return a NCName of the prefix for the namespace.
+     */
+    public NCName getXmlNamespacePrefix(String namespace, NCName defaultPrefix) {
+        //If its the xml namespace no prefix is needed.
+        if (namespace.equals(NS_URI_XML)) {
+            return emptyNCName;
+        }
+        //If its the xmlns namespace you shouldn't be using it!
+        if (namespace.equals(NS_URI_XMLNS)) {
+            return emptyNCName;
+        }
+        //Lookup prefix
+        NCName prefix = (NCName)xmlnses.get(namespace);
+        if (prefix == null) {
+            //The namespace does not have a prefix let so lets add one.
+            //Find name a valid prefix name that isn't used and is not xml or xmlns.
+            if (defaultPrefix != null && !defaultPrefix.toString().equals("") && !defaultPrefix.equals("xml") && !defaultPrefix.equals("xmlns") && !xmlnses.containsValue(defaultPrefix)) {
+                //Use default prefix given
+                prefix = defaultPrefix;
+            } else {
+                //Find next available nsXXX prefix
+                prefix = new NCName("ns" + Integer.toString(xmlnses.size()));
+                for (int i = 1; xmlnses.containsKey(prefix); i++) {
+                    prefix = new NCName("ns" + Integer.toString(xmlnses.size() + i));
+                }
+            }
+            
+            //Add prefix pointer part.
+            pointerParts.add(xmlnses.size(), new XmlnsPart(prefix, namespace));
+            
+            //Add to Map.
+            xmlnses.put(namespace, prefix);
+        }
+        return prefix;
+    }
+    
+    /**
+     * Returns a QName prefixed from the map of local namespaces and prefixes.
+     * The namespace and localpart remain unchanged.
+     * 
+     * @param qname the QName used to lookup the namespace and copy.
+     * @return a QName with the new prefix, but same namespace and localpart.
+     */
+    public QName prefixQNameNamespace(QName qname) {
+        //Get prefix for the fault QName in the XPointer.
+        NCName prefix = getXmlNamespacePrefix(qname);
+        return new QName(qname.getNamespaceURI(), qname.getLocalPart(), prefix.toString());
+    }
+}

Added: incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPart.java?view=auto&rev=565165
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPart.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPart.java Sun Aug 12 14:51:41 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.woden.xpointer;
+
+import org.apache.woden.types.NCName;
+
+/**
+ * Represents a fragment identifier conforming to the XML Pointer Language Framework.
+ * 
+ * This class is based upon a class of the same name in the Apache Coccon.
+ *
+ * @author Dan Harvey (danharvey42@gmail.com)
+ */
+public class XmlnsPart implements PointerPart {
+    private final NCName prefix;
+    private final String namespace;
+
+    public XmlnsPart(NCName prefix, String namespace) {
+        if (prefix == null | namespace == null) {
+            throw new IllegalArgumentException();
+        }
+        this.prefix = prefix;
+        this.namespace = namespace;
+    }
+
+    public String toString() {
+        return "xmlns(" + prefix + "=" + namespace + ")";
+    }
+    
+    public void prefixNamespaces(XPointer xpointer) {
+        //This PointerPart does not have any namespaces.
+    }
+}

Modified: incubator/woden/trunk/java/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java?view=diff&rev=565165&r1=565164&r2=565165
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java Sun Aug 12 14:51:41 2007
@@ -773,6 +773,7 @@
       DescriptionImpl desc = new DescriptionImpl();
       desc.setTargetNamespace(namespace1);
       InterfaceElement interfac = desc.addInterfaceElement();
+      interfac.setName(name1);
       InterfaceFaultElement fault = interfac.addInterfaceFaultElement();
       fault.setName(name1);
       InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
@@ -852,6 +853,7 @@
       DescriptionImpl desc = new DescriptionImpl();
       desc.setTargetNamespace(namespace1);
       InterfaceElement interfac = desc.addInterfaceElement();
+      interfac.setName(name1);
       InterfaceFaultElement fault = interfac.addInterfaceFaultElement();
       fault.setName(name1);
       InterfaceOperationElement oper = interfac.addInterfaceOperationElement();

Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java?view=diff&rev=565165&r1=565164&r2=565165
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java Sun Aug 12 14:51:41 2007
@@ -53,6 +53,7 @@
 import org.apache.woden.wsdl20.extensions.soap.SOAPBindingFaultReferenceExtensionsTest;
 import org.apache.woden.wsdl20.extensions.soap.SOAPBindingMessageReferenceExtensionsTest;
 import org.apache.woden.wsdl20.extensions.soap.SOAPBindingOperationExtensionsTest;
+import org.apache.woden.wsdl20.fragids.FragmentIdentificationTest;
 import org.apache.woden.wsdl20.xml.BindingElementTest;
 import org.apache.woden.wsdl20.xml.BindingFaultElementTest;
 import org.apache.woden.wsdl20.xml.BindingFaultReferenceElementTest;
@@ -152,6 +153,7 @@
     addTest(BindingFaultReferenceTest.suite());
     addTest(BindingMessageReferenceTest.suite());
     addTest(DocumentationElementTest.suite());
+    addTest(FragmentIdentificationTest.suite());    
     //TODO in-progress 30May06 tests for BindingOpExt and BindingMsgRefExt
   }
 



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