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 2008/01/07 18:36:43 UTC
svn commit: r609714 [5/8] - in /webservices/woden/branches/woden65: ./
ant-test/ src/org/apache/woden/ src/org/apache/woden/ant/
src/org/apache/woden/internal/ src/org/apache/woden/internal/resolver/
src/org/apache/woden/internal/util/dom/ src/org/apac...
Modified: webservices/woden/branches/woden65/src/org/apache/woden/xpointer/PointerPart.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/xpointer/PointerPart.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/xpointer/PointerPart.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/xpointer/PointerPart.java Mon Jan 7 09:36:13 2008
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.woden.xpointer;
/**
@@ -30,14 +29,4 @@
*/
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);
-
}
Modified: webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointer.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointer.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointer.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointer.java Mon Jan 7 09:36:13 2008
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -18,148 +18,239 @@
package org.apache.woden.xpointer;
import java.util.List;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.Map;
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.
+ * XPointer is a class which represents an XPointer defined in the XPointer Framework.
+ * This is specified at <a href="http://www.w3.org/TR/xptr-framework/">http://www.w3.org/TR/xptr-framework/</a>
*
- * 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 Map prefixBindingContex;
+ private final Map namespaceBindingContex;
+ private NCName shorthandPointer;
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/";
+
+ private static final String NS_URI_XML = "http://www.w3.org/XML/1998/namespace";
+ private static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
+ private static final NCName NS_PREFIX_XMLNS = new NCName("xmlns");
/**
- * Constructs a new Fragment Identifier.
+ * Constructs a new XPointer.
*
*/
public XPointer() {
- pointerParts = new LinkedList();
- xmlnses = new HashMap();
+ pointerParts = new ArrayList();
+ shorthandPointer = emptyNCName;
+
+ //Setup prefix/namespace binding context.
+ prefixBindingContex = new HashMap();
+ namespaceBindingContex = new HashMap();
+ addPrefixNamespaceBinding(new NCName("xml"), NS_URI_XML);
+ }
+
+ /**
+ * Constructs a new XPointer from the serialised string.
+ *
+ * @param xpointerString a String form of the XPointer to deserialise.
+ */
+ public XPointer(String xpointerString) throws InvalidXPointerException {
+ this(); //Construct a new XPointer.
+ if (xpointerString == null || xpointerString.equals(""))
+ throw new InvalidXPointerException("The XPointer string is either null or empty", "");
+ XPointerParser.parseXPointer(xpointerString, this); //Parse the string and add the Pointers to the new XPointer.
}
/**
* Appends a pointer part to the end of this XPointer.
*
* @param pointerPart the Pointer Part to append.
+ * @throws UnsupportedOperationException() if a Shorthand Pointer is already set.
*/
- public void addPart(PointerPart pointerPart) {
- pointerParts.add(pointerPart);
- //Make sure the PointerPart's namespaces are in line with this XPointer.
- pointerPart.prefixNamespaces(this);
+ public void addPointerPart(PointerPart pointerPart) {
+ if(!shorthandPointer.equals(emptyNCName)) {
+ throw new UnsupportedOperationException("A Shortname Pointer already exists for this XPointer.");
+ } else {
+ pointerParts.add(pointerPart);
+ }
}
/**
- * Returns a String serialisation of this XPointer.
+ * Inserts a pointer part at index of this XPointer.
*
- * @return a String containing the serialisation of this XPointer
+ * @param pointerPart the Pointer Part to inserted.
+ * @param index an integer specifying the point to insert the pointer part.
+ * @throws UnsupportedOperationException() if a Shorthand Pointer is already set.
*/
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- Iterator parts = pointerParts.iterator();
- while (parts.hasNext()) {
- buffer.append(parts.next());
+ public void addPointerPart(int index, PointerPart pointerPart) {
+ if(hasShorthandPointer()) {
+ throw new UnsupportedOperationException("A Shortname Pointer already exists for this XPointer.");
}
- return buffer.toString();
+ if(index < 0 || index > pointerParts.size()) {
+ throw new IndexOutOfBoundsException("The index you gave is out of the bounds of the list of XPointers");
+ }
+ pointerParts.add(index, pointerPart);
}
- /** Namespace management code **/
+ /**
+ * Returns the pointer parts in this XPointer.
+ *
+ * @return a PointerPart[] of type Object[] containing the pointer parts in this XPointer.
+ * @throws IllegalStateException if this XPointer has a shorthand pointer.
+ */
+ public Object[] getPointerParts() {
+ if (hasPointerParts()) {
+ int size = pointerParts.size();
+ Object[] parts = new Object[size]; //Ugly but it will have to do for Java 1.4
+ for(int i=0; i<size; i++) {
+ parts[i] = pointerParts.get(i);
+ }
+ return parts;
+ } else {
+ throw new IllegalStateException("This XPointer has a shorthand pointer.");
+ }
+ }
+
+ /**
+ * Sets the Shorthand Pointer of this XPointer to the NCName given as an argument.
+ *
+ * @param shorthandPointer an NCName of the Shorthand Pointer to set.
+ * @throws UnsupportedOperationException() is a PointerPart Pointer is already set.
+ */
+ public void setShorthandPointer(NCName shorthandPointer) {
+ if (hasPointerParts()) {
+ throw new UnsupportedOperationException("A PointerPart Pointer already exists for this XPointer");
+ }
+ if (shorthandPointer.equals(null)) {
+ throw new NullPointerException("The shorthandPointer argument is null");
+ }
+
+ this.shorthandPointer = shorthandPointer;
+ }
/**
- * 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.
+ * Returns the shorthandPointer in this XPointer.
*
- * @param qname The QName containing the namespace and a prefix.
- * @return a NCName of the prefix for the namespace.
+ * @return an NCName containing the shorthand pointer for this XPointer.
+ * @throws IllegalStateException if this XPointer has a shorthand pointer.
*/
- public NCName getXmlNamespacePrefix(QName qname) {
- return getXmlNamespacePrefix(qname.getNamespaceURI() , new NCName(qname.getPrefix()));
+ public NCName getShorthandPointer() {
+ if (hasShorthandPointer()) {
+ return shorthandPointer;
+ } else {
+ throw new IllegalStateException("This XPointer has scheme based pointers.");
+ }
+ }
+
+ /**
+ * Adds a Prefix/Namespace binding to this XPointers contex.
+ *
+ * @param prefix a NCName of the prefix too bind to the namespace.
+ * @param namespace a String of the namespace to bind to the prefix.
+ * @throws NullPointerException if the prefix or namespace arguments are null.
+ * @throws IllegalArgumentException if the prefix or namespace are invalid as specified at <a href="http://www.w3.org/TR/xptr-framework/#nsContext">http://www.w3.org/TR/xptr-framework/#nsContext</a>
+ */
+ public void addPrefixNamespaceBinding(NCName prefix, String namespace) {
+ if (prefix == null)
+ throw new NullPointerException("The prefix argument provided has a null pointer.");
+ if (namespace == null)
+ throw new NullPointerException("The namespace argument provided has a null pointer.");
+ if (prefix.equals(NS_PREFIX_XMLNS))
+ throw new IllegalArgumentException("The xmlns prefix must not be bound to any namespace.");
+ if (namespace.equals(NS_URI_XMLNS))
+ throw new IllegalArgumentException("The " + NS_URI_XMLNS + " namespace must not be bound to any prefix.");
+ //Its a valid binding so add it to the binding contex.
+ prefixBindingContex.put(prefix, namespace);
+ namespaceBindingContex.put(namespace, prefix);
+ }
+
+ /**
+ * Gets the Namespace the Prefix is bound to if the binding exists,
+ * otherwise it will return null.
+ *
+ * @param prefix a NCName of the prefix bound to the namespace.
+ * @return A String of the namespace bound to this prefix or null if none exists.
+ */
+ public String getPrefixBinding(NCName prefix) {
+ return (String)prefixBindingContex.get(prefix);
+ }
+
+ /**
+ * Gets Prefix the Namespace is bound to if the binding exists,
+ * otherwise it will return null.
+ *
+ * @param namespace a String of the prefix bound to the prefix.
+ * @return A NCName of the prefix bound to this namespace or null if none exists.
+ */
+ public NCName getNamespaceBinding(String namespace) {
+ return (NCName)namespaceBindingContex.get(namespace);
+ }
+
+ /**
+ * Checks whether a prefix is bound or not.
+ *
+ * @param prefix A NCName of the prefix to check.
+ * @return a boolean value that is true if the binding exists, or false otherwise.
+ */
+ public boolean hasPrefixBinding(NCName prefix) {
+ return prefixBindingContex.containsKey(prefix);
+ }
+
+ /**
+ * Checks whether a namespace is bound or not.
+ *
+ * @param namespace A String of the namespace to check.
+ * @return a boolean value that is true if the binding exists, or false otherwise.
+ */
+ public boolean hasNamespaceBinding(String namespace) {
+ return namespaceBindingContex.containsKey(namespace);
}
/**
- * 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.
+ * Tests whether this XPointer has a shorthand pointer or not.
*
- * @param namespace The namespace to get the prefix for.
- * @return a NCName of the prefix for the namespace.
+ * @return a boolean which is true if this XPointer contains an shorthand pointer, false otherwise.
*/
- public NCName getXmlNamespacePrefix(String namespace) {
- return getXmlNamespacePrefix(namespace, null);
+ public boolean hasShorthandPointer() {
+ return !shorthandPointer.equals(emptyNCName);
}
/**
- * 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.
+ * Tests whether this XPointer has scheme based pointers or not.
*
- * @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.
+ * @return a boolean which is true if this XPointer contains scheme based pointers, false otherwise.
*/
- 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;
+ public boolean hasPointerParts() {
+ return !pointerParts.isEmpty();
}
/**
- * Returns a QName prefixed from the map of local namespaces and prefixes.
- * The namespace and localpart remain unchanged.
+ * Returns a String serialisation of this XPointer.
*
- * @param qname the QName used to lookup the namespace and copy.
- * @return a QName with the new prefix, but same namespace and localpart.
+ * @return a String containing the serialisation of this XPointer
*/
- 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());
+ public String toString() {
+ if (shorthandPointer.equals(emptyNCName)) {
+ StringBuffer buffer = new StringBuffer();
+ Iterator parts = pointerParts.iterator();
+ while (parts.hasNext()) {
+ buffer.append(parts.next());
+ }
+ return buffer.toString();
+ } else {
+ return shorthandPointer.toString();
+ }
}
-}
+
+}
\ No newline at end of file
Added: webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointerParser.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointerParser.java?rev=609714&view=auto
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointerParser.java (added)
+++ webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointerParser.java Mon Jan 7 09:36:13 2008
@@ -0,0 +1,635 @@
+/**
+ * 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.Hashtable;
+
+import org.apache.woden.types.XMLChar;
+import org.apache.woden.types.NCName;
+
+/**
+ * This class parses a String to the XPointer Framework specification for shorthand and scheme based pointers.
+ * For scheme based pointers each know pointer part
+ *
+ * See the <a href="http://www.w3.org/TR/xptr-framework/">XPointer Framework Recommendation</a> for
+ * more information on the XPointer Framework, ShortHand and Scheme based Pointers.
+ *
+ * This class based on the org.apache.xerces.xpointer.XPointerHandler class in the Apache Xerces Project
+ * for the core XPointer parsing code. It has been modified to be used inside the Woden XPointer model.
+ *
+ * @author Dan Harvey (danharvey42@gmail.com)
+ *
+ */
+final class XPointerParser {
+
+ /**
+ * Parses a String XPointer and stores the results into the given XPointer object.
+ *
+ * @param xpointerString
+ * @param xpointer
+ * @throws InvalidXPointerException if the XPointer being parsed contains invalid syntax.
+ */
+ public static void parseXPointer(String xpointerString, XPointer xpointer) throws InvalidXPointerException{
+ final String ELEMENT_SCHEME_NAME = "element"; // Supported schemes
+
+ final Tokens tokens = new Tokens(); // tokens
+
+ // scan the XPointer expression
+ int length = xpointerString.length();
+ boolean success = Scanner.scanExpr(tokens, xpointerString, 0, length);
+
+ if (!success)
+ throw new InvalidXPointerException("Invalid XPointer expression", xpointerString);
+
+ while (tokens.hasMore()) {
+ int token = tokens.nextToken();
+
+ switch (token) {
+ case Tokens.XPTRTOKEN_SHORTHAND: {
+
+ // The shorthand name
+ token = tokens.nextToken();
+ String shortHandPointerName = tokens.getTokenString(token);
+
+ if (shortHandPointerName == null)
+ throw new InvalidXPointerException("Invalid Shorthand XPointer", xpointerString);
+
+ xpointer.setShorthandPointer(new NCName(shortHandPointerName));
+ break;
+ }
+ case Tokens.XPTRTOKEN_SCHEMENAME: {
+
+ // Retrieve the local name and prefix to form the scheme name
+ token = tokens.nextToken();
+ String prefix = tokens.getTokenString(token);
+ token = tokens.nextToken();
+ String localName = tokens.getTokenString(token);
+
+ String schemeName = prefix + localName;
+
+ // The next character should be an open parenthesis
+ int openParenCount = 0;
+ int closeParenCount = 0;
+
+ token = tokens.nextToken();
+ String openParen = tokens.getTokenString(token);
+ if (openParen != "XPTRTOKEN_OPEN_PAREN") {
+
+ // can not have more than one ShortHand Pointer
+ if (token == Tokens.XPTRTOKEN_SHORTHAND) {
+ throw new InvalidXPointerException("MultipleShortHandPointers", xpointerString);
+ } else {
+ throw new InvalidXPointerException("Invalid XPointer Expression", xpointerString);
+ }
+ }
+ openParenCount++;
+
+ // followed by zero or more ( and the schemeData
+ String schemeData = null;
+ while (tokens.hasMore()) {
+ token = tokens.nextToken();
+ schemeData = tokens.getTokenString(token);
+ if (schemeData != "XPTRTOKEN_OPEN_PAREN") {
+ break;
+ }
+ openParenCount++;
+ }
+ token = tokens.nextToken();
+ schemeData = tokens.getTokenString(token);
+
+ // followed by the same number of )
+ if (tokens.hasMore()) {
+ token = tokens.nextToken();
+ String closeParen = tokens.getTokenString(token);
+ if (closeParen != "XPTRTOKEN_CLOSE_PAREN")
+ new InvalidXPointerException("SchemeDataNotFollowedByCloseParenthesis", xpointerString);
+ } else {
+ new InvalidXPointerException("SchemeDataNotFollowedByCloseParenthesis", xpointerString);
+ }
+
+ closeParenCount++;
+
+ while (tokens.hasMore()) {
+ if (tokens.getTokenString(tokens.peekToken()) != "XPTRTOKEN_OPEN_PAREN") {
+ break;
+ }
+ closeParenCount++;
+ }
+
+ // check if the number of open parenthesis are equal to the number of close parenthesis
+ if (openParenCount != closeParenCount) {
+ throw new InvalidXPointerException("UnbalancedParenthesisInXPointerExpression", xpointerString);
+ }
+
+ // Perform scheme specific parsing of the pointer part, make this more generic for any pointer part?
+ if (schemeName.equals(ELEMENT_SCHEME_NAME)) {
+ PointerPart elementSchemePointer = ElementPointerPart.parseFromString(schemeData);
+ xpointer.addPointerPart(elementSchemePointer);
+ } //Else an unknown scheme.
+ break;
+ }
+ default:
+ throw new InvalidXPointerException("InvalidXPointerExpression", xpointerString);
+ }
+ }
+
+ }
+
+ /**
+ * List of XPointer Framework tokens.
+ *
+ */
+ private static class Tokens {
+
+ /**
+ * XPointer Framework tokens
+ * [1] Pointer ::= Shorthand | SchemeBased
+ * [2] Shorthand ::= NCName
+ * [3] SchemeBased ::= PointerPart (S? PointerPart)*
+ * [4] PointerPart ::= SchemeName '(' SchemeData ')'
+ * [5] SchemeName ::= QName
+ * [6] SchemeData ::= EscapedData*
+ * [7] EscapedData ::= NormalChar | '^(' | '^)' | '^^' | '(' SchemeData ')'
+ * [8] NormalChar ::= UnicodeChar - [()^]
+ * [9] UnicodeChar ::= [#x0-#x10FFFF]
+ *
+ */
+ private static final int XPTRTOKEN_OPEN_PAREN = 0,
+ XPTRTOKEN_CLOSE_PAREN = 1, XPTRTOKEN_SHORTHAND = 2,
+ XPTRTOKEN_SCHEMENAME = 3, XPTRTOKEN_SCHEMEDATA = 4;
+
+ // Token count
+ private static final int INITIAL_TOKEN_COUNT = 1 << 8;
+
+ private int[] fTokens = new int[INITIAL_TOKEN_COUNT];
+
+ private int fTokenCount = 0;
+
+ // Current token position
+ private int fCurrentTokenIndex;
+
+ private Hashtable fTokenNames = new Hashtable();
+
+ /**
+ * Constructor
+ *
+ */
+ private Tokens() {
+
+ fTokenNames.put(new Integer(XPTRTOKEN_OPEN_PAREN),
+ "XPTRTOKEN_OPEN_PAREN");
+ fTokenNames.put(new Integer(XPTRTOKEN_CLOSE_PAREN),
+ "XPTRTOKEN_CLOSE_PAREN");
+ fTokenNames.put(new Integer(XPTRTOKEN_SHORTHAND),
+ "XPTRTOKEN_SHORTHAND");
+ fTokenNames.put(new Integer(XPTRTOKEN_SCHEMENAME),
+ "XPTRTOKEN_SCHEMENAME");
+ fTokenNames.put(new Integer(XPTRTOKEN_SCHEMEDATA),
+ "XPTRTOKEN_SCHEMEDATA");
+ }
+
+ /**
+ * Returns the token String
+ * @param token The index of the token
+ * @return String The token string
+ */
+ private String getTokenString(int token) {
+ return (String) fTokenNames.get(new Integer(token));
+ }
+
+ /**
+ * Add the specified string as a token
+ *
+ * @param token The token string
+ */
+ private void addToken(String tokenStr) {
+ Integer tokenInt = (Integer) fTokenNames.get(tokenStr);
+ if (tokenInt == null) {
+ tokenInt = new Integer(fTokenNames.size());
+ fTokenNames.put(tokenInt, tokenStr);
+ }
+ addToken(tokenInt.intValue());
+ }
+
+ /**
+ * Add the specified int token
+ *
+ * @param token The int specifying the token
+ */
+ private void addToken(int token) {
+ try {
+ fTokens[fTokenCount] = token;
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ int[] oldList = fTokens;
+ fTokens = new int[fTokenCount << 1];
+ System.arraycopy(oldList, 0, fTokens, 0, fTokenCount);
+ fTokens[fTokenCount] = token;
+ }
+ fTokenCount++;
+ }
+
+
+
+ /**
+ * Returns true if the {@link #getNextToken()} method
+ * returns a valid token.
+ */
+ private boolean hasMore() {
+ return fCurrentTokenIndex < fTokenCount;
+ }
+
+ /**
+ * Obtains the token at the current position, then advance
+ * the current position by one.
+ *
+ * throws If there's no such next token, this method throws
+ * <tt>new XNIException("XPointerProcessingError");</tt>.
+ */
+ private int nextToken() {
+ if (fCurrentTokenIndex == fTokenCount) {
+ throw new IndexOutOfBoundsException("There are no more tokens to return.");
+ }
+ return fTokens[fCurrentTokenIndex++];
+ }
+
+ /**
+ * Obtains the token at the current position, without advancing
+ * the current position.
+ *
+ * If there's no such next token, this method throws
+ * <tt>new XNIException("XPointerProcessingError");</tt>.
+ */
+ private int peekToken() {
+ if (fCurrentTokenIndex == fTokenCount) {
+ throw new IndexOutOfBoundsException("There are no more tokens to return.");
+ }
+ return fTokens[fCurrentTokenIndex];
+ }
+ }
+
+ /**
+ * The XPointer expression scanner. Scans the XPointer framework expression.
+ *
+ */
+ private static class Scanner {
+
+ /**
+ * 7-bit ASCII subset
+ *
+ * 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ * 0, 0, 0, 0, 0, 0, 0, 0, 0, HT, LF, 0, 0, CR, 0, 0, // 0
+ * 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
+ * SP, !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, // 2
+ * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, // 3
+ * @, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, // 4
+ * P, Q, R, S, T, U, V, W, X, Y, Z, [, \, ], ^, _, // 5
+ * `, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, // 6
+ * p, q, r, s, t, u, v, w, x, y, z, {, |, }, ~, DEL // 7
+ */
+ private static final byte CHARTYPE_INVALID = 0, // invalid XML character
+ CHARTYPE_OTHER = 1, // not special - one of "#%&;?\`{}~" or DEL
+ CHARTYPE_WHITESPACE = 2, // one of "\t\n\r " (0x09, 0x0A, 0x0D, 0x20)
+ CHARTYPE_CARRET = 3, // ^
+ CHARTYPE_OPEN_PAREN = 4, // '(' (0x28)
+ CHARTYPE_CLOSE_PAREN = 5, // ')' (0x29)
+ CHARTYPE_MINUS = 6, // '-' (0x2D)
+ CHARTYPE_PERIOD = 7, // '.' (0x2E)
+ CHARTYPE_SLASH = 8, // '/' (0x2F)
+ CHARTYPE_DIGIT = 9, // '0'-'9' (0x30 to 0x39)
+ CHARTYPE_COLON = 10, // ':' (0x3A)
+ CHARTYPE_EQUAL = 11, // '=' (0x3D)
+ CHARTYPE_LETTER = 12, // 'A'-'Z' or 'a'-'z' (0x41 to 0x5A and 0x61 to 0x7A)
+ CHARTYPE_UNDERSCORE = 13, // '_' (0x5F)
+ CHARTYPE_NONASCII = 14; // Non-ASCII Unicode codepoint (>= 0x80)
+
+ private static final byte[] fASCIICharMap = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2,
+ 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 2, 1, 1, 1, 1, 1, 1, 1, 4, 5, 1, 1, 1, 6, 7, 8, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 10, 1, 1, 11, 1, 1, 1, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 1, 1, 1, 3, 13, 1, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 1, 1, 1, 1, 1 };
+
+ /**
+ * Scans the XPointer Expression
+ *
+ */
+ private static boolean scanExpr(Tokens tokens, String data, int currentOffset, int endOffset) throws InvalidXPointerException {
+ int ch;
+ int openParen = 0;
+ int closeParen = 0;
+ int nameOffset, dataOffset;
+ boolean isQName = false;
+ String name = null;
+ String prefix = null;
+ String schemeData = null;
+ StringBuffer schemeDataBuff = new StringBuffer();
+
+ while (true) {
+
+ if (currentOffset == endOffset) {
+ break;
+ }
+ ch = data.charAt(currentOffset);
+
+ //
+ while (ch == ' ' || ch == 0x0A || ch == 0x09 || ch == 0x0D) {
+ if (++currentOffset == endOffset) {
+ break;
+ }
+ ch = data.charAt(currentOffset);
+ }
+ if (currentOffset == endOffset) {
+ break;
+ }
+
+ //
+ // [1] Pointer ::= Shorthand | SchemeBased
+ // [2] Shorthand ::= NCName
+ // [3] SchemeBased ::= PointerPart (S? PointerPart)*
+ // [4] PointerPart ::= SchemeName '(' SchemeData ')'
+ // [5] SchemeName ::= QName
+ // [6] SchemeData ::= EscapedData*
+ // [7] EscapedData ::= NormalChar | '^(' | '^)' | '^^' | '(' SchemeData ')'
+ // [8] NormalChar ::= UnicodeChar - [()^]
+ // [9] UnicodeChar ::= [#x0-#x10FFFF]
+ // [?] QName ::= (NCName ':')? NCName
+ // [?] NCName ::= (Letter | '_') (NCNameChar)*
+ // [?] NCNameChar ::= Letter | Digit | '.' | '-' | '_' (ascii subset of 'NCNameChar')
+ // [?] Letter ::= [A-Za-z] (ascii subset of 'Letter')
+ // [?] Digit ::= [0-9] (ascii subset of 'Digit')
+ //
+ byte chartype = (ch >= 0x80) ? CHARTYPE_NONASCII
+ : fASCIICharMap[ch];
+
+ switch (chartype) {
+
+ case CHARTYPE_OPEN_PAREN: // '('
+ addToken(tokens, Tokens.XPTRTOKEN_OPEN_PAREN);
+ openParen++;
+ ++currentOffset;
+ break;
+
+ case CHARTYPE_CLOSE_PAREN: // ')'
+ addToken(tokens, Tokens.XPTRTOKEN_CLOSE_PAREN);
+ closeParen++;
+ ++currentOffset;
+ break;
+
+ case CHARTYPE_CARRET:
+ case CHARTYPE_COLON:
+ case CHARTYPE_DIGIT:
+ case CHARTYPE_EQUAL:
+ case CHARTYPE_LETTER:
+ case CHARTYPE_MINUS:
+ case CHARTYPE_NONASCII:
+ case CHARTYPE_OTHER:
+ case CHARTYPE_PERIOD:
+ case CHARTYPE_SLASH:
+ case CHARTYPE_UNDERSCORE:
+ case CHARTYPE_WHITESPACE:
+ // Scanning SchemeName | Shorthand
+ if (openParen == 0) {
+ nameOffset = currentOffset;
+ currentOffset = scanNCName(data, endOffset,
+ currentOffset);
+
+ if (currentOffset == nameOffset)
+ throw new InvalidXPointerException("InvalidShortHandPointer", data);
+
+ if (currentOffset < endOffset) {
+ ch = data.charAt(currentOffset);
+ } else {
+ ch = -1;
+ }
+
+ name = data.substring(nameOffset, currentOffset).intern();
+ prefix = "".intern();
+
+ // The name is a QName => a SchemeName
+ if (ch == ':') {
+ if (++currentOffset == endOffset) {
+ return false;
+ }
+
+ ch = data.charAt(currentOffset);
+ prefix = name;
+ nameOffset = currentOffset;
+ currentOffset = scanNCName(data, endOffset,
+ currentOffset);
+
+ if (currentOffset == nameOffset) {
+ return false;
+ }
+
+ if (currentOffset < endOffset) {
+ ch = data.charAt(currentOffset);
+ } else {
+ ch = -1;
+ }
+
+ isQName = true;
+ name = data.substring(nameOffset, currentOffset).intern();
+ }
+
+ // REVISIT:
+ if (currentOffset != endOffset) {
+ addToken(tokens, Tokens.XPTRTOKEN_SCHEMENAME);
+ tokens.addToken(prefix);
+ tokens.addToken(name);
+ isQName = false;
+ } else if (currentOffset == endOffset) {
+ // NCName => Shorthand
+ addToken(tokens, Tokens.XPTRTOKEN_SHORTHAND);
+ tokens.addToken(name);
+ isQName = false;
+ }
+
+ // reset open/close paren for the next pointer part
+ closeParen = 0;
+
+ break;
+
+ } else if (openParen > 0 && closeParen == 0 && name != null) {
+ // Scanning SchemeData
+ dataOffset = currentOffset;
+ currentOffset = scanData(data, schemeDataBuff,
+ endOffset, currentOffset);
+
+ if (currentOffset == dataOffset)
+ throw new InvalidXPointerException("InvalidSchemeDataInXPointer", data);
+
+ if (currentOffset < endOffset) {
+ ch = data.charAt(currentOffset);
+ } else {
+ ch = -1;
+ }
+
+ schemeData = schemeDataBuff.toString().intern();
+ addToken(tokens, Tokens.XPTRTOKEN_SCHEMEDATA);
+ tokens.addToken(schemeData);
+
+ // reset open/close paren for the next pointer part
+ openParen = 0;
+ schemeDataBuff.delete(0, schemeDataBuff.length());
+
+ } else {
+ // ex. schemeName()
+ // Should we throw an exception with a more suitable message instead??
+ return false;
+ }
+ }
+ } // end while
+ return true;
+ }
+
+ /**
+ * Scans a NCName.
+ * From Namespaces in XML
+ * [5] NCName ::= (Letter | '_') (NCNameChar)*
+ * [6] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
+ *
+ * @param data A String containing the XPointer expression
+ * @param endOffset The int XPointer expression length
+ * @param currentOffset An int representing the current position of the XPointer expression pointer
+ */
+ private static int scanNCName(String data, int endOffset, int currentOffset) {
+ int ch = data.charAt(currentOffset);
+ if (ch >= 0x80) {
+ if (!XMLChar.isNameStart(ch)) {
+ return currentOffset;
+ }
+ } else {
+ byte chartype = fASCIICharMap[ch];
+ if (chartype != CHARTYPE_LETTER
+ && chartype != CHARTYPE_UNDERSCORE) {
+ return currentOffset;
+ }
+ }
+
+ //while (currentOffset++ < endOffset) {
+ while (++currentOffset < endOffset) {
+ ch = data.charAt(currentOffset);
+ if (ch >= 0x80) {
+ if (!XMLChar.isName(ch)) {
+ break;
+ }
+ } else {
+ byte chartype = fASCIICharMap[ch];
+ if (chartype != CHARTYPE_LETTER
+ && chartype != CHARTYPE_DIGIT
+ && chartype != CHARTYPE_PERIOD
+ && chartype != CHARTYPE_MINUS
+ && chartype != CHARTYPE_UNDERSCORE) {
+ break;
+ }
+ }
+ }
+ return currentOffset;
+ }
+
+ /**
+ * Scans the SchemeData.
+ * [6] SchemeData ::= EscapedData*
+ * [7] EscapedData ::= NormalChar | '^(' | '^)' | '^^' | '(' SchemeData ')'
+ * [8] NormalChar ::= UnicodeChar - [()^]
+ * [9] UnicodeChar ::= [#x0-#x10FFFF]
+ *
+ */
+ private static int scanData(String data, StringBuffer schemeData,
+ int endOffset, int currentOffset) {
+ while (true) {
+
+ if (currentOffset == endOffset) {
+ break;
+ }
+
+ int ch = data.charAt(currentOffset);
+ byte chartype = (ch >= 0x80) ? CHARTYPE_NONASCII
+ : fASCIICharMap[ch];
+
+ if (chartype == CHARTYPE_OPEN_PAREN) {
+ schemeData.append(ch);
+ //schemeData.append(Tokens.XPTRTOKEN_OPEN_PAREN);
+ currentOffset = scanData(data, schemeData, endOffset,
+ ++currentOffset);
+ if (currentOffset == endOffset) {
+ return currentOffset;
+ }
+
+ ch = data.charAt(currentOffset);
+ chartype = (ch >= 0x80) ? CHARTYPE_NONASCII
+ : fASCIICharMap[ch];
+
+ if (chartype != CHARTYPE_CLOSE_PAREN) {
+ return endOffset;
+ }
+ schemeData.append((char) ch);
+ ++currentOffset;//
+
+ } else if (chartype == CHARTYPE_CLOSE_PAREN) {
+ return currentOffset;
+
+ } else if (chartype == CHARTYPE_CARRET) {
+ ch = data.charAt(++currentOffset);
+ chartype = (ch >= 0x80) ? CHARTYPE_NONASCII
+ : fASCIICharMap[ch];
+
+ if (chartype != CHARTYPE_CARRET
+ && chartype != CHARTYPE_OPEN_PAREN
+ && chartype != CHARTYPE_CLOSE_PAREN) {
+ break;
+ }
+ schemeData.append((char) ch);
+ ++currentOffset;
+
+ } else {
+ schemeData.append((char) ch);
+ ++currentOffset;//
+ }
+ }
+
+ return currentOffset;
+ }
+
+ //
+ // Protected methods
+ //
+
+ /**
+ * This method adds the specified token to the token list. By
+ * default, this method allows all tokens. However, subclasses
+ * of the XPathExprScanner can override this method in order
+ * to disallow certain tokens from being used in the scanned
+ * XPath expression. This is a convenient way of allowing only
+ * a subset of XPath.
+ */
+ protected static void addToken(Tokens tokens, int token) {
+ if (token == Tokens.XPTRTOKEN_OPEN_PAREN
+ || token == Tokens.XPTRTOKEN_CLOSE_PAREN
+ || token == Tokens.XPTRTOKEN_SCHEMENAME
+ || token == Tokens.XPTRTOKEN_SCHEMEDATA
+ || token == Tokens.XPTRTOKEN_SHORTHAND) {
+ tokens.addToken(token);
+ return;
+ }
+ throw new IllegalArgumentException("InvalidXPointerToken");
+ }
+
+ } // class Scanner
+}
Propchange: webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XPointerParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XmlnsPointerPart.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XmlnsPointerPart.java?rev=609714&view=auto
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XmlnsPointerPart.java (added)
+++ webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XmlnsPointerPart.java Mon Jan 7 09:36:13 2008
@@ -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 XmlnsPointerPart implements PointerPart {
+ private final NCName prefix;
+ private final String namespace;
+
+ public XmlnsPointerPart(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.
+ }
+}
Propchange: webservices/woden/branches/woden65/src/org/apache/woden/xpointer/XmlnsPointerPart.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/woden/branches/woden65/test/org/apache/woden/OMWSDLReaderTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/OMWSDLReaderTest.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/OMWSDLReaderTest.java (original)
+++ webservices/woden/branches/woden65/test/org/apache/woden/OMWSDLReaderTest.java Mon Jan 7 09:36:13 2008
@@ -29,15 +29,13 @@
private WSDLFactory omWSDLFactory = null;
private WSDLReader omWSDLReader = null;
- private ErrorHandler handler = null;
public static Test suite(){
return new TestSuite(OMWSDLReaderTest.class);
}
protected void setUp() throws Exception{
-
- handler = new TestErrorHandler();
+ //Create wsdl20 factory and reader.
try{
omWSDLFactory = WSDLFactory.newInstance("org.apache.woden.internal.OMWSDLFactory");
omWSDLReader = omWSDLFactory.newWSDLReader();
@@ -45,13 +43,15 @@
catch (Exception e){
e.printStackTrace();
}
+ //Set errorHandler
+ omWSDLReader.getErrorReporter().setErrorHandler(new TestErrorHandler());
}
public void testReadValidWSDL20FromOM(){
Description desc = null;
try{
URL wsdlURL = getClass().getClassLoader().getResource("org/apache/woden/primer-hotelReservationService.wsdl");
- desc = omWSDLReader.readWSDL(wsdlURL.toString(), handler);
+ desc = omWSDLReader.readWSDL(wsdlURL.toString());
}
catch(WSDLException e){
fail("Unexpected exception: " + e.getMessage());
@@ -62,12 +62,59 @@
public void testReadInvalidWSDL20FromOM(){
try{
URL wsdlURL = getClass().getClassLoader().getResource("org/apache/woden/badDescriptionTags.wsdl");
- omWSDLReader.readWSDL(wsdlURL.toString(), handler);
+ omWSDLReader.readWSDL(wsdlURL.toString());
fail("Expected a WSDLException because the \"description\" tag was deliberately misspelt.");
}
catch(WSDLException e){
assertTrue("Expected a WSDLException with message containing \"WSDL501\", but got: " + e.getMessage() ,
e.getMessage().indexOf("WSDL501") > -1);
+ }
+ }
+
+ public void testReadEmbeddedWSDLSourceFromOM() {
+ Description desc = null;
+ //Load in a WSDL 2.0 file
+ URL wsdlURL = getClass().getClassLoader().getResource("org/apache/woden/embeded.xml");
+
+ //Good Tests.
+ String[] goodFragids = new String[]{
+ //Shorthand
+ "#wsdlRoot",
+ //element() scheme.
+ "#element(wsdlRoot)", "#element(first/1/2)", "#element(/1/1/2)", "#element(second/2)"
+ };
+
+ //Test fragids
+ for (int i=0; i< goodFragids.length; i++) {
+ try {
+ desc = omWSDLReader.readWSDL(wsdlURL.toString() + goodFragids[i]);
+ } catch(WSDLException e) {
+ fail("Failed with unexpected exception: " + e);
+ }
+ assertNotNull("Failed to load the embedded wsdl20 description with fragid: " + goodFragids[i], desc);
+ }
+
+ //Bad Tests - Invalid XPointer. (Can't programmatically see between bad syntax and not pointing unless we modify WSDLException)
+ String[] badFragids = new String[]{
+ //Shorthand - bad syntax.
+ "#wsdl#Root", "#wsd(Root",
+ //Shorthand - don't point.
+ "#wsdlRootElement", "#nonexistentFragment",
+ //element() scheme. - bad syntax.
+ "#element(wsdlRoot//)", "#element(/wsdlRoot)", "#element(wsdlRoot/)", "#element(wsdl,Root/1/1/2)", "#element(second/a)",
+ //element() scheme - don't point.
+ "#element(wsdlRoot/20)", "#element(/4/1/2)", "#element(second/3)"
+ };
+
+ //Test fragids
+ for (int i=0; i< badFragids.length; i++) {
+ try {
+ desc = omWSDLReader.readWSDL(wsdlURL.toString() + badFragids[i]);
+ } catch(WSDLException e) {
+ assertEquals("Expected exception WSDL531 for invalid XPoitner: " + badFragids[i] + ", but got the exception: " + e, "PARSER_ERROR", e.getFaultCode());
+ continue;
+ }
+ fail("XPointer parse didn't not throw exception for invalid fragid: " + badFragids[i]);
}
}
}
Modified: webservices/woden/branches/woden65/test/org/apache/woden/WSDLReaderTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/WSDLReaderTest.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/WSDLReaderTest.java (original)
+++ webservices/woden/branches/woden65/test/org/apache/woden/WSDLReaderTest.java Mon Jan 7 09:36:13 2008
@@ -39,7 +39,6 @@
{
private WSDLFactory factory = null;
private WSDLReader reader = null;
- private ErrorHandler handler = null;
public static Test suite()
{
@@ -48,7 +47,7 @@
protected void setUp() throws Exception
{
- handler = new TestErrorHandler();
+ //Create wsdl20 factory and reader.
try
{
factory = WSDLFactory.newInstance();
@@ -57,13 +56,14 @@
catch (Exception e)
{
}
+ //Set error handler.
+ reader.getErrorReporter().setErrorHandler(new TestErrorHandler());
}
protected void tearDown() throws Exception
{
factory = null;
reader = null;
- handler = null;
}
public void testReadValidWSDL20()
@@ -72,7 +72,7 @@
try
{
URL wsdlURL = getClass().getClassLoader().getResource("org/apache/woden/primer-hotelReservationService.wsdl");
- desc = reader.readWSDL(wsdlURL.toString(), handler);
+ desc = reader.readWSDL(wsdlURL.toString());
}
catch(WSDLException e)
{
@@ -86,7 +86,7 @@
try
{
URL wsdlURL = getClass().getClassLoader().getResource("org/apache/woden/badDescriptionTags.wsdl");
- reader.readWSDL(wsdlURL.toString(), handler);
+ reader.readWSDL(wsdlURL.toString());
fail("Expected a WSDLException because the \"description\" tag was deliberately misspelt.");
}
catch(WSDLException e)
@@ -124,7 +124,7 @@
WSDLSource wsdlSource = reader.createWSDLSource();
wsdlSource.setBaseURI(wsdlURI);
wsdlSource.setSource(doc);
- desc = reader.readWSDL(wsdlSource, handler);
+ desc = reader.readWSDL(wsdlSource);
}
catch(WSDLException e)
{
@@ -147,12 +147,59 @@
WSDLSource wsdlSource = reader.createWSDLSource();
wsdlSource.setBaseURI(wsdlURI);
wsdlSource.setSource(is);
- desc = reader.readWSDL(wsdlSource, handler);
+ desc = reader.readWSDL(wsdlSource);
}
catch(WSDLException e)
{
fail("Unexpected exception: " + e.getMessage());
}
assertNotNull("The description returned is null.", desc);
+ }
+
+ public void testReadEmbeddedWSDLSource() {
+ Description desc = null;
+ //Load in a WSDL 2.0 file
+ URL wsdlURL = getClass().getClassLoader().getResource("org/apache/woden/embeded.xml");
+
+ //Good Tests.
+ String[] goodFragids = new String[]{
+ //Shorthand
+ "#wsdlRoot",
+ //element() scheme.
+ "#element(wsdlRoot)", "#element(first/1/2)", "#element(/1/1/2)", "#element(second/2)"
+ };
+
+ //Test fragids
+ for (int i=0; i< goodFragids.length; i++) {
+ try {
+ desc = reader.readWSDL(wsdlURL.toString() + goodFragids[i]);
+ } catch(WSDLException e) {
+ fail("Failed with unexpected exception: " + e);
+ }
+ assertNotNull("Failed to load the embedded wsdl20 description with fragid: " + goodFragids[i], desc);
+ }
+
+ //Bad Tests - Invalid XPointer. (Can't programmatically see between bad syntax and not pointing unless we modify WSDLException)
+ String[] badFragids = new String[]{
+ //Shorthand - bad syntax.
+ "#wsdl#Root", "#wsd(Root",
+ //Shorthand - don't point.
+ "#wsdlRootElement", "#nonexistentFragment",
+ //element() scheme. - bad syntax.
+ "#element(wsdlRoot//)", "#element(/wsdlRoot)", "#element(wsdlRoot/)", "#element(wsdl,Root/1/1/2)", "#element(second/a)",
+ //element() scheme - don't point.
+ "#element(wsdlRoot/20)", "#element(/4/1/2)", "#element(second/3)"
+ };
+
+ //Test fragids
+ for (int i=0; i< badFragids.length; i++) {
+ try {
+ desc = reader.readWSDL(wsdlURL.toString() + badFragids[i]);
+ } catch(WSDLException e) {
+ assertEquals("Expected exception PARSE_ERROR for invalid XPoitner: " + badFragids[i] + ", but got the exception: " + e, "PARSER_ERROR", e.getFaultCode());
+ continue;
+ }
+ fail("XPointer parse didn't not throw exception for invalid fragid: " + badFragids[i]);
+ }
}
}
Added: webservices/woden/branches/woden65/test/org/apache/woden/embeded.xml
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/embeded.xml?rev=609714&view=auto
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/embeded.xml (added)
+++ webservices/woden/branches/woden65/test/org/apache/woden/embeded.xml Mon Jan 7 09:36:13 2008
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ !
+ ! 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.
+ !-->
+<root xml:id="first" name="first">
+ <anotherNode xml:id="second">
+ <finalNode xml:id="third" />
+ <description
+ xml:id="wsdlRoot"
+ xmlns="http://www.w3.org/ns/wsdl"
+ targetNamespace= "http://greath.example.com/2004/wsdl/resSvc"
+ xmlns:tns= "http://greath.example.com/2004/wsdl/resSvc"
+ xmlns:ghns = "http://greath.example.com/2004/schemas/resSvc"
+ xmlns:wsoap= "http://www.w3.org/ns/wsdl/soap"
+ xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
+ xmlns:wsdlx= "http://www.w3.org/ns/wsdl-extensions">
+
+ <documentation>
+ This document describes the GreatH Web service. Additional
+ application-level requirements for use of this service --
+ beyond what WSDL 2.0 is able to describe -- are available
+ at http://greath.example.com/2004/reservation-documentation.html
+ </documentation>
+
+ <types>
+ <xs:schema
+ targetNamespace="http://greath.example.com/2004/schemas/resSvc"
+ xmlns="http://greath.example.com/2004/schemas/resSvc"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:element name="checkAvailability" type="tCheckAvailability"/>
+ <xs:complexType name="tCheckAvailability">
+ <xs:sequence>
+ <xs:element name="checkInDate" type="xs:date"/>
+ <xs:element name="checkOutDate" type="xs:date"/>
+ <xs:element name="roomType" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="checkAvailabilityResponse" type="xs:double"/>
+
+ <xs:element name="invalidDataError" type="xs:string"/>
+
+ </xs:schema>
+ </types>
+
+ <interface name = "reservationInterface" >
+
+ <fault name = "invalidDataFault"
+ element = "ghns:invalidDataError"/>
+
+ <operation name="opCheckAvailability"
+ pattern="http://www.w3.org/ns/wsdl/in-out"
+ style="http://www.w3.org/ns/wsdl/style/iri"
+ wsdlx:safe = "true">
+ <input messageLabel="In"
+ element="ghns:checkAvailability" />
+ <output messageLabel="Out"
+ element="ghns:checkAvailabilityResponse" />
+ <outfault ref="tns:invalidDataFault" messageLabel="Out"/>
+ </operation>
+
+ </interface>
+
+ <binding name="reservationSOAPBinding"
+ interface="tns:reservationInterface"
+ type="http://www.w3.org/ns/wsdl/soap"
+ wsoap:version="1.2"
+ wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP/">
+
+ <fault ref="tns:invalidDataFault"
+ wsoap:code="soap:Sender"/>
+
+ <operation ref="tns:opCheckAvailability" wsoap:mep="http://www.w3.org/2003/05/soap/mep/soap-response">
+ <input />
+ <output />
+ <outfault ref="tns:invalidDataFault" />
+ </operation>
+
+ </binding>
+
+ <service name="reservationService"
+ interface="tns:reservationInterface">
+
+ <endpoint name="reservationEndpoint"
+ binding="tns:reservationSOAPBinding"
+ address ="http://greath.example.com/2004/reservation"/>
+
+ </service>
+
+ </description>
+ </anotherNode>
+</root>
Propchange: webservices/woden/branches/woden65/test/org/apache/woden/embeded.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java (original)
+++ webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLComponentValidatorTest.java Mon Jan 7 09:36:13 2008
@@ -31,17 +31,14 @@
import org.apache.woden.internal.ErrorReporterImpl;
import org.apache.woden.internal.wsdl20.BindingFaultImpl;
import org.apache.woden.internal.wsdl20.BindingFaultReferenceImpl;
-import org.apache.woden.internal.wsdl20.Constants;
-import org.apache.woden.internal.wsdl20.DescriptionImpl;
-import org.apache.woden.internal.wsdl20.ElementDeclarationImpl;
import org.apache.woden.internal.wsdl20.EndpointImpl;
import org.apache.woden.internal.wsdl20.InterfaceFaultReferenceImpl;
import org.apache.woden.internal.wsdl20.InterfaceImpl;
import org.apache.woden.internal.wsdl20.InterfaceMessageReferenceImpl;
import org.apache.woden.internal.wsdl20.ServiceImpl;
-import org.apache.woden.internal.wsdl20.extensions.PopulatedExtensionRegistry;
import org.apache.woden.tests.TestErrorHandler;
import org.apache.woden.types.NCName;
+import org.apache.woden.types.QNameTokenUnion;
import org.apache.woden.wsdl20.Binding;
import org.apache.woden.wsdl20.BindingFault;
import org.apache.woden.wsdl20.BindingFaultReference;
@@ -103,7 +100,7 @@
{
val = new WSDLComponentValidator();
handler = new TestErrorHandler();
- reporter = new ErrorReporterImpl();
+ reporter = WSDLFactory.newInstance().newWSDLReader().getErrorReporter();
reporter.setErrorHandler(handler);
}
@@ -400,12 +397,10 @@
/**
* Test that the testAssertionInterfaceMessageReference1028 method returns
* true if the message content model is #any or #none and the element
- * declartion is empty, false otherwise.
+ * declaration is empty, false otherwise.
*/
public void testTestAssertionInterfaceMessageReference1028()
{
- QName name1 = new QName("http://www.sample.org", "name1");
-
WSDLFactory factory = null;
try {
factory = WSDLFactory.newInstance();
@@ -417,19 +412,16 @@
try
{
DescriptionElement descEl = factory.newDescription();
- Description descComp = descEl.toComponent();
- ElementDeclarationImpl ed = new ElementDeclarationImpl();
- ed.setName(name1);
- ((DescriptionImpl)descEl).addElementDeclaration(ed);
InterfaceElement interfac = descEl.addInterfaceElement();
InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
-
InterfaceMessageReferenceElement interfaceMessageReference = oper.addInterfaceMessageReferenceElement();
- interfaceMessageReference.setMessageContentModel(Constants.NMTOKEN_ANY);
+ interfaceMessageReference.setElement(QNameTokenUnion.ANY);
- descComp.getInterfaces(); //init Interface's ref to its Description
+ Description descComp = descEl.toComponent(); //initialise Interface's ref to its Description
+ InterfaceMessageReference msgRefComp =
+ descComp.getInterfaces()[0].getInterfaceOperations()[0].getInterfaceMessageReferences()[0];
- if(!val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)interfaceMessageReference, reporter))
+ if(!val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)msgRefComp, reporter))
{
fail("The testAssertionInterfaceMessageReference1028 method returned false for an interface message reference with the message content model #any and an empty element declaration.");
}
@@ -443,19 +435,16 @@
try
{
DescriptionElement descEl = factory.newDescription();
- Description descComp = descEl.toComponent();
- ElementDeclarationImpl ed = new ElementDeclarationImpl();
- ed.setName(name1);
- ((DescriptionImpl)descEl).addElementDeclaration(ed);
InterfaceElement interfac = descEl.addInterfaceElement();
InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
-
InterfaceMessageReferenceElement interfaceMessageReference = oper.addInterfaceMessageReferenceElement();
- interfaceMessageReference.setMessageContentModel(Constants.NMTOKEN_NONE);
+ interfaceMessageReference.setElement(QNameTokenUnion.NONE);
- descComp.getInterfaces(); //init Interface's ref to its Description
-
- if(!val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)interfaceMessageReference, reporter))
+ Description descComp = descEl.toComponent(); //initialise Interface's ref to its Description
+ InterfaceMessageReference msgRefComp =
+ descComp.getInterfaces()[0].getInterfaceOperations()[0].getInterfaceMessageReferences()[0];
+
+ if(!val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)msgRefComp, reporter))
{
fail("The testAssertionInterfaceMessageReference1028 method returned false for an interface message reference with the message content model #none and an empty element declaration.");
}
@@ -464,111 +453,6 @@
{
fail("There was a problem running the test assertion method " + e);
}
-
- // Test that the method returns false if the message content model is #any and the element declaration is not empty.
- try
- {
- DescriptionElement descEl = factory.newDescription();
- Description descComp = descEl.toComponent();
- ElementDeclarationImpl ed = new ElementDeclarationImpl();
- ed.setName(name1);
- ((DescriptionImpl)descEl).addElementDeclaration(ed);
- InterfaceElement interfac = descEl.addInterfaceElement();
- InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
-
- InterfaceMessageReferenceElement interfaceMessageReference = oper.addInterfaceMessageReferenceElement();
- interfaceMessageReference.setMessageContentModel(Constants.NMTOKEN_ANY);
- interfaceMessageReference.setElementName(name1);
-
- descComp.getInterfaces(); //init Interface's ref to its Description
-
- if(val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)interfaceMessageReference, reporter))
- {
- fail("The testAssertionInterfaceMessageReference1028 method returned true for an interface message reference with the message content model #any and a non-empty element declaration.");
- }
- }
- catch(WSDLException e)
- {
- fail("There was a problem running the test assertion method " + e);
- }
-
- // Test that the method returns false if the message content model is #none and the element declaration is not empty.
- try
- {
- DescriptionElement descEl = factory.newDescription();
- ElementDeclarationImpl ed = new ElementDeclarationImpl();
- ed.setName(name1);
- ((DescriptionImpl)descEl).addElementDeclaration(ed);
- InterfaceElement interfac = descEl.addInterfaceElement();
- InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
-
- InterfaceMessageReferenceElement interfaceMessageReference = oper.addInterfaceMessageReferenceElement();
- interfaceMessageReference.setMessageContentModel(Constants.NMTOKEN_NONE);
- interfaceMessageReference.setElementName(name1);
-
- descEl.toComponent().getInterfaces(); //init Interface's ref to its Description
-
- if(val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)interfaceMessageReference, reporter))
- {
- fail("The testAssertionInterfaceMessageReference1028 method returned true for an interface message reference with the message content model #none and a non-empty element declaration.");
- }
- }
- catch(WSDLException e)
- {
- fail("There was a problem running the test assertion method " + e);
- }
-
- // Test that the method returns true if the message content model is #other and the element declaration is not empty.
- try
- {
- DescriptionElement descEl = factory.newDescription();
- ElementDeclarationImpl ed = new ElementDeclarationImpl();
- ed.setName(name1);
- ((DescriptionImpl)descEl).addElementDeclaration(ed);
- InterfaceElement interfac = descEl.addInterfaceElement();
- InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
-
- InterfaceMessageReferenceElement interfaceMessageReference = oper.addInterfaceMessageReferenceElement();
- interfaceMessageReference.setMessageContentModel(Constants.NMTOKEN_OTHER);
- interfaceMessageReference.setElementName(name1);
-
- descEl.toComponent().getInterfaces(); //init Interface's ref to its Description
-
- if(!val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)interfaceMessageReference, reporter))
- {
- fail("The testAssertionInterfaceMessageReference1028 method returned false for an interface message reference with the message content model #other and a non-empty element declaration.");
- }
- }
- catch(WSDLException e)
- {
- fail("There was a problem running the test assertion method " + e);
- }
-
- // Test that the method returns true if the message content model is #element and the element declaration is not empty.
- try
- {
- DescriptionElement descEl = factory.newDescription();
- ElementDeclarationImpl ed = new ElementDeclarationImpl();
- ed.setName(name1);
- ((DescriptionImpl)descEl).addElementDeclaration(ed);
- InterfaceElement interfac = descEl.addInterfaceElement();
- InterfaceOperationElement oper = interfac.addInterfaceOperationElement();
-
- InterfaceMessageReferenceElement interfaceMessageReference = oper.addInterfaceMessageReferenceElement();
- interfaceMessageReference.setMessageContentModel(Constants.NMTOKEN_ELEMENT);
- interfaceMessageReference.setElementName(name1);
-
- descEl.toComponent().getInterfaces(); //init Interface's ref to its Description
-
- if(!val.testAssertionInterfaceMessageReference1028((InterfaceMessageReferenceImpl)interfaceMessageReference, reporter))
- {
- fail("The testAssertionInterfaceMessageReference1028 method returned false for an interface message reference with the message content model #element and a non-empty element declaration.");
- }
- }
- catch(WSDLException e)
- {
- fail("There was a problem running the test assertion method " + e);
- }
}
/**
Modified: webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java (original)
+++ webservices/woden/branches/woden65/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java Mon Jan 7 09:36:13 2008
@@ -75,7 +75,8 @@
{
val = new WSDLDocumentValidator();
handler = new TestErrorHandler();
- reporter = new ErrorReporterImpl();
+
+ reporter = WSDLFactory.newInstance().newWSDLReader().getErrorReporter();
reporter.setErrorHandler(handler);
}
@@ -100,7 +101,7 @@
handler.reset();
try
{
- DescriptionElement desc = new DOMWSDLFactory().newDescription();
+ DescriptionElement desc = WSDLFactory.newInstance().newDescription();
desc.setTargetNamespace(new URI("http://www.sample.org"));
if(!val.testAssertionDescription1006(desc, reporter))
@@ -117,7 +118,7 @@
handler.reset();
try
{
- DescriptionElement desc = new DOMWSDLFactory().newDescription();
+ DescriptionElement desc = WSDLFactory.newInstance().newDescription();
desc.setTargetNamespace(new URI("//www.sample.org"));
boolean isValid = val.testAssertionDescription1006(desc, reporter);
if(isValid)
Modified: webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsDOM.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsDOM.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsDOM.java (original)
+++ webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsDOM.java Mon Jan 7 09:36:13 2008
@@ -41,6 +41,7 @@
import org.apache.woden.wsdl20.InterfaceTest;
import org.apache.woden.wsdl20.ServiceTest;
import org.apache.woden.wsdl20.TypeDefinitionTest;
+import org.apache.woden.wsdl20.extensions.ExtensionRegistryTest;
import org.apache.woden.wsdl20.extensions.http.HTTPBindingExtensionsTest;
import org.apache.woden.wsdl20.extensions.http.HTTPBindingFaultExtensionsTest;
import org.apache.woden.wsdl20.extensions.http.HTTPBindingMessageReferenceExtensionsTest;
@@ -74,6 +75,10 @@
import org.apache.woden.wsdl20.xml.TypesElementTest;
import org.apache.woden.xml.IntOrTokenAttrTest;
import org.apache.woden.xml.TokenAttrTest;
+import org.apache.woden.xpointer.XPointerTest;
+
+import testcase.extensions.foo.FooBindingExtensionsTest;
+import testcase.resolver.schemaloc.SchemaLocationTest;
public class AllWodenTestsDOM extends TestSuite
{
@@ -101,7 +106,7 @@
addTest(WSDLFactoryTest.suite());
addTest(WSDLReaderTest.suite());
addTest(DOMXMLElementTest.suite());
- addTest(W3CTestSuiteTest.suite());
+ //addTest(W3CTestSuiteTest.suite()); W3C testsuite is run via /ant-test/build.xml and results are compared to W3C baseline
addTestSuite(ReaderFeaturesTest.class);
addTest(WSDLDocumentValidatorTest.suite());
addTest(WSDLComponentValidatorTest.suite());
@@ -154,6 +159,10 @@
addTest(BindingMessageReferenceTest.suite());
addTest(DocumentationElementTest.suite());
addTest(FragmentIdentificationTest.suite());
+ addTest(ExtensionRegistryTest.suite());
+ addTest(FooBindingExtensionsTest.suite());
+ addTest(XPointerTest.suite());
+ addTest(SchemaLocationTest.suite());
//TODO in-progress 30May06 tests for BindingOpExt and BindingMsgRefExt
}
Modified: webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsOM.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsOM.java?rev=609714&r1=609713&r2=609714&view=diff
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsOM.java (original)
+++ webservices/woden/branches/woden65/test/org/apache/woden/tests/AllWodenTestsOM.java Mon Jan 7 09:36:13 2008
@@ -49,7 +49,7 @@
addTest(OMWSDLFactoryTest.suite());
addTest(OMWSDLReaderTest.suite());
- addTest(OMW3CTestSuiteTest.suite());
+ //addTest(OMW3CTestSuiteTest.suite()); W3C testsuite is run via /ant-test/build.xml and results are compared to W3C baseline.
addTest(OMServiceElementTest.suite());
addTest(OMEndpointElementTest.suite());
addTest(OMSimpleURIResolverTest.suite());
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org