Author: jkaputin
Date: Mon Oct 9 16:19:06 2006
New Revision: 454549
URL: http://svn.apache.org/viewvc?view=rev&rev=454549
Log:
Renamed ElementSource to XMLElement and re-implemented
the DOMUtils methods now defined on XMLElement in
BaseXMLElement and DOMXMLElement.
Modified:
incubator/woden/branches/WODEN-44/src/org/apache/woden/XMLElement.java
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/BaseXMLElement.java
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/DOMXMLElement.java
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/Messages.properties
Modified: incubator/woden/branches/WODEN-44/src/org/apache/woden/XMLElement.java
URL:
http://svn.apache.org/viewvc/incubator/woden/branches/WODEN-44/src/org/apache/woden/XMLElement.java?view=diff&rev=454549&r1=454548&r2=454549
==============================================================================
--- incubator/woden/branches/WODEN-44/src/org/apache/woden/XMLElement.java
(original)
+++ incubator/woden/branches/WODEN-44/src/org/apache/woden/XMLElement.java Mon
Oct 9 16:19:06 2006
@@ -15,9 +15,11 @@
*/
package org.apache.woden;
-import javax.xml.namespace.QName;
+import java.net.URI;
import java.util.List;
+import javax.xml.namespace.QName;
+
/**
* This interface represents an XML element information item in a format to
* be interpreted by the Woden implementation.
@@ -40,7 +42,7 @@
*
* @throws IllegalArgumentException if elem is not a type supported by the
implementation.
*/
- public void setSource(Object elem) throws WSDLException;
+ public void setSource(Object elem);
/**
* Returns an Object representing an XML element, which the caller must
@@ -60,25 +62,21 @@
/**
* @return a list of attributes associated with the XML element
*/
- public List getAttributes ();
+ public List getAttributes();
/**
- * Returns the value of an attribute of an element. Should return null
- * if the attribute is not found.
+ * Returns the value of the specified attribute or null if it is not found.
*
* @param attrName name of attribute to look for
* @return the attribute value including prefix if present
*/
- public String getAttribute (String attrName);
+ public String getAttribute(String attrName);
/**
- * Return the qualified name from the declared namespace
*
- * @param prefixedValue
- * @return the QName corresponding to the prefix
- * @throws WSDLException
+ * @return the namespace URI of the element
*/
- public QName getQName(String prefixedValue) throws WSDLException;
+ public URI getNamespaceURI();
/**
*
@@ -87,12 +85,21 @@
public String getLocalName();
/**
+ * Return the qualified name from the declared namespace
+ *
+ * @param prefixedValue
+ * @return the QName corresponding to the prefix
+ * @throws WSDLException
+ */
+ public QName getQName(String prefixedValue) throws WSDLException;
+
+ /**
* Return the first child element of the given element. Null if no
* children are found.
*
* @return the first child element.
*/
- public XMLElement getFirstChildElement () throws WSDLException;
+ public XMLElement getFirstChildElement();
/**
* Return the next sibling element of the given element. Null if no
@@ -100,7 +107,7 @@
*
* @return the next sibling element.
*/
- public XMLElement getNextSiblingElement() throws WSDLException;
+ public XMLElement getNextSiblingElement();
//TODO - other methods for accessing the element's contents?
Modified:
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/BaseXMLElement.java
URL:
http://svn.apache.org/viewvc/incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/BaseXMLElement.java?view=diff&rev=454549&r1=454548&r2=454549
==============================================================================
---
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/BaseXMLElement.java
(original)
+++
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/BaseXMLElement.java
Mon Oct 9 16:19:06 2006
@@ -15,12 +15,18 @@
*/
package org.apache.woden.internal;
-import org.apache.woden.XMLElement;
+import java.net.URI;
+
+import javax.xml.namespace.QName;
+
import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.XMLElement;
/**
* This abstract class implements methods of the XMLElement interface that are
* common across all concrete implementations.
+ *
*/
public abstract class BaseXMLElement implements XMLElement {
@@ -31,22 +37,111 @@
fErrorReporter = errorReporter;
}
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#setSource(java.lang.Object)
+ */
abstract public void setSource(Object elem);
- /**
- * @return Returns the fSource.
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getSource()
*/
- public Object getSource() {
+ public final Object getSource() {
return fSource;
}
+
+ //TODO refactor getAttributes() here
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getAttribute(java.lang.String)
+ */
+ public final String getAttribute(String attrName) {
+
+ if(fSource != null) {
+ return doGetAttribute(attrName);
+ } else {
+ return null;
+ }
+
+ }
+
+ protected abstract String doGetAttribute(String attrName);
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getNamespaceURI()
+ */
+ public final URI getNamespaceURI() {
+
+ if(fSource != null) {
+ return doGetNamespaceURI();
+ } else {
+ return null;
+ }
+ }
+
+ protected abstract URI doGetNamespaceURI();
- /**
- * @return Returns the fErrorReporter.
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getLocalName()
*/
- public ErrorReporter getErrorReporter()
- {
- return fErrorReporter;
+ public final String getLocalName() {
+
+ if(fSource != null) {
+ return doGetLocalName();
+ } else {
+ return null;
+ }
}
+
+ protected abstract String doGetLocalName();
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getQName(java.lang.String)
+ */
+ public final QName getQName(String prefixedValue) throws WSDLException {
+
+ if(fSource != null) {
+ return doGetQName(prefixedValue);
+ } else {
+ return null;
+ }
+ }
+ protected abstract QName doGetQName(String prefixedValue) throws
WSDLException;
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getFirstChildElement()
+ */
+ public final XMLElement getFirstChildElement() {
+
+ if(fSource != null) {
+ return doGetFirstChildElement();
+ } else {
+ return null;
+ }
+ }
+
+ protected abstract XMLElement doGetFirstChildElement();
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.woden.XMLElement#getNextSiblingElement()
+ */
+ public final XMLElement getNextSiblingElement() {
+
+ if(fSource != null) {
+ return doGetNextSiblingElement();
+ } else {
+ return null;
+ }
+ }
+
+ protected abstract XMLElement doGetNextSiblingElement();
+
}
Modified:
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/DOMXMLElement.java
URL:
http://svn.apache.org/viewvc/incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/DOMXMLElement.java?view=diff&rev=454549&r1=454548&r2=454549
==============================================================================
---
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/DOMXMLElement.java
(original)
+++
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/DOMXMLElement.java
Mon Oct 9 16:19:06 2006
@@ -16,21 +16,25 @@
package org.apache.woden.internal;
-import org.apache.woden.WSDLException;
+import java.net.URI;
+import java.util.List;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
import org.apache.woden.XMLElement;
+import org.apache.woden.internal.util.dom.DOMQNameUtils;
import org.apache.woden.internal.util.dom.XPathUtils;
-import org.apache.woden.internal.util.dom.DOMUtils;
-import org.w3c.dom.*;
-
-import javax.xml.namespace.QName;
-import java.util.List;
-import java.util.Vector;
+import org.apache.woden.internal.wsdl20.Constants;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
public class DOMXMLElement extends BaseXMLElement{
- private static final String ATTR_XMLNS = "xmlns";
-
public DOMXMLElement(ErrorReporter errorReporter) {
super(errorReporter);
}
@@ -45,8 +49,8 @@
}
else {
String elemClass = (elem != null
- ? elem.getClass().getName()
- : null);
+ ? elem.getClass().getName()
+ : null);
String xmlElementClass = this.getClass().getName();
String msg = fErrorReporter.getFormattedMessage(
"WSDL019", new Object[] {elemClass, xmlElementClass});
@@ -55,6 +59,7 @@
}
+ //TODO refactor this as per the other methods and return XMLAttribute[].
public List getAttributes() {
String nodename, prefix;
if (fSource instanceof Element){
@@ -65,7 +70,8 @@
nodename = attrMap.item(i).getNodeName();
prefix = attrMap.item(i).getPrefix();
- if ( !(ATTR_XMLNS.equals(nodename) || ATTR_XMLNS.equals(prefix))
) {
+ if ( !(Constants.ATTR_XMLNS.equals(nodename) ||
+ Constants.ATTR_XMLNS.equals(prefix)) ) {
attrs.add(attrMap.item(i));
}
}
@@ -75,86 +81,154 @@
return null;
}
- public String getAttribute(String attrName) {
- if (fSource instanceof Element){
- Element el = (Element)fSource;
- String strAttr = null;
- Attr attr = el.getAttributeNode(attrName);
-
- if (attr != null) {
- strAttr = attr.getValue();
- }
- return strAttr;
- }
- return null;
- }
+ protected String doGetAttribute(String attrName) {
+
+ Element el = (Element)fSource;
+ return getAttribute(el, attrName);
+ }
+
+ protected QName doGetQName(String prefixedValue) throws WSDLException {
+
+ Element el = (Element)fSource;
+ int index = prefixedValue.indexOf(':');
+ String prefix = (index != -1)
+ ? prefixedValue.substring(0, index)
+ : null;
+ String localPart = prefixedValue.substring(index + 1);
+ String namespaceURI = getNamespaceFromPrefix(el, prefix);
+
+ if (namespaceURI != null) {
+ return new QName(namespaceURI,localPart,
+ prefix != null ? prefix : "");
+ }
+ else{
+ String faultCode = (prefix == null)
+ ? WSDLException.NO_PREFIX_SPECIFIED
+ : WSDLException.UNBOUND_PREFIX;
+
+ String msg = fErrorReporter.getFormattedMessage(
+ "WSDL513",
+ new Object[] {prefixedValue,
DOMQNameUtils.newQName(el)});
+
+ WSDLException wsdlExc = new WSDLException(
+ faultCode,
+ msg);
+
+ wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(el));
+
+ throw wsdlExc;
+ }
+ }
+
+ protected URI doGetNamespaceURI() {
+
+ Element el = (Element)fSource;
+ String nsStr = el.getNamespaceURI();
+ return URI.create(nsStr);
+ }
+
+ protected String doGetLocalName() {
+
+ Element el = (Element)fSource;
+ return el.getLocalName();
+ }
+
+ protected XMLElement doGetFirstChildElement() {
+
+ XMLElement xmlElement = new DOMXMLElement(fErrorReporter);
+ Element el = (Element)fSource;
+ for (Node node = el.getFirstChild(); node!=null;
node=node.getNextSibling()){
+ if (node.getNodeType() == Node.ELEMENT_NODE){
+ xmlElement.setSource(node);
+ return xmlElement;
+ }
+ }
+ return null; //no child element found
+ }
+
+ protected XMLElement doGetNextSiblingElement() {
+
+ XMLElement xmlElement = new DOMXMLElement(fErrorReporter);
+ Element el = (Element)fSource;
+ for (Node node = el.getNextSibling (); node != null; node =
node.getNextSibling ()) {
+ if (node.getNodeType() == Node.ELEMENT_NODE){
+ xmlElement.setSource(node);
+ return xmlElement;
+ }
+ }
+ return null; //no sibling element found
+ }
+
+ /* ************************************************************************
+ * Private helper methods
+ *
************************************************************************/
+
+ private String getAttribute(Element el, String attrName) {
+
+ String sRet = null;
+ Attr attr = el.getAttributeNode(attrName);
+
+ if (attr != null) {
+ sRet = attr.getValue();
+ }
+ return sRet;
+ }
+
+ private String getAttributeNS (Element el,
+ String namespaceURI,
+ String localPart) {
+ String sRet = null;
+ Attr attr = el.getAttributeNodeNS (namespaceURI, localPart);
+
+ if (attr != null) {
+ sRet = attr.getValue ();
+ }
+
+ return sRet;
+ }
+
+ private String getNamespaceFromPrefix(Node context, String prefix) {
+
+ short nodeType = context.getNodeType ();
+ Node tempNode = null;
+
+ switch (nodeType)
+ {
+ case Node.ATTRIBUTE_NODE :
+ {
+ tempNode = ((Attr) context).getOwnerElement ();
+ break;
+ }
+ case Node.ELEMENT_NODE :
+ {
+ tempNode = context;
+ break;
+ }
+ default :
+ {
+ tempNode = context.getParentNode ();
+ break;
+ }
+ }
+
+ while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
+ {
+ Element tempEl = (Element) tempNode;
+
+ String namespaceURI = (prefix == null)
+ ? getAttribute (tempEl, Constants.ATTR_XMLNS)
+ : getAttributeNS (tempEl,
Constants.NS_URI_XMLNS, prefix);
+
+ if (namespaceURI != null)
+ {
+ return namespaceURI;
+ }
+ else
+ {
+ tempNode = tempEl.getParentNode ();
+ }
+ }
- public XMLElement getFirstChildElement() throws WSDLException {
- XMLElement xmlElement = new DOMXMLElement(getErrorReporter());
- if (fSource instanceof Element){
- Element el = (Element)fSource;
- for (Node node = el.getFirstChild(); node!=null;
node=node.getNextSibling()){
- if (node.getNodeType() == Node.ELEMENT_NODE){
- xmlElement.setSource(node);
- return xmlElement;
- }
- }
- }
- return null;
- }
-
- public QName getQName(String prefixedValue) throws WSDLException {
- if (fSource instanceof Element){
- Element el = (Element)fSource;
- int index = prefixedValue.indexOf(':');
- String prefix = (index != -1)
- ? prefixedValue.substring(0, index)
- : null;
- String localPart = prefixedValue.substring(index + 1);
- String namespaceURI = DOMUtils.getNamespaceURIFromPrefix(el,
prefix);
-
- if (namespaceURI != null){
- return new QName(namespaceURI,localPart,
- prefix != null ? prefix : "");
- }
- else{
- String faultCode = (prefix == null)
- ? WSDLException.NO_PREFIX_SPECIFIED
- : WSDLException.UNBOUND_PREFIX;
-
- WSDLException wsdlExc = new WSDLException(faultCode,
- "Unable to determine " +
- "namespace of '" +
- prefixedValue + "'.");
-
- wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(el));
-
- throw wsdlExc;
- }
-
- }
- return null;
- }
-
- public String getLocalName() {
- if (fSource instanceof Element){
- Element el = (Element)fSource;
- return el.getLocalName();
- }
- return null;
- }
-
- public XMLElement getNextSiblingElement() throws WSDLException {
- XMLElement xmlElement = new DOMXMLElement(getErrorReporter());
- if (fSource instanceof Element){
- Element el = (Element)fSource;
- for (Node node = el.getNextSibling (); node != null; node =
node.getNextSibling ()) {
- if (node.getNodeType() == Node.ELEMENT_NODE){
- xmlElement.setSource(node);
- return xmlElement;
- }
- }
- }
- return null;
+ return null; //no namespace found for specified prefix
}
}
Modified:
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/Messages.properties?view=diff&rev=454549&r1=454548&r2=454549
==============================================================================
---
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/Messages.properties
(original)
+++
incubator/woden/branches/WODEN-44/src/org/apache/woden/internal/Messages.properties
Mon Oct 9 16:19:06 2006
@@ -69,6 +69,7 @@
WSDL510=Could not create a QName from the string "{0}" within the string of
QNames "{1}".
WSDL511=Boolean defaulted to 'false' due to invalid boolean string "{0}".
WSDL512=Could not create an Integer from the string "{0}".
+WSDL513=Could not determine the namespace for prefixed value "{0}" in element
"{1}".
WSDL520=Extension element "{0}" in the context of "{1}" must not be in the
WSDL namespace.
WSDL521=Could not parse an inline schema in the WSDL at URL "{0}".
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]