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/09/11 01:04:05 UTC
svn commit: r574400 [1/2] - in /incubator/woden/trunk/java:
src/org/apache/woden/internal/ src/org/apache/woden/internal/util/om/
src/org/apache/woden/internal/xpointer/
src/org/apache/woden/wsdl20/fragids/ src/org/apache/woden/xpointer/
test/org/apach...
Author: jkaputin
Date: Mon Sep 10 16:04:02 2007
New Revision: 574400
URL: http://svn.apache.org/viewvc?rev=574400&view=rev
Log:
WODEN-115
Dan Harvey's patch to support description element
nested within an XML document (i.e. not the root
element)
Added:
incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/
incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java (with props)
incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/OMXMLElementEvaluator.java (with props)
incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/XMLElementEvaluator.java (with props)
incubator/woden/trunk/java/src/org/apache/woden/xpointer/ElementPointerPart.java (with props)
incubator/woden/trunk/java/src/org/apache/woden/xpointer/InvalidXPointerException.java (with props)
incubator/woden/trunk/java/src/org/apache/woden/xpointer/XPointerParser.java (with props)
incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPointerPart.java
- copied, changed from r573600, incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPart.java
incubator/woden/trunk/java/test/org/apache/woden/embeded.xml (with props)
incubator/woden/trunk/java/test/org/apache/woden/xpointer/
incubator/woden/trunk/java/test/org/apache/woden/xpointer/XPointerTest.java (with props)
Removed:
incubator/woden/trunk/java/src/org/apache/woden/xpointer/XmlnsPart.java
Modified:
incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java
incubator/woden/trunk/java/src/org/apache/woden/internal/Messages.properties
incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java
incubator/woden/trunk/java/src/org/apache/woden/internal/util/om/OMUtils.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultReferencePart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingMessageReferencePart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingOperationPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ComponentPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/DescriptionPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ElementDeclarationPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/EndpointPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ExtensionsPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/FragmentIdentifier.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultReferencePart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceMessageReferencePart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceOperationPart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfacePart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ServicePart.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java
incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java
incubator/woden/trunk/java/src/org/apache/woden/xpointer/XPointer.java
incubator/woden/trunk/java/test/org/apache/woden/OMWSDLReaderTest.java
incubator/woden/trunk/java/test/org/apache/woden/WSDLReaderTest.java
incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
incubator/woden/trunk/java/test/org/apache/woden/wsdl20/fragids/FragmentIdentificationTest.java
Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java Mon Sep 10 16:04:02 2007
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Map;
@@ -42,6 +43,7 @@
import org.apache.woden.internal.wsdl20.Constants;
import org.apache.woden.internal.wsdl20.validation.WSDLComponentValidator;
import org.apache.woden.internal.wsdl20.validation.WSDLDocumentValidator;
+import org.apache.woden.internal.xpointer.DOMXMLElementEvaluator;
import org.apache.woden.schema.Schema;
import org.apache.woden.wsdl20.Description;
import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
@@ -51,6 +53,8 @@
import org.apache.woden.wsdl20.xml.TypesElement;
import org.apache.woden.wsdl20.xml.WSDLElement;
import org.apache.woden.xml.XMLAttr;
+import org.apache.woden.xpointer.InvalidXPointerException;
+import org.apache.woden.xpointer.XPointer;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaException;
@@ -228,27 +232,63 @@
/*
* Helper method for readWSDL(WSDLSource)
*/
- private Description readWSDL(String wsdlURL, Document domDoc)
+ private Description readWSDL(String wsdlURI, Document domDoc)
throws WSDLException {
- return readWSDL(wsdlURL, domDoc.getDocumentElement());
+ //Try to find an element the XPointer points to if a Fragment Identifier exists.
+ URI uri = null;
+ try {
+ uri = new URI(wsdlURI);
+ } catch (URISyntaxException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL506", new Object[] {null, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+
+ String fragment = uri.getFragment();
+
+
+ if (fragment == null) { //No fragment identifier so just use the root element.
+ return readWSDL(wsdlURI, domDoc.getDocumentElement());//Use document root if no WSDL20 root found.
+ } else {
+ XPointer xpointer;
+ try {
+ xpointer = new XPointer(fragment);
+ } catch(InvalidXPointerException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL530", new Object[] {fragment, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+ Element root = domDoc.getDocumentElement();
+
+ DOMXMLElementEvaluator evaluator = new DOMXMLElementEvaluator(xpointer, root, getErrorReporter());
+ Element result = evaluator.evaluateElement();
+
+ if (result != null) { //Element from XPointer evaluation.
+ return readWSDL(wsdlURI, result);
+ } else {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL531", new Object[] {fragment, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg);
+ }
+ }
}
/*
* Helper method for readWSDL(WSDLSource)
*/
- private Description readWSDL(String wsdlURL, InputSource inputSource)
+ private Description readWSDL(String wsdlURI, InputSource inputSource)
throws WSDLException {
try
{
- Document wsdlDocument = getDocument(inputSource, wsdlURL);
+ Document wsdlDocument = getDocument(inputSource, wsdlURI);
- return readWSDL(wsdlURL, wsdlDocument);
+ return readWSDL(wsdlURI, wsdlDocument);
} catch (IOException e) {
String msg = getErrorReporter().getFormattedMessage(
- "WSDL503", new Object[] {wsdlURL});
+ "WSDL503", new Object[] {wsdlURI});
throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/Messages.properties?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/Messages.properties (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/Messages.properties Mon Sep 10 16:04:02 2007
@@ -81,6 +81,9 @@
WSDL524=URI resolution failed on URI "{0}".
WSDL523=Cannot add a new TypesElement as one already exists in the DescriptionElement.
+WSDL530=The XPointer "{0}" from the context URI "{1}" is invalid.
+WSDL531=The XPointer "{0}" from the context URI "{1}" failed to resolve any xml element.
+
# ------------ TODO determine if these errors are needed -------------------
# TODO - replace WSDL5xx error codes with reference numbers from the asserts
Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/OMWSDLReader.java Mon Sep 10 16:04:02 2007
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
@@ -43,14 +44,18 @@
import org.apache.woden.internal.util.om.OMQNameUtils;
import org.apache.woden.internal.util.om.OMUtils;
import org.apache.woden.internal.wsdl20.Constants;
+import org.apache.woden.internal.xpointer.OMXMLElementEvaluator;
import org.apache.woden.schema.Schema;
import org.apache.woden.wsdl20.Description;
import org.apache.woden.wsdl20.xml.DescriptionElement;
import org.apache.woden.wsdl20.xml.WSDLElement;
+import org.apache.woden.xpointer.InvalidXPointerException;
+import org.apache.woden.xpointer.XPointer;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaException;
import org.apache.ws.commons.schema.utils.NamespaceMap;
+import org.w3c.dom.Element;
import org.xml.sax.InputSource;
/**
@@ -70,27 +75,70 @@
URL url;
try {
url = StringUtils.getURL(null, wsdlURI);
- }
- catch (MalformedURLException e) {
+ } catch (MalformedURLException e) {
String msg = getErrorReporter().getFormattedMessage(
"WSDL502", new Object[] {null, wsdlURI});
throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
}
String wsdlURL = url.toString();
- OMElement wsdlDescription = null;
+ OMElement root = null;
+
+ // perform URI Resolution here
+ try {
+ root = OMUtils.getElement(resolveURI(wsdlURL));
+ } catch (IOException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL503", new Object[] {wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ } catch (URISyntaxException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL502", new Object[] {null, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ } catch (XMLStreamException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL500", new Object[] {"XML", wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+ //Try to find an element the XPointer points to if a Fragment Identifier exists.
+ URI uri = null;
try {
- // perform URI Resolution here
- wsdlDescription = OMUtils.getElement(resolveURI(wsdlURL));
- } catch (IOException e) {
- String msg = getErrorReporter().getFormattedMessage("WSDL503",
- new Object[] { wsdlURL });
+ uri = new URI(wsdlURI);
+ } catch (URISyntaxException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL506", new Object[] {wsdlURI});
throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
}
- XMLElement descEl = createXMLElement(wsdlDescription);
- DescriptionElement descElem = parseDescription(url.toString(), descEl, null);
- return descElem.toComponent();
+ String fragment = uri.getFragment();
+
+ if (fragment == null) { //No fragment identifier so just use the root element.
+ XMLElement descEl = createXMLElement(root);
+ DescriptionElement descElem = parseDescription(url.toString(), descEl, null);
+ return descElem.toComponent();
+ } else {
+ XPointer xpointer;
+ try {
+ xpointer = new XPointer(fragment);
+ } catch(InvalidXPointerException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL530", new Object[] {fragment, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+
+ OMXMLElementEvaluator evaluator = new OMXMLElementEvaluator(xpointer, root, getErrorReporter());
+ OMElement result = evaluator.evaluateElement();
+
+ if (result != null) { //Element from XPointer evaluation.
+ XMLElement descEl = createXMLElement(result);
+ DescriptionElement descElem = parseDescription(url.toString(), descEl, null);
+ return descElem.toComponent();
+ } else {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL531", new Object[] {fragment, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg);
+ }
+ }
}
/*
@@ -196,6 +244,14 @@
//not previously imported, so retrieve it now.
try {
importedSchemaDoc = OMUtils.getElement(schemaURL);
+ } catch (URISyntaxException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL502", new Object[] {null, schemaURL});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ } catch (XMLStreamException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL500", new Object[] {"XML", schemaURL});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
} catch (IOException e4) {
//schema retrieval failed (e.g. 'not found')
@@ -418,9 +474,15 @@
// not previously imported or included, so retrieve the WSDL.
try {
docEl = OMUtils.getElement(locationStr);
- }
- catch (IOException e)
- {
+ } catch (URISyntaxException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL502", new Object[] {null, locationStr});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ } catch (XMLStreamException e){
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL500", new Object[] {"XML", locationStr});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ } catch (IOException e) {
// document retrieval failed (e.g. 'not found')
getErrorReporter().reportError(
new ErrorLocatorImpl(), // TODO line&col nos.
Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/util/om/OMUtils.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/util/om/OMUtils.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/util/om/OMUtils.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/util/om/OMUtils.java Mon Sep 10 16:04:02 2007
@@ -48,21 +48,15 @@
* @return A StAXOMBuilder which could be used in obtaining the document object
* @throws IOException
*/
- public static StAXOMBuilder getOMBuilder(String strUri) throws IOException {
+ public static StAXOMBuilder getOMBuilder(String strUri) throws IOException, URISyntaxException, XMLStreamException {
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();
- }
+
+ URI uri = new URI(strUri);
+ URL url = uri.toURL();
+
+ InputStream in = url.openStream();
+ builder = new StAXOMBuilder(in);
+
return builder;
}
@@ -73,7 +67,7 @@
* @return an OMElement representing the document just read
* @throws IOException
*/
- public static OMElement getElement(String uri) throws IOException {
+ public static OMElement getElement(String uri) throws IOException, URISyntaxException, XMLStreamException {
StAXOMBuilder builder = OMUtils.getOMBuilder(uri);
return builder == null ? null : builder.getDocumentElement();
}
Added: incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java?rev=574400&view=auto
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java Mon Sep 10 16:04:02 2007
@@ -0,0 +1,77 @@
+/**
+ * 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.internal.xpointer;
+
+//Woden
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.DOMXMLElement;
+import org.apache.woden.ErrorReporter;
+
+//XPointer
+import org.apache.woden.xpointer.XPointer;
+
+//DOM
+import org.w3c.dom.Element;
+
+/**
+ * This class extends the XMLElementEvaluator to support the DOM implementation in XMLElement.
+ *
+ * @author Dan Harvey <da...@gmail.com>
+ *
+ */
+public class DOMXMLElementEvaluator extends XMLElementEvaluator {
+
+ /**
+ * Constructs a new DOMXMLElementEvaluator to evaluate a XPointer on a DOM Element.
+ *
+ * @param xpointer an XPointer to evaluate.
+ * @param element an DOM Element to be evaluated.
+ * @param errorReporter the Woden Error Reporter context object.
+ */
+ public DOMXMLElementEvaluator(XPointer xpointer, Element element, ErrorReporter errorReporter) {
+ super(xpointer, createXMLElement(element, errorReporter));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.internal.xpointer.XMLElementEvaluator#testElementShorthand(org.apache.woden.XMLElement, java.lang.String)
+ */
+ public boolean testElementShorthand(XMLElement element, String shorthand) {
+ //Simple http://www.w3.org/TR/xml-id/ support for now until we support full scheme based ID's.
+ Element domElement = (Element)element.getSource();
+ String attr = domElement.getAttributeNS("http://www.w3.org/XML/1998/namespace", "id");
+ return attr != null && attr.equals(shorthand);
+ }
+
+ /**
+ * Evaluates the XPointer on the root Element and returns the resulting Element or null.
+ *
+ * @return an Element from the resultant evaluation of the root Element or null if evaluation fails.
+ */
+ public Element evaluateElement(){
+ XMLElement element = evaluate();
+ if (element != null) return (Element)element.getSource();
+ return null;
+ }
+
+ //Private methods
+ private static XMLElement createXMLElement(Element element, ErrorReporter errorReporter) {
+ DOMXMLElement domXMLElement = new DOMXMLElement(errorReporter);
+ domXMLElement.setSource(element);
+ return domXMLElement;
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/OMXMLElementEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/OMXMLElementEvaluator.java?rev=574400&view=auto
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/OMXMLElementEvaluator.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/OMXMLElementEvaluator.java Mon Sep 10 16:04:02 2007
@@ -0,0 +1,83 @@
+/**
+ * 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.internal.xpointer;
+
+//Java
+import javax.xml.namespace.QName;
+
+//Woden
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.OMXMLElement;
+import org.apache.woden.ErrorReporter;
+
+//XPointer
+import org.apache.woden.xpointer.XPointer;
+
+//OM
+import org.apache.axiom.om.OMElement;
+
+/**
+ * This class extends XMLElementEvaluator to support the OM implementation in XMLElement
+ *
+ * @author Dan Harvey <da...@gmail.com>
+ *
+ */
+public class OMXMLElementEvaluator extends XMLElementEvaluator {
+
+ /**
+ * Constructs a new OMXMLElementEvaluator to evaluate a XPointer on a OM Element.
+ *
+ * @param xpointer an XPointer to evaluate.
+ * @param element an OMElement to be evaluated.
+ * @param errorReporter the Woden Error Reporter context object.
+ */
+ public OMXMLElementEvaluator(XPointer xpointer, OMElement element, ErrorReporter errorReporter) {
+ super(xpointer, createXMLElement(element, errorReporter));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.internal.xpointer.XMLElementEvaluator#testElementShorthand(org.apache.woden.XMLElement, java.lang.String)
+ */
+ public boolean testElementShorthand(XMLElement element, String shorthand) {
+ // Simple http://www.w3.org/TR/xml-id/ support for now until we support full scheme based ID's.
+ OMElement omElement = (OMElement)element.getSource();
+ String attr = omElement.getAttributeValue(new QName("http://www.w3.org/XML/1998/namespace", "id"));
+ return attr != null && attr.equals(shorthand);
+ }
+
+ /**
+ * Evaluates the XPointer on the root Element and returns the resulting
+ * Element or null.
+ *
+ * @return an Element from the resultant evaluation of the root Element or
+ * null if evaluation fails.
+ */
+ public OMElement evaluateElement() {
+ XMLElement element = evaluate();
+ if (element != null) return (OMElement) element.getSource();
+ return null;
+ }
+
+ // Private methods
+ private static XMLElement createXMLElement(Object elem, ErrorReporter errorReporter) {
+ OMXMLElement omXMLElement = new OMXMLElement(errorReporter);
+ omXMLElement.setSource(elem);
+ return omXMLElement;
+
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/OMXMLElementEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/XMLElementEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/XMLElementEvaluator.java?rev=574400&view=auto
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/XMLElementEvaluator.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/XMLElementEvaluator.java Mon Sep 10 16:04:02 2007
@@ -0,0 +1,217 @@
+/**
+ * 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.internal.xpointer;
+
+import java.util.Collections;
+import java.util.EmptyStackException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Stack;
+import java.util.Arrays;
+
+import org.apache.woden.XMLElement;
+import org.apache.woden.types.NCName;
+import org.apache.woden.xpointer.PointerPart;
+import org.apache.woden.xpointer.ElementPointerPart;
+import org.apache.woden.xpointer.XPointer;
+
+/**
+ * This class Evaluates an XPointer on a XMLElement, using the XPointer model in Woden.
+ * It currently supports shorthand pointer and element() scheme based pointer part.
+ *
+ * @author Dan Harvey <da...@gmail.com>
+ *
+ */
+public abstract class XMLElementEvaluator {
+ private final XPointer xpointer;
+ private final XMLElement root;
+
+ /**
+ * Constructs a new XMLElement abstract class for a XPointer and XMLElement.
+ *
+ * @param xpointer an XPointer which to evaluate.
+ * @param root an XMLElement which to evaluate the XPointer against.
+ */
+ public XMLElementEvaluator(XPointer xpointer, XMLElement root) {
+ this.xpointer = xpointer;
+ this.root = root;
+ }
+
+ /**
+ * Evaluates the XPointer on the root XMLElement and returns the resulting XMLElement or null.
+ *
+ * @return an XMLElement from the resultant evaluation of the root XMLElement or null if evaluation fails.
+ *
+ */
+ public XMLElement evaluate() {
+ if(xpointer.hasPointerParts()) { //Scheme based pointer.
+ //Take each pointer part at a time and evaluate it against the root element. The first result found will be returned.
+ XMLElement result = null;
+ for(Iterator it = Arrays.asList(xpointer.getPointerParts()).iterator(); it.hasNext(); ) {
+ PointerPart pointerPart = (PointerPart)it.next();
+ //TODO Add extra pointer parts here once we support them.
+ if (pointerPart instanceof ElementPointerPart) {
+ result = evaluateElementPointerPart((ElementPointerPart)pointerPart);
+ }
+ if (result != null) return result;
+ }
+ } else if(xpointer.hasShorthandPointer()) { //Shorthand pointer
+ //Iterator for XMLElement from root in document order. See http://www.w3.org/TR/xpath#dt-document-order
+ return evaluateShorthandPointer(xpointer.getShorthandPointer());
+
+ }
+ return null;
+ }
+
+ /**
+ * Evaluates an element() XPointer scheme based pointer part to the specification at
+ * <a href="http://www.w3.org/TR/xptr-element/">http://www.w3.org/TR/xptr-element/</a>
+ *
+ * @param elementPointerPart an ElementPointerPart to evaluate.
+ * @return an XMLElement pointed to by this Element pointer part, or null if none exists.
+ */
+ private XMLElement evaluateElementPointerPart(ElementPointerPart elementPointerPart) {
+ if (elementPointerPart.hasChildSequence() && elementPointerPart.hasNCName()) { //Both NCName and childSequence.
+ //Find NCName.
+ XMLElement element = evaluateShorthandPointer(elementPointerPart.getNCName());
+ if (element == null) return null;
+ //Walk through children.
+ return evaluateChildSequence(element, elementPointerPart.getChildSequence());
+ } else if(elementPointerPart.hasNCName()) { //Only NCName
+ return evaluateShorthandPointer(elementPointerPart.getNCName());
+ } else { //Only a childSequence
+ //XML must only have 1 root element so we can't evaluate it if its > 1
+ Integer[] childSequence = elementPointerPart.getChildSequence();
+ if (childSequence[0].intValue() > 1) return null;
+ Integer[] nChildSequence = new Integer[childSequence.length-1];
+ for (int i=1; i<childSequence.length; i++) {
+ nChildSequence[i-1] = childSequence[i];
+ }
+ return evaluateChildSequence(root, nChildSequence);
+ }
+ }
+
+ /**
+ * Evaluates an shorthand pointer in an XPointer based on the specification at
+ * <a href="http://www.w3.org/TR/xptr-framework/#shorthand">http://www.w3.org/TR/xptr-framework/#shorthand</a>
+ *
+ * @param ncname an NCName to evaluate.
+ * @return an XMLElement pointed to by this shorthand name, or null if none exists.
+ */
+ private XMLElement evaluateShorthandPointer(NCName ncname) {
+ //Iterator for XMLElement from root in document order. See http://www.w3.org/TR/xpath#dt-document-order
+ String shorthand = ncname.toString();
+ for(Iterator it = new DocumentOrderIterator(root); it.hasNext(); ){
+ XMLElement element = (XMLElement)it.next();
+ if (testElementShorthand(element, shorthand)) return element;
+ }
+ return null;
+ }
+
+ /**
+ * Evaluates a child sequence array of Integers to an XMLElement following XML Document Order.
+ * This is a helper method used by other evaluation methods in this class.
+ *
+ * @param element an XMLElement to start from.
+ * @param childSequence an Integer[] to evaluate from the start XMLElement.
+ * @return an XMLElement pointed to by this childSequence, or null if none exists.
+ */
+ private XMLElement evaluateChildSequence(XMLElement element, Integer[] childSequence) {
+ for(int i=0; i<childSequence.length; i++) {
+ //does the iTh child exist?
+ XMLElement[] children = element.getChildElements();
+ children = filterNoneElementNodes(children);
+ if (childSequence[i].intValue() > children.length) { //childSequence int out of bounds of child array so does not exist.
+ return null;
+ } else {
+ element = element.getChildElements()[childSequence[i].intValue()-1];
+ }
+ }
+ return element;
+ }
+
+ //Utility classes
+
+ /**
+ * Filters an XMLElement[] for nodes which are not xml tag elements.
+ *
+ * @param nodes an XMLElement[] of the nodes to filter.
+ * @return an XMLElement[] of the remaining nodes.
+ */
+ private static XMLElement[] filterNoneElementNodes(XMLElement[] nodes) {
+ List nodeList = Arrays.asList(nodes);
+ for(Iterator it = nodeList.iterator(); it.hasNext(); ) {
+ XMLElement node = (XMLElement)it.next();
+ if(node.getLocalName().indexOf('#') > -1) {
+ it.remove();
+ }
+ }
+ XMLElement[] nNodes = new XMLElement[nodeList.size()];
+ nodeList.toArray(nNodes);
+ return nNodes;
+ }
+
+ //Abstract Methods
+ /**
+ * Tests the element for an id according to the specification at
+ * <a href="http://www.w3.org/TR/xptr-framework/#term-sdi">http://www.w3.org/TR/xptr-framework/#term-sdi</a> and returns a boolean answer.
+ *
+ * @param element An XMLElement to test for an id.
+ * @param id A String of the id to test for.
+ * @return boolean value of whether the id matches or not.
+ */
+ public abstract boolean testElementShorthand(XMLElement element, String id);
+
+ //Internal classes
+ /**
+ * DocumentOrderIterator is a implementation of Iterator which iterates in Document Order from a root XMLElement object.
+ *
+ */
+ private class DocumentOrderIterator implements Iterator {
+ private final Stack stack;
+
+ public DocumentOrderIterator(XMLElement root) {
+ stack = new Stack();
+ stack.add(root);
+ }
+
+ public boolean hasNext() {
+ return !stack.isEmpty();
+ }
+
+ public Object next() {
+ //Get next element.
+ XMLElement element;
+ try {
+ element = (XMLElement)stack.pop();
+ } catch (EmptyStackException e) {
+ throw new NoSuchElementException();
+ }
+ //Add children to top of stack in reverse order.
+ List children = Arrays.asList(element.getChildElements());
+ Collections.reverse(children);
+ stack.addAll(children);
+
+ return element;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/internal/xpointer/XMLElementEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import javax.xml.namespace.QName;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>BindingFaultPart</code> is a Binding Fault Pointer Part for the Binding Fault WSDL 2.0 component.
* See the specification at <a href="http://www.w3.org/TR/wsdl20/#wsdl.bindingFault">http://www.w3.org/TR/wsdl20/#wsdl.bindingFault</a>
@@ -46,8 +45,8 @@
this.fault = fault;
}
- public void prefixNamespaces(XPointer xpointer) {
- fault = xpointer.prefixQNameNamespace(fault);
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return new BindingFaultPart(binding, fragmentIdentifier.prefixQNameNamespace(fault));
}
/**
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultReferencePart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultReferencePart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultReferencePart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingFaultReferencePart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import javax.xml.namespace.QName;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>BindingFaultReferencePart</code> is a Binding Fault Reference Pointer Part for the Binding Fault Reference WSDL 2.0 component.
@@ -53,9 +52,10 @@
this.fault = fault;
}
- public void prefixNamespaces(XPointer xpointer) {
- operation = xpointer.prefixQNameNamespace(operation);
- fault = xpointer.prefixQNameNamespace(fault);
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ QName nOperation = fragmentIdentifier.prefixQNameNamespace(operation);
+ QName nFault = fragmentIdentifier.prefixQNameNamespace(fault);
+ return new BindingFaultReferencePart(binding, nOperation, message, nFault);
}
/**
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingMessageReferencePart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingMessageReferencePart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingMessageReferencePart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingMessageReferencePart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import javax.xml.namespace.QName;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>BindingMessageReferencePart</code> is a Binding Message Reference Pointer Part for the Binding Message Reference WSDL 2.0 component.
@@ -50,8 +49,8 @@
this.message = message;
}
- public void prefixNamespaces(XPointer xpointer) {
- operation = xpointer.prefixQNameNamespace(operation);
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return new BindingMessageReferencePart(binding, fragmentIdentifier.prefixQNameNamespace(operation), message);
}
/**
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingOperationPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingOperationPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingOperationPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingOperationPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import javax.xml.namespace.QName;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>BindingOperationPart</code> is a Binding Operation Pointer Part for the Binding Operation WSDL 2.0 component.
@@ -47,8 +46,8 @@
this.operation = operation;
}
- public void prefixNamespaces(XPointer xpointer) {
- operation = xpointer.prefixQNameNamespace(operation);
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return new BindingOperationPart(binding, fragmentIdentifier.prefixQNameNamespace(operation));
}
/**
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/BindingPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -20,7 +20,6 @@
import org.apache.woden.types.NCName;
import org.apache.woden.wsdl20.Binding;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>BindingPart</code> is a Binding Pointer Part for the Binding WSDL 2.0 component.
@@ -66,7 +65,7 @@
return "wsdl.binding(" + binding + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ComponentPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ComponentPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ComponentPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ComponentPart.java Mon Sep 10 16:04:02 2007
@@ -25,7 +25,16 @@
* @author Dan Harvey (danharvey42@gmail.com)
*
*/
-
public interface ComponentPart extends PointerPart {
+ /**
+ * Checks that the namespace prefixes used in this PointerPart are consistent with those in the WSDL Fragment Identifier.
+ * It returns a identical copy of this object with the required changes.
+ * This method is called by the add method on WSDL Fragment Identifier when PointerParts are added to it.
+ *
+ * @param fragmentIdentifier a Fragment Identifier which the namespace prefixes are checked against.
+ * @return a ComponentPart which has been checked with changed namespaces if needed.
+ */
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier);
+
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/DescriptionPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/DescriptionPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/DescriptionPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/DescriptionPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -17,7 +17,6 @@
package org.apache.woden.wsdl20.fragids;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>DescriptionPart</code> is a Description Pointer Part for the Description WSDL 2.0 component.
@@ -37,8 +36,8 @@
return "wsdl.description()";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ElementDeclarationPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ElementDeclarationPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ElementDeclarationPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ElementDeclarationPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -20,7 +20,6 @@
import javax.xml.namespace.QName;
import org.apache.woden.WSDLReader;
-import org.apache.woden.xpointer.XPointer;
import java.net.URI;
@@ -54,10 +53,6 @@
}
}
- public void prefixNamespaces(XPointer xpointer) {
- element = xpointer.prefixQNameNamespace(element);
- }
-
/**
* Constructs a ElementDeclarationPart class for an Element Declaration component with another type system.
*
@@ -70,6 +65,18 @@
}
this.element = element;
this.system = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.wsdl20.fragids.ComponentPart#prefixNamespaces(org.apache.woden.wsdl20.fragids.FragmentIdentifier)
+ */
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ if (system == null) {
+ return new ElementDeclarationPart(fragmentIdentifier.prefixQNameNamespace(element));
+ } else {
+ return new ElementDeclarationPart(fragmentIdentifier.prefixQNameNamespace(element), system);
+ }
}
/**
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/EndpointPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/EndpointPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/EndpointPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/EndpointPart.java Mon Sep 10 16:04:02 2007
@@ -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,7 +18,6 @@
package org.apache.woden.wsdl20.fragids;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>EndpointPart</code> is a Endpoint Pointer Part for the Endpoint WSDL 2.0 component.
@@ -55,8 +54,8 @@
return "wsdl.endpoint(" + service + "/" + endpoint + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ExtensionsPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ExtensionsPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ExtensionsPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ExtensionsPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import java.net.URI;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>ExtensionPart</code> is a Extension Pointer Part for the Extension WSDL 2.0 component.
@@ -46,6 +45,10 @@
this.namespace = namespace;
this.identifier = identifier;
}
+
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
+ }
/**
* Returns a String of the serialised Extension Pointer Part.
@@ -54,10 +57,5 @@
*/
public String toString() {
return "wsdl.extension(" + namespace + "/" + identifier + ")";
- }
-
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
- }
-
+ }
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/FragmentIdentifier.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/FragmentIdentifier.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/FragmentIdentifier.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/FragmentIdentifier.java Mon Sep 10 16:04:02 2007
@@ -17,8 +17,12 @@
package org.apache.woden.wsdl20.fragids;
+import javax.xml.namespace.QName;
+
+import org.apache.woden.types.NCName;
import org.apache.woden.wsdl20.fragids.ComponentPart;
import org.apache.woden.xpointer.XPointer;
+import org.apache.woden.xpointer.XmlnsPointerPart;
/**
* This Class extends the XPointer class to work with WSDL fragment identifiers which are WSDL XPointer in effect.
@@ -30,26 +34,82 @@
*
*/
-public class FragmentIdentifier extends XPointer{
-
+public class FragmentIdentifier {
+ private static XPointer xpointer;
+
/**
* Constructs a new empty Fragment Identifier
*
- * @param wsdlpart The WSDL2.0 component pointer part for this fragment identifier.
+ * @param wsdlPart The WSDL2.0 component pointer part for this fragment identifier.
*
- * TODO add support for leading XPointer parts when we support embedded WSDL 2.0
*/
- public FragmentIdentifier(ComponentPart wsdlpart) {
- super();
- addPart(wsdlpart);
+ public FragmentIdentifier(ComponentPart wsdlPart) {
+ xpointer = new XPointer();
+ wsdlPart = wsdlPart.prefixNamespaces(this); //Prefix namespaces if needed.
+ xpointer.addPointerPart(wsdlPart);
}
-
+
/**
* Returns a String serialisation of this fragment identifier.
*
* @return a String fragment identifier
*/
public String toString() {
- return super.toString();
+ return xpointer.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());
+ }
+
+ /**
+ * 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) {
+ //Lookup prefix
+ NCName prefix = (NCName)xpointer.getNamespaceBinding(namespace);
+ if (prefix == null) {
+ //The namespace does not have a prefix yet so lets add one.
+ //Find next available nsXXX prefix
+ int i = 1;
+ do {
+ prefix = new NCName("ns" + i);
+ i++;
+ } while (xpointer.hasPrefixBinding(prefix));
+
+ //Add prefix pointer part.
+ xpointer.addPointerPart(new XmlnsPointerPart(prefix, namespace));
+
+ //Add to our binding contex.
+ xpointer.addPrefixNamespaceBinding(prefix, namespace);
+ }
+ 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());
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultPart.java Mon Sep 10 16:04:02 2007
@@ -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,7 +18,6 @@
package org.apache.woden.wsdl20.fragids;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>InterfaceFaultPart</code> is a Interface Fault Pointer Part for the Interface Fault WSDL 2.0 component.
@@ -55,8 +54,8 @@
return "wsdl.interfaceFault(" + interfaceName + "/" + fault + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultReferencePart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultReferencePart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultReferencePart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceFaultReferencePart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import javax.xml.namespace.QName;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>InterfaceFaultReferencePart</code> is a Interface Fault Reference Pointer Part for the Interface Fault Reference WSDL 2.0 component.
@@ -53,8 +52,8 @@
this.fault = fault;
}
- public void prefixNamespaces(XPointer xpointer) {
- fault = xpointer.prefixQNameNamespace(fault);
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return new InterfaceFaultReferencePart(interfaceName, operation, message, fragmentIdentifier.prefixQNameNamespace(fault));
}
/**
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceMessageReferencePart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceMessageReferencePart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceMessageReferencePart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceMessageReferencePart.java Mon Sep 10 16:04:02 2007
@@ -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,7 +18,6 @@
package org.apache.woden.wsdl20.fragids;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>InterfaceMessageReferencePart</code> is a Interface Message Reference Pointer Part for the Interface Message Reference WSDL 2.0 component.
@@ -58,8 +57,8 @@
return "wsdl.interfaceMessageReference(" + interfaceName + "/" + operation + "/" + message + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceOperationPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceOperationPart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceOperationPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfaceOperationPart.java Mon Sep 10 16:04:02 2007
@@ -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,7 +18,6 @@
package org.apache.woden.wsdl20.fragids;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>InterfaceOperationPart</code> is a Interface Operation Pointer Part for the Interface Operation WSDL 2.0 component.
@@ -55,7 +54,7 @@
return "wsdl.interfaceOperation(" + interfaceName + "/" + operation + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfacePart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfacePart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfacePart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/InterfacePart.java Mon Sep 10 16:04:02 2007
@@ -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,7 +18,6 @@
package org.apache.woden.wsdl20.fragids;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>InterfacePart</code> is a Interface Pointer Part for the Interface WSDL 2.0 component.
@@ -52,7 +51,7 @@
return "wsdl.interface(" + interfaceName + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ServicePart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ServicePart.java?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ServicePart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/ServicePart.java Mon Sep 10 16:04:02 2007
@@ -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,7 +18,6 @@
package org.apache.woden.wsdl20.fragids;
import org.apache.woden.types.NCName;
-import org.apache.woden.xpointer.XPointer;
/**
* <code>ServicePart</code> is a Service Pointer Part for the Service WSDL 2.0 component.
@@ -52,8 +51,8 @@
return "wsdl.service(" + service + ")";
}
- public void prefixNamespaces(XPointer xpointer) {
- //This PointerPart does not have any namespaces.
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ return this;
}
}
Modified: 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?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/fragids/TypeDefinitionPart.java Mon Sep 10 16:04:02 2007
@@ -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.
@@ -19,7 +19,6 @@
import javax.xml.namespace.QName;
-import org.apache.woden.xpointer.XPointer;
import java.net.URI;
@@ -63,8 +62,16 @@
this.system = null;
}
- public void prefixNamespaces(XPointer xpointer) {
- type = xpointer.prefixQNameNamespace(type);
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.wsdl20.fragids.ComponentPart#prefixNamespaces(org.apache.woden.wsdl20.fragids.FragmentIdentifier)
+ */
+ public ComponentPart prefixNamespaces(FragmentIdentifier fragmentIdentifier) {
+ if (system == null) {
+ return new TypeDefinitionPart(fragmentIdentifier.prefixQNameNamespace(type));
+ } else {
+ return new TypeDefinitionPart(fragmentIdentifier.prefixQNameNamespace(type), system);
+ }
}
/**
Added: incubator/woden/trunk/java/src/org/apache/woden/xpointer/ElementPointerPart.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/xpointer/ElementPointerPart.java?rev=574400&view=auto
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/xpointer/ElementPointerPart.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/xpointer/ElementPointerPart.java Mon Sep 10 16:04:02 2007
@@ -0,0 +1,264 @@
+/**
+ * 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;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.lang.StringBuffer;
+
+import java.lang.NumberFormatException;
+
+/**
+ * ElementPointerPart is a class which represents the element() scheme for the XPointer Framework.
+ * The specification is defined at <a href="http://www.w3.org/TR/xptr-element/">http://www.w3.org/TR/xptr-element/</a>
+ *
+ * This class is immutable.
+ *
+ * @author Dan Harvey (danharvey42@gmail.com)
+ *
+ */
+public class ElementPointerPart implements PointerPart {
+ private final NCName ncname;
+ private final List childSequence;
+
+ /**
+ * Constructs an ElementPointerPart with only an elementID NCName.
+ *
+ * @param elementID an NCName of the elementID to reference.
+ * @throws NullPointerException is a null elementID is given.
+ */
+ public ElementPointerPart(NCName elementID) {
+ if(elementID == null) {
+ throw new NullPointerException("The elementID argument is null.");
+ }
+ this.ncname = elementID;
+ this.childSequence = null;
+ }
+
+ /**
+ * Constructs an ElementPointerPart with only a childSequence.
+ *
+ * @param childSequence a List of Integers representing the child sequence.
+ * @throws NullPointerException if childSequence is null.
+ * @throws IllegalArgumentException if childSequence is empty or contains elements other than Integers.
+ */
+ public ElementPointerPart(List childSequence) {
+ if(childSequence == null) {
+ throw new NullPointerException("The childSequence argument is null.");
+ }
+ if(childSequence.isEmpty()) {
+ throw new IllegalArgumentException("The childSequence list is empty.");
+ }
+ for(Iterator it = childSequence.iterator(); it.hasNext();) {
+ if(!(it.next() instanceof Integer)){
+ throw new IllegalArgumentException("The childSequence list must only contain Integers.");
+ }
+ }
+ this.ncname = null;
+ this.childSequence = childSequence;
+ }
+
+ /**
+ * Constructs an ElementPointerPart with both an NCName and a childSequence.
+ *
+ * @param elementID an NCName of the elementID to reference.
+ * @param childSequence a List of Integers representing the child sequence.
+ * @throws NullPointerException if elementID or childSequence are null.
+ * @throws IllegalArgumentException if childSequence is empty or contains elements other than Integers.
+ */
+ public ElementPointerPart(NCName elementID, List childSequence) {
+ if(elementID == null) {
+ throw new NullPointerException("The elementID argument is null.");
+ }
+ if(childSequence == null) {
+ throw new NullPointerException("The childSequence argument is null.");
+ }
+ if(childSequence.isEmpty()) {
+ throw new IllegalArgumentException("The childSequence list is empty.");
+ }
+ for(Iterator it = childSequence.iterator(); it.hasNext();) {
+ Object integer = it.next();
+ if(!(integer instanceof Integer)){
+ throw new IllegalArgumentException("the childSequence list must only contain Integers.");
+ } else if (((Integer)integer).intValue() == 0){
+ throw new IllegalArgumentException("the childSequence list must only contain Integers bigger than 0.");
+ }
+ }
+ this.ncname = elementID;
+ this.childSequence = childSequence;
+ }
+
+ /**
+ * Returns the NCName for this Element PointerPart.
+ *
+ * @return an NCName if it exists in this Element PointerPart, otherwise null.
+ */
+ public NCName getNCName() {
+ return ncname;
+ }
+
+ /**
+ * Returns the child sequence of this Element PointerPart.
+ *
+ * @return a Integer[] of the child sequence for this element pointer part, or an empty array if none exists.
+ */
+ public Integer[] getChildSequence() {
+ int size = childSequence.size();
+ Integer[] sequence = new Integer[size];
+ for(int i=0; i<size; i++) {
+ sequence[i] = (Integer)childSequence.get(i);
+ }
+ return sequence;
+ }
+
+ /**
+ * Checks if this Element PointerPart has a NCName or not.
+ *
+ * @return a boolean, true if it has a NCName or false if not.
+ */
+ public boolean hasNCName() {
+ return ncname != null;
+ }
+
+ /**
+ * Checks if this Element PointerPart has a childSequence or not.
+ *
+ * @return a boolean, true if this has a childSequence or false if not.
+ */
+ public boolean hasChildSequence() {
+ return childSequence != null;
+ }
+
+ /*
+ *(non-Javadoc)
+ * @see org.apache.woden.xpointer.PointerPart#toString()
+ */
+ public String toString() {
+ String schemeData;
+ if (childSequence == null) {
+ schemeData = ncname.toString();
+ } else if (ncname == null) {
+ schemeData = serialiseChildSequence();
+ } else {
+ schemeData = ncname.toString() + serialiseChildSequence();
+ }
+ return "element(" + schemeData + ")";
+ }
+
+ /**
+ * Serialises the child sequence and returns it as a string.
+ *
+ * @return a String of the serialised child sequence.
+ */
+ private String serialiseChildSequence() {
+ StringBuffer buffer = new StringBuffer();
+ for(Iterator it = childSequence.iterator(); it.hasNext();) {
+ Integer child = (Integer)it.next();
+ buffer.append("/" + child.toString());
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Deserialises the schemaData for an ElementPointerPart and constructs a new ElementPointerPart from it.
+ *
+ * @param schemeData a String of the schemeaData parsed from the string XPointer.
+ * @return an ElementPointerPart representing the parsed schemaData.
+ * @throws IllegalArgumentException if the schemeData has invalid scheme syntax.
+ */
+ public static ElementPointerPart parseFromString(final String schemeData) throws InvalidXPointerException {
+ List childSequence = null;
+ NCName elementID = null;
+ int startChar;
+ int endChar;
+
+ //Find an NCName if it exists?
+ startChar = schemeData.indexOf("/");
+ // -1 Only an NCName. 0 No NCName. > 1 An NCName.
+
+ switch (startChar) {
+ case -1: //Only an NCName.
+ try {
+ elementID = new NCName(schemeData);
+ }
+ catch (IllegalArgumentException e) {
+ throw new InvalidXPointerException("Invalid NCName in the XPointer", schemeData);
+ }
+ return new ElementPointerPart(elementID);
+ case 0: //No NCName.
+ break;
+ default: //An NCName.
+ try {
+ elementID = new NCName(schemeData.substring(0, startChar));
+ } catch (IllegalArgumentException e) {
+ throw new InvalidXPointerException("Invalid NCName in the XPointer", schemeData, 0, startChar);
+ }
+ break;
+ }
+
+ //Find remaining child sequence.
+ childSequence = new ArrayList();
+
+ endChar = schemeData.indexOf("/", startChar+1);
+ // -1 Only single child sequence element. > 0 A childSequence.
+
+ if (endChar < 0) { //Only single child sequence element.
+ childSequence.add(parseIntegerFromChildSequence(schemeData, startChar+1, schemeData.length()));
+ } else { //Multiple child sequence elements.
+ while(true) {
+ if (endChar < 0) {//Last integer.
+ childSequence.add(parseIntegerFromChildSequence(schemeData, startChar+1, schemeData.length()));
+ break;
+ } else { //Inner sequence integer.
+ childSequence.add(parseIntegerFromChildSequence(schemeData, startChar+1, endChar));
+ startChar = endChar;
+ endChar = schemeData.indexOf("/", startChar+1);
+ }
+ }
+ }
+
+ if (elementID == null) { //Only a childSequence
+ return new ElementPointerPart(childSequence);
+ } else { //Both NCName and childSequence
+ return new ElementPointerPart(elementID, childSequence);
+ }
+ }
+
+ /**
+ * Parses a String for an integer between two indices and returns this as an Integer.
+ *
+ * @param string a String to parse.
+ * @param start an int char index to the start of the Integer.
+ * @param end an int char index to the end of the Integer.
+ * @return an Integer resulting from parsing the given String in the index range.
+ * @throws IllegalArgumentException if the given char range does not contain an integer.
+ */
+ private static Integer parseIntegerFromChildSequence(String string, int start, int end) throws InvalidXPointerException{
+ if (start < end) { //Make sure sub string is not of zero length.
+ try { //Make sure the integer is valid.
+ return new Integer(string.substring(start, end));
+ } catch (NumberFormatException e) {
+ throw new InvalidXPointerException("The child sequence part contained a invalid integer.", string, start, end);
+ }
+ } else {
+ throw new InvalidXPointerException("The child sequence part contained a empty item at " + String.valueOf(start), string, start, end);
+ }
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/xpointer/ElementPointerPart.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/woden/trunk/java/src/org/apache/woden/xpointer/InvalidXPointerException.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/xpointer/InvalidXPointerException.java?rev=574400&view=auto
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/xpointer/InvalidXPointerException.java (added)
+++ incubator/woden/trunk/java/src/org/apache/woden/xpointer/InvalidXPointerException.java Mon Sep 10 16:04:02 2007
@@ -0,0 +1,141 @@
+/**
+ * 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;
+
+/**
+ * This class represents Exceptions that can happen during parsing an XPointer Expression.
+ *
+ * @author Dan Harvey <da...@gmail.com>
+ *
+ */
+public class InvalidXPointerException extends Exception {
+ private static final long serialVersionUID = 0;
+ private final String fragment;
+ private final Integer startChar;
+ private final Integer endChar;
+
+ /**
+ * Constructs a InvalidXPointerException with a message and fragment properties.
+ *
+ * @param message a String message of error.
+ * @param fragment a String fragment of the cause.
+ */
+ public InvalidXPointerException(String message, String fragment) {
+ this(message, fragment, null, null, null);
+ }
+
+ /**
+ * Constructs a InvalidXPointerException with a message and fragment properties.
+ *
+ * It also has a Throwable argument to support exception chaining.
+ *
+ * @param message a String message of error.
+ * @param fragment a String fragment of the cause of the error.
+ * @param cause a Throwable which caused this exception to be thrown.
+ */
+ public InvalidXPointerException(String message, String fragment, Throwable cause) {
+ this(message, fragment, null, null, cause);
+ }
+
+ /**
+ * Constructs a InvalidXPointerException with a message and fragment properties,
+ * and index to the cause inside the fragment.
+ *
+ * @param message a String message of error.
+ * @param fragment a String fragment of the cause of the error.
+ * @param startChar a int char index to the start of the cause in the fragment.
+ * @param endChar a int char index to the end of the cause in the fragment.
+ */
+ public InvalidXPointerException(String message, String fragment, int startChar, int endChar) {
+ this(message, fragment, new Integer(startChar), new Integer(endChar), null);
+ }
+
+ /**
+ * Constructs a InvalidXPointerException with a message and fragment properties,
+ * and index to the cause inside the fragment.
+ *
+ * It also has a Throwable argument to support exception chaining.
+ *
+ * @param message a String message of error.
+ * @param fragment a String fragment of the cause of the error.
+ * @param startChar an int char index to the start of the cause in the fragment.
+ * @param endChar an int char index to the end of the cause in the fragment.
+ * @param cause a Throwable which caused the exception to be thrown.
+ */
+ public InvalidXPointerException(String message, String fragment, int startChar, int endChar, Throwable cause) {
+ this(message, fragment, new Integer(startChar), new Integer(endChar), cause);
+ }
+
+ /**
+ * Constructs a new InvalidXPointerException.
+ * This constructor is called by all of the above constructors and stores the in indexes and Integers internally.
+ *
+ * @param message a String message of error.
+ * @param fragment a String fragment of the cause of the error.
+ * @param startChar an Integer char index to the start of the cause in the fragment.
+ * @param endChar an Integer char index to the end of the cause in the fragment.
+ * @param cause a Throwable which caused the exception to be thrown.
+ */
+ private InvalidXPointerException(String message, String fragment, Integer startChar, Integer endChar, Throwable cause) {
+ super(message, cause);
+ this.fragment = fragment;
+ this.startChar = startChar;
+ this.endChar = endChar;
+ }
+
+ /**
+ * Returns the fragment String stored inside this exception.
+ *
+ * @return a String fragment.
+ */
+ public String getFragment() {
+ return fragment;
+ }
+
+ /**
+ * Returns the startChar index of the cause of this error in the fragment.
+ *
+ * @return an Integer of the startChar index if one exists, otherwise null.
+ */
+ public Integer getStartChar() {
+ return startChar;
+ }
+
+ /**
+ * Returns the endChar index of the cause of this error in the fragment.
+ *
+ * @return an Integer of the startChar index if one exists, otherwise null.
+ */
+ public Integer getEndChar() {
+ return endChar;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Throwable#toString()
+ */
+ public String toString() {
+ String postString;
+ if (startChar != null && endChar!= null) {
+ postString = "{XPointer: " + fragment + ", start: " + startChar.toString()+ ", end: " + endChar.toString() + ", substr: " + fragment.substring(startChar.intValue(), endChar.intValue()) + "}";
+ } else {
+ postString = "{XPointer: " + fragment + "}";
+ }
+ return "InvalidXPointerException: " + getMessage() + ". " + postString;
+ }
+
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/xpointer/InvalidXPointerException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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?rev=574400&r1=574399&r2=574400&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/xpointer/PointerPart.java Mon Sep 10 16:04:02 2007
@@ -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);
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org