You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by gd...@apache.org on 2007/03/24 00:11:58 UTC
svn commit: r521935 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ axiom-dom/src/main/j...
Author: gdaniels
Date: Fri Mar 23 16:11:57 2007
New Revision: 521935
URL: http://svn.apache.org/viewvc?view=rev&rev=521935
Log:
* Introduce OMFactory.createOMElement(QName) and implementations thereof
* Test the above
* Make sure whitespace-only local names are also disallowed in OMAttributeImpl
* Bubble up exceptions in OMLinkedListImplFactoryTest - because we were catching exceptions and just logging them, removing the try/catch blocks actually revealed that a couple of the tests were failing!! Fix the failures.
* Clean up various code (fix logic, bad String compares, etc)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java Fri Mar 23 16:11:57 2007
@@ -1,181 +1,195 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axiom.om;
-
-import javax.xml.namespace.QName;
-
-/** Class OMFactory */
-public interface OMFactory {
-
- /** Creates a new OMDocument. */
- OMDocument createOMDocument();
-
- OMDocument createOMDocument(OMXMLParserWrapper builder);
-
-
- /**
- * @param localName
- * @param ns - This can be null
- */
- OMElement createOMElement(String localName, OMNamespace ns);
-
- OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent)
- throws OMException;
-
- /**
- * @param localName
- * @param ns - this can be null
- * @param parent
- * @param builder
- */
- OMElement createOMElement(String localName, OMNamespace ns,
- OMContainer parent,
- OMXMLParserWrapper builder);
-
- /**
- * Construct element with arbitrary data source. This is an optional operation which may not be
- * supported by all factories.
- *
- * @param source
- * @param localName
- * @param ns
- */
- OMElement createOMElement(OMDataSource source, String localName,
- OMNamespace ns);
-
- /**
- * This is almost the same as as createOMElement(localName,OMNamespace) method above. But some
- * people may, for some reason, need to use the conventional method of putting a namespace. Or
- * in other words people might not want to use the new OMNamespace. Well, this is for those
- * people.
- *
- * @param localName
- * @param namespaceURI
- * @param namespacePrefix
- * @return Returns the newly created OMElement.
- */
- OMElement createOMElement(String localName,
- String namespaceURI,
- String namespacePrefix);
-
- /**
- * QName(localPart), QName(namespaceURI, localPart) - a prefix will be assigned to this
- * QName(namespaceURI, localPart, prefix)
- *
- * @param qname
- * @param parent
- * @return Returns the new OMElement.
- * @throws OMException
- */
- OMElement createOMElement(QName qname, OMContainer parent)
- throws OMException;
-
- /**
- * @param uri
- * @param prefix
- * @return Returns OMNameSpace.
- */
- OMNamespace createOMNamespace(String uri, String prefix);
-
- /**
- * @param parent
- * @param text
- * @return Returns OMText.
- */
- OMText createOMText(OMContainer parent, String text);
-
- /**
- * @param parent
- * @param text - This text itself can contain a namespace inside it.
- */
- OMText createOMText(OMContainer parent, QName text);
-
- /**
- * @param parent
- * @param text
- * @param type - this should be either of XMLStreamConstants.CHARACTERS,
- * XMLStreamConstants.CDATA, XMLStreamConstants.SPACE, XMLStreamConstants.ENTITY_REFERENCE
- * @return Returns OMText.
- */
- OMText createOMText(OMContainer parent, String text, int type);
-
- OMText createOMText(OMContainer parent, char[] charArary, int type);
-
- /**
- * @param parent
- * @param text - This text itself can contain a namespace inside it.
- * @param type
- */
- OMText createOMText(OMContainer parent, QName text, int type);
-
- /**
- * @param s
- * @return Returns OMText.
- */
- OMText createOMText(String s);
-
- /**
- * @param s
- * @param type - OMText node can handle SPACE, CHARACTERS, CDATA and ENTITY REFERENCES. For
- * Constants, use either XMLStreamConstants or constants found in OMNode.
- * @return Returns OMText.
- */
- OMText createOMText(String s, int type);
-
- OMText createOMText(String s, String mimeType, boolean optimize);
-
- OMText createOMText(Object dataHandler, boolean optimize);
-
- OMText createOMText(OMContainer parent, String s, String mimeType,
- boolean optimize);
-
- OMText createOMText(String contentID, OMContainer parent,
- OMXMLParserWrapper builder);
-
- OMAttribute createOMAttribute(String localName,
- OMNamespace ns,
- String value);
-
- /**
- * Creates DocType/DTD.
- *
- * @param parent
- * @param content
- * @return Returns doctype.
- */
- OMDocType createOMDocType(OMContainer parent, String content);
-
- /**
- * Creates a PI.
- *
- * @param parent
- * @param piTarget
- * @param piData
- * @return Returns OMProcessingInstruction.
- */
- OMProcessingInstruction createOMProcessingInstruction(OMContainer parent,
- String piTarget, String piData);
-
- /**
- * Creates a comment.
- *
- * @param parent
- * @param content
- * @return Returns OMComment.
- */
- OMComment createOMComment(OMContainer parent, String content);
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axiom.om;
+
+import javax.xml.namespace.QName;
+
+/** Class OMFactory */
+public interface OMFactory {
+
+ /** Creates a new OMDocument. */
+ OMDocument createOMDocument();
+
+ OMDocument createOMDocument(OMXMLParserWrapper builder);
+
+
+ /**
+ * @param localName
+ * @param ns - This can be null
+ */
+ OMElement createOMElement(String localName, OMNamespace ns);
+
+ OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent)
+ throws OMException;
+
+ /**
+ * @param localName
+ * @param ns - this can be null
+ * @param parent
+ * @param builder
+ */
+ OMElement createOMElement(String localName, OMNamespace ns,
+ OMContainer parent,
+ OMXMLParserWrapper builder);
+
+ /**
+ * Construct element with arbitrary data source. This is an optional operation which may not be
+ * supported by all factories.
+ *
+ * @param source
+ * @param localName
+ * @param ns
+ */
+ OMElement createOMElement(OMDataSource source, String localName,
+ OMNamespace ns);
+
+ /**
+ * This is almost the same as as createOMElement(localName,OMNamespace) method above. But some
+ * people may, for some reason, need to use the conventional method of putting a namespace. Or
+ * in other words people might not want to use the new OMNamespace. Well, this is for those
+ * people.
+ *
+ * @param localName
+ * @param namespaceURI
+ * @param namespacePrefix
+ * @return Returns the newly created OMElement.
+ */
+ OMElement createOMElement(String localName,
+ String namespaceURI,
+ String namespacePrefix);
+
+ /**
+ * Create an OMElement with the given QName under the given parent.
+ *
+ * If the QName contains a prefix, we will ensure that an OMNamespace is created
+ * mapping the given namespace to the given prefix. If no prefix is passed, we'll
+ * use whatever's already mapped in the parent, or create a generated one.
+ *
+ * @param qname the QName of the element to create
+ * @param parent the OMContainer in which to place the new element
+ * @return Returns the new OMElement
+ * @throws OMException if there's a namespace mapping problem
+ */
+ OMElement createOMElement(QName qname, OMContainer parent) throws OMException;
+
+ /**
+ * Create an OMElement with the given QName
+ *
+ * If the QName contains a prefix, we will ensure that an OMNamespace is created
+ * mapping the given namespace to the given prefix. If no prefix is passed, we'll
+ * use whatever's already mapped in the parent, or create a generated one.
+ *
+ * @param qname
+ * @return the new OMElement.
+ */
+ OMElement createOMElement(QName qname) throws OMException;
+
+ /**
+ * @param uri
+ * @param prefix
+ * @return Returns OMNameSpace.
+ */
+ OMNamespace createOMNamespace(String uri, String prefix);
+
+ /**
+ * @param parent
+ * @param text
+ * @return Returns OMText.
+ */
+ OMText createOMText(OMContainer parent, String text);
+
+ /**
+ * @param parent
+ * @param text - This text itself can contain a namespace inside it.
+ */
+ OMText createOMText(OMContainer parent, QName text);
+
+ /**
+ * @param parent
+ * @param text
+ * @param type - this should be either of XMLStreamConstants.CHARACTERS,
+ * XMLStreamConstants.CDATA, XMLStreamConstants.SPACE, XMLStreamConstants.ENTITY_REFERENCE
+ * @return Returns OMText.
+ */
+ OMText createOMText(OMContainer parent, String text, int type);
+
+ OMText createOMText(OMContainer parent, char[] charArary, int type);
+
+ /**
+ * @param parent
+ * @param text - This text itself can contain a namespace inside it.
+ * @param type
+ */
+ OMText createOMText(OMContainer parent, QName text, int type);
+
+ /**
+ * @param s
+ * @return Returns OMText.
+ */
+ OMText createOMText(String s);
+
+ /**
+ * @param s
+ * @param type - OMText node can handle SPACE, CHARACTERS, CDATA and ENTITY REFERENCES. For
+ * Constants, use either XMLStreamConstants or constants found in OMNode.
+ * @return Returns OMText.
+ */
+ OMText createOMText(String s, int type);
+
+ OMText createOMText(String s, String mimeType, boolean optimize);
+
+ OMText createOMText(Object dataHandler, boolean optimize);
+
+ OMText createOMText(OMContainer parent, String s, String mimeType,
+ boolean optimize);
+
+ OMText createOMText(String contentID, OMContainer parent,
+ OMXMLParserWrapper builder);
+
+ OMAttribute createOMAttribute(String localName,
+ OMNamespace ns,
+ String value);
+
+ /**
+ * Creates DocType/DTD.
+ *
+ * @param parent
+ * @param content
+ * @return Returns doctype.
+ */
+ OMDocType createOMDocType(OMContainer parent, String content);
+
+ /**
+ * Creates a PI.
+ *
+ * @param parent
+ * @param piTarget
+ * @param piData
+ * @return Returns OMProcessingInstruction.
+ */
+ OMProcessingInstruction createOMProcessingInstruction(OMContainer parent,
+ String piTarget, String piData);
+
+ /**
+ * Creates a comment.
+ *
+ * @param parent
+ * @param content
+ * @return Returns OMComment.
+ */
+ OMComment createOMComment(OMContainer parent, String content);
+}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Fri Mar 23 16:11:57 2007
@@ -1,173 +1,173 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axiom.om.impl.builder;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.OMContainerEx;
-import org.apache.axiom.om.impl.OMNodeEx;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class SAXOMBuilder extends DefaultHandler {
- OMElement root = null;
-
- OMNode lastNode = null;
-
- OMElement nextElem = null;
-
- OMFactory factory = OMAbstractFactory.getOMFactory();
-
- List prefixMappings = new ArrayList();
-
- public void setDocumentLocator(Locator arg0) {
- }
-
- public void startDocument() throws SAXException {
-
- }
-
- public void endDocument() throws SAXException {
- }
-
- protected OMElement createNextElement(String localName) throws OMException {
- OMElement e;
- if (lastNode == null) {
- root = e = factory.createOMElement(localName, null, null, null);
- } else if (lastNode.isComplete()) {
- e = factory.createOMElement(localName, null, lastNode.getParent(),
- null);
- ((OMNodeEx) lastNode).setNextOMSibling(e);
- ((OMNodeEx) e).setPreviousOMSibling(lastNode);
- } else {
- OMContainerEx parent = (OMContainerEx) lastNode;
- e = factory.createOMElement(localName, null, (OMElement) lastNode,
- null);
- parent.setFirstChild(e);
- }
- return e;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
- * java.lang.String)
- */
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
- if (nextElem == null)
- nextElem = createNextElement(null);
- nextElem.declareNamespace(uri, prefix);
- }
-
- public void endPrefixMapping(String arg0) throws SAXException {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
- * java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
- if (localName == null || localName.trim().equals(""))
- localName = qName.substring(qName.indexOf(':') + 1);
- if (nextElem == null)
- nextElem = createNextElement(localName);
- else
- nextElem.setLocalName(localName);
- nextElem
- .setNamespace(nextElem.findNamespace(namespaceURI, null));
- int j = atts.getLength();
- for (int i = 0; i < j; i++)
- nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i),
- nextElem.findNamespace(atts.getURI(i), null));
- lastNode = nextElem;
- nextElem = null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
- * java.lang.String, java.lang.String)
- */
- public void endElement(String arg0, String arg1, String arg2)
- throws SAXException {
- if (lastNode.isComplete()) {
- OMContainer parent = lastNode.getParent();
- ((OMNodeEx) parent).setComplete(true);
- lastNode = (OMNode) parent;
- } else {
- OMElement e = (OMElement) lastNode;
- ((OMNodeEx) e).setComplete(true);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xml.sax.ContentHandler#characters(char[], int, int)
- */
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- if (lastNode == null) {
- throw new SAXException("");
- }
- OMNode node;
- if (lastNode.isComplete()) {
- node =
- factory.createOMText(lastNode.getParent(),
- new String(ch,
- start, length));
- ((OMNodeEx) lastNode).setNextOMSibling(node);
- ((OMNodeEx) node).setPreviousOMSibling(lastNode);
- } else {
- OMContainerEx e = (OMContainerEx) lastNode;
- node = factory.createOMText(e, new String(ch, start, length));
- e.setFirstChild(node);
- }
- lastNode = node;
- }
-
- public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
- throws SAXException {
- }
-
- public void processingInstruction(String arg0, String arg1)
- throws SAXException {
- }
-
- public void skippedEntity(String arg0) throws SAXException {
- }
-
- /** @return Returns the root. */
- public OMElement getRootElement() {
- return root;
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axiom.om.impl.builder;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SAXOMBuilder extends DefaultHandler {
+ OMElement root = null;
+
+ OMNode lastNode = null;
+
+ OMElement nextElem = null;
+
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+
+ List prefixMappings = new ArrayList();
+
+ public void setDocumentLocator(Locator arg0) {
+ }
+
+ public void startDocument() throws SAXException {
+
+ }
+
+ public void endDocument() throws SAXException {
+ }
+
+ protected OMElement createNextElement(String localName) throws OMException {
+ OMElement e;
+ if (lastNode == null) {
+ root = e = factory.createOMElement(localName, null, null, null);
+ } else if (lastNode.isComplete()) {
+ e = factory.createOMElement(localName, null, lastNode.getParent(),
+ null);
+ ((OMNodeEx) lastNode).setNextOMSibling(e);
+ ((OMNodeEx) e).setPreviousOMSibling(lastNode);
+ } else {
+ OMContainerEx parent = (OMContainerEx) lastNode;
+ e = factory.createOMElement(localName, null, (OMElement) lastNode,
+ null);
+ parent.setFirstChild(e);
+ }
+ return e;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
+ * java.lang.String)
+ */
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ if (nextElem == null)
+ nextElem = createNextElement(null);
+ nextElem.declareNamespace(uri, prefix);
+ }
+
+ public void endPrefixMapping(String arg0) throws SAXException {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
+ * java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ public void startElement(String namespaceURI, String localName,
+ String qName, Attributes atts) throws SAXException {
+ if (localName == null || localName.trim().equals(""))
+ localName = qName.substring(qName.indexOf(':') + 1);
+ if (nextElem == null)
+ nextElem = createNextElement(localName);
+ else
+ nextElem.setLocalName(localName);
+ nextElem
+ .setNamespace(nextElem.findNamespace(namespaceURI, null));
+ int j = atts.getLength();
+ for (int i = 0; i < j; i++)
+ nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i),
+ nextElem.findNamespace(atts.getURI(i), null));
+ lastNode = nextElem;
+ nextElem = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public void endElement(String arg0, String arg1, String arg2)
+ throws SAXException {
+ if (lastNode.isComplete()) {
+ OMContainer parent = lastNode.getParent();
+ ((OMNodeEx) parent).setComplete(true);
+ lastNode = (OMNode) parent;
+ } else {
+ OMElement e = (OMElement) lastNode;
+ ((OMNodeEx) e).setComplete(true);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ if (lastNode == null) {
+ throw new SAXException("");
+ }
+ OMNode node;
+ if (lastNode.isComplete()) {
+ node =
+ factory.createOMText(lastNode.getParent(),
+ new String(ch,
+ start, length));
+ ((OMNodeEx) lastNode).setNextOMSibling(node);
+ ((OMNodeEx) node).setPreviousOMSibling(lastNode);
+ } else {
+ OMContainerEx e = (OMContainerEx) lastNode;
+ node = factory.createOMText(e, new String(ch, start, length));
+ e.setFirstChild(node);
+ }
+ lastNode = node;
+ }
+
+ public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
+ throws SAXException {
+ }
+
+ public void processingInstruction(String arg0, String arg1)
+ throws SAXException {
+ }
+
+ public void skippedEntity(String arg0) throws SAXException {
+ }
+
+ /** @return Returns the root. */
+ public OMElement getRootElement() {
+ return root;
+ }
+}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Fri Mar 23 16:11:57 2007
@@ -348,7 +348,7 @@
*/
public Attr getAttributeNodeNS(String namespaceURI, String localName) {
- if (namespaceURI == OMConstants.XMLNS_NS_URI) {
+ if (OMConstants.XMLNS_NS_URI.equals(namespaceURI)) {
OMNamespace ns = this.findNamespaceURI(localName);
String nsuri = ns != null ? ns.getNamespaceURI() : "";
@@ -596,10 +596,12 @@
/** Returns whether this element contains any attribute or not. */
public boolean hasAttributes() {
- boolean flag = false;
- if (this.attributes != null) {
- flag = (this.attributes.getLength() > 0);
- }
+ boolean flag;
+
+ // TODO : Review. This code doesn't make any sense since it always gets overwritten. WTF?
+// if (this.attributes != null) {
+// flag = (this.attributes.getLength() > 0);
+// }
//The namespaces
flag = this.namespace != null;
@@ -607,8 +609,6 @@
if (!flag) {
if (this.namespaces != null) {
flag = !this.namespaces.isEmpty();
- } else if (this.namespace != null) {
- flag = true;
}
}
@@ -1277,7 +1277,7 @@
// check if the parent of this element has the same namespace
// as the default and if NOT add the attr
boolean parentHasSameDefaultNS = this.parentNode != null &&
- this.parentNode.getNamespaceURI() == this.getNamespaceURI() &&
+ this.parentNode.getNamespaceURI().equals(this.getNamespaceURI()) &&
(this.parentNode.getPrefix() == null ||
this.parentNode.getPrefix().equals(""));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Fri Mar 23 16:11:57 2007
@@ -78,6 +78,11 @@
public OMElement createOMElement(String localName, OMNamespace ns,
OMContainer parent) throws OMDOMException {
+ if (parent == null) {
+ return new ElementImpl((DocumentImpl) this.createOMDocument(),
+ localName, (NamespaceImpl) ns, this);
+ }
+
switch (((ParentNode) parent).getNodeType()) {
case Node.ELEMENT_NODE: // We are adding a new child to an elem
ElementImpl parentElem = (ElementImpl) parent;
@@ -178,6 +183,19 @@
}
/**
+ * Create an OMElement with the given QName
+ * <p/>
+ * If the QName contains a prefix, we will ensure that an OMNamespace is created mapping the
+ * given namespace to the given prefix. If no prefix is passed, we'll create a generated one.
+ *
+ * @param qname
+ * @return the new OMElement.
+ */
+ public OMElement createOMElement(QName qname) throws OMException {
+ return createOMElement(qname, null);
+ }
+
+ /**
* Creates a new OMNamespace.
*
* @see org.apache.axiom.om.OMFactory#createOMNamespace(String, String)
@@ -303,7 +321,7 @@
}
public OMComment createOMComment(OMContainer parent, String content) {
- DocumentImpl doc = null;
+ DocumentImpl doc;
if (parent instanceof DocumentImpl) {
doc = (DocumentImpl) parent;
} else {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java Fri Mar 23 16:11:57 2007
@@ -45,7 +45,7 @@
*/
public OMAttributeImpl(String localName, OMNamespace ns, String value, OMFactory factory)
{
- if (localName == null || localName.length() == 0)
+ if (localName == null || localName.trim().length() == 0)
throw new IllegalArgumentException("Local name may not be null or empty");
this.localName = localName;
@@ -80,7 +80,7 @@
* @param localName
*/
public void setLocalName(String localName) {
- if (localName == null || localName.length() == 0)
+ if (localName == null || localName.trim().length() == 0)
throw new IllegalArgumentException("Local name may not be null or empty");
this.localName = localName;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Fri Mar 23 16:11:57 2007
@@ -100,16 +100,34 @@
}
/**
- * Method createOMElement.
+ * Create an OMElement with the given QName under the given parent.
*
- * @param qname
- * @param parent
- * @return Returns OMElement.
- * @throws OMException
+ * If the QName contains a prefix, we will ensure that an OMNamespace is created
+ * mapping the given namespace to the given prefix. If no prefix is passed, we'll
+ * use whatever's already mapped in the parent, or create a generated one.
+ *
+ * @param qname the QName of the element to create
+ * @param parent the OMContainer in which to place the new element
+ * @return Returns the new OMElement
+ * @throws OMException if there's a namespace mapping problem
*/
public OMElement createOMElement(QName qname, OMContainer parent)
throws OMException {
return new OMElementImpl(qname, parent, this);
+ }
+
+ /**
+ * Create an OMElement with the given QName
+ * <p/>
+ * If the QName contains a prefix, we will ensure that an OMNamespace is created mapping the
+ * given namespace to the given prefix. If no prefix is passed, we'll use whatever's already
+ * mapped in the parent, or create a generated one.
+ *
+ * @param qname
+ * @return the new OMElement.
+ */
+ public OMElement createOMElement(QName qname) throws OMException {
+ return new OMElementImpl(qname, null, this);
}
/**
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java Fri Mar 23 16:11:57 2007
@@ -31,14 +31,11 @@
import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.SOAPHeaderBlock;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
/** User: Eran Chinthaka (eran.chinthaka@gmail.com) Date: Feb 8, 2005 Time: 11:06:09 AM */
public class OMLinkedListImplFactoryTest extends AbstractTestCase {
-
- private Log log = LogFactory.getLog(getClass());
-
public OMLinkedListImplFactoryTest(String testName) {
super(testName);
}
@@ -63,27 +60,35 @@
}
- public void testCreateOMElement() {
- try {
- OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
- getTestResourceFile("soap/whitespacedMessage.xml"));
- OMElement documentElement = omBuilder.getDocumentElement();
- OMElement child = omFactory.createOMElement("child",
- namespace,
- documentElement,
- omBuilder);
- assertTrue(
- "OMElement with a builder should start with done = false ",
- !child.isComplete());
- assertTrue("This OMElement must have a builder ",
- child.getBuilder() instanceof OMXMLParserWrapper);
-
- } catch (Exception e) {
- log.info(e.getMessage());
- }
+ public void testCreateOMElement() throws Exception {
+ OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/whitespacedMessage.xml"));
+ OMElement envelope = omBuilder.getDocumentElement();
+ OMElement body = envelope.getFirstElement();
+
+ OMElement child = omFactory.createOMElement("child",
+ namespace,
+ body,
+ omBuilder);
+ assertFalse("OMElement with a builder should start with done = false",
+ child.isComplete());
+ assertNotNull("This OMElement must have a builder", child.getBuilder());
+
+ // Try the QName version
+ QName qname = new QName(nsUri, "local", nsPrefix);
+ OMElement element = omFactory.createOMElement(qname);
+
+ assertNotNull(element);
+
+ // Now make one with a parent (and thus inherit the NS)
+ element = omFactory.createOMElement(qname, child);
+ assertNotNull(element);
+ assertEquals("Namespace wasn't found correctly",
+ element.getNamespace(),
+ namespace);
}
- public void testCreateOMNamespace() {
+ public void testCreateOMNamespace() throws Exception {
assertTrue("OMNamespace uri not correct",
nsUri.equals(
namespace.getNamespaceURI())); // here equalsIgnoreCase should not be used as case does matter
@@ -105,128 +110,97 @@
}
- public void testCreateSOAPBody() {
- try {
- OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
- getTestResourceFile("soap/minimalMessage.xml"));
- SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
- SOAPBody soapBodyOne = omFactory.createSOAPBody(soapEnvelope);
- assertTrue(
- "Programatically created SOAPBody should have done = true ",
- soapBodyOne.isComplete());
- soapBodyOne.detach();
- SOAPBody soapBodyTwo = omFactory.createSOAPBody(soapEnvelope,
- omBuilder);
- assertTrue(
- "SOAPBody with a builder should start with done = false ",
- !soapBodyTwo.isComplete());
- assertTrue("This SOAPBody must have a builder ",
- soapBodyTwo.getBuilder() instanceof OMXMLParserWrapper);
-
-
- } catch (Exception e) {
- log.info(e.getMessage());
- }
- }
-
- public void testCreateSOAPEnvelope() {
- try {
- omFactory.createOMNamespace(
- SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,
- SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);
- SOAPEnvelope soapEnvelopeTwo = omFactory.createSOAPEnvelope();
- assertTrue(
- "Programatically created SOAPEnvelope should have done = true ",
- soapEnvelopeTwo.isComplete());
- SOAPEnvelope soapEnvelope = omFactory.createSOAPEnvelope(
- OMTestUtils.getOMBuilder(
- getTestResourceFile("soap/minimalMessage.xml")));
- assertTrue(
- "SOAPEnvelope with a builder should start with done = false ",
- !soapEnvelope.isComplete());
- assertTrue("This SOAPEnvelope must have a builder ",
- soapEnvelope.getBuilder() instanceof OMXMLParserWrapper);
-
-
- } catch (Exception e) {
- log.info(e.getMessage());
- }
- }
-
- public void testCreateSOAPHeader() {
- try {
- OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
- getTestResourceFile("soap/minimalMessage.xml"));
- SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
- SOAPHeader soapHeader = omFactory.createSOAPHeader(soapEnvelope);
- assertTrue(
- "Programatically created SOAPHeader should have done = true ",
- soapHeader.isComplete());
- soapHeader.detach();
- SOAPHeader soapHeaderTwo = omFactory.createSOAPHeader(soapEnvelope,
- omBuilder);
- assertTrue(
- "SOAPHeader with a builder should start with done = false ",
- !soapHeaderTwo.isComplete());
- assertTrue("This SOAPHeader must have a builder ",
- soapHeaderTwo.getBuilder() instanceof OMXMLParserWrapper);
-
-
- } catch (Exception e) {
- log.info(e.getMessage());
- }
- }
-
- public void testCreateSOAPHeaderBlock() {
- try {
- OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
- getTestResourceFile("soap/soapmessage.xml"));
- SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
- SOAPHeader soapHeader = soapEnvelope.getHeader();
- SOAPHeaderBlock soapHeaderBlock = omFactory.createSOAPHeaderBlock(
- "soapHeaderBlockOne", namespace, soapHeader);
- assertTrue(
- "Programatically created SOAPHeaderBlock should have done = true ",
- soapHeaderBlock.isComplete());
- SOAPHeaderBlock soapHeaderBlockTwo = omFactory.createSOAPHeaderBlock(
- "soapHeaderBlockOne", namespace, soapHeader, omBuilder);
- assertTrue(
- "SOAPHeaderBlock with a builder should start with done = false ",
- !soapHeaderBlockTwo.isComplete());
- assertTrue("This SOAPHeaderBlock must have a builder ",
- soapHeaderBlockTwo.getBuilder() instanceof OMXMLParserWrapper);
-
-
- } catch (Exception e) {
- log.info(e.getMessage());
- }
- }
-
- public void testCreateSOAPFault() {
- try {
- OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
- getTestResourceFile("soap/soapmessage.xml"));
- SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
- SOAPBody soapBody = soapEnvelope.getBody();
- SOAPFault soapFault = omFactory.createSOAPFault(soapBody,
- new Exception(" this is just a test "));
- assertTrue(
- "Programatically created SOAPFault should have done = true ",
- soapFault.isComplete());
- soapFault.detach();
- SOAPFault soapFaultTwo = omFactory.createSOAPFault(soapBody,
- omBuilder);
- assertTrue(
- "SOAPFault with a builder should start with done = false ",
- !soapFaultTwo.isComplete());
- assertTrue("This SOAPFault must have a builder ",
- soapFaultTwo.getBuilder() instanceof OMXMLParserWrapper);
-
-
- } catch (Exception e) {
- log.info(e.getMessage());
- }
+ public void testCreateSOAPBody() throws Exception {
+ OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/minimalMessage.xml"));
+ SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
+ SOAPBody soapBodyOne = omFactory.createSOAPBody(soapEnvelope);
+ assertTrue(
+ "Programatically created SOAPBody should have done = true ",
+ soapBodyOne.isComplete());
+ }
+
+ public void testCreateSOAPBodyWithBuilder() throws Exception {
+ OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/minimalMessage.xml"));
+ SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
+
+ SOAPBody soapBodyTwo = omFactory.createSOAPBody(soapEnvelope,
+ omBuilder);
+ assertTrue(
+ "SOAPBody with a builder should start with done = false ",
+ !soapBodyTwo.isComplete());
+ assertNotNull("This SOAPBody must have a builder ", soapBodyTwo.getBuilder());
+ }
+
+ public void testCreateSOAPEnvelope() throws Exception {
+ omFactory.createOMNamespace(
+ SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,
+ SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);
+ SOAPEnvelope soapEnvelopeTwo = omFactory.createSOAPEnvelope();
+ assertTrue(
+ "Programatically created SOAPEnvelope should have done = true ",
+ soapEnvelopeTwo.isComplete());
+ SOAPEnvelope soapEnvelope = omFactory.createSOAPEnvelope(
+ OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/minimalMessage.xml")));
+ assertTrue(
+ "SOAPEnvelope with a builder should start with done = false ",
+ !soapEnvelope.isComplete());
+ assertNotNull("This SOAPEnvelope must have a builder", soapEnvelope.getBuilder());
+ }
+
+ public void testCreateSOAPHeader() throws Exception {
+ OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/minimalMessage.xml"));
+ SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
+ SOAPHeader soapHeader = omFactory.createSOAPHeader(soapEnvelope);
+ assertTrue(
+ "Programatically created SOAPHeader should have done = true ",
+ soapHeader.isComplete());
+ soapHeader.detach();
+ SOAPHeader soapHeaderTwo = omFactory.createSOAPHeader(soapEnvelope,
+ omBuilder);
+ assertTrue(
+ "SOAPHeader with a builder should start with done = false ",
+ !soapHeaderTwo.isComplete());
+ assertNotNull("This SOAPHeader must have a builder ", soapHeaderTwo.getBuilder());
}
+ public void testCreateSOAPHeaderBlock() throws Exception {
+ OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/soapmessage.xml"));
+ SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
+ SOAPHeader soapHeader = soapEnvelope.getHeader();
+ SOAPHeaderBlock soapHeaderBlock = omFactory.createSOAPHeaderBlock(
+ "soapHeaderBlockOne", namespace, soapHeader);
+ assertTrue(
+ "Programatically created SOAPHeaderBlock should have done = true ",
+ soapHeaderBlock.isComplete());
+ SOAPHeaderBlock soapHeaderBlockTwo = omFactory.createSOAPHeaderBlock(
+ "soapHeaderBlockOne", namespace, soapHeader, omBuilder);
+ assertTrue(
+ "SOAPHeaderBlock with a builder should start with done = false ",
+ !soapHeaderBlockTwo.isComplete());
+ assertNotNull("SOAPHeaderBlock must have a builder", soapHeaderBlockTwo.getBuilder());
+ }
+ public void testCreateSOAPFault() throws Exception {
+ OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
+ getTestResourceFile("soap/soapmessage.xml"));
+ SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
+ SOAPBody soapBody = soapEnvelope.getBody();
+ SOAPFault soapFault = omFactory.createSOAPFault(soapBody,
+ new Exception(" this is just a test "));
+ assertTrue(
+ "Programatically created SOAPFault should have done = true ",
+ soapFault.isComplete());
+ soapFault.detach();
+ SOAPFault soapFaultTwo = omFactory.createSOAPFault(soapBody,
+ omBuilder);
+ assertTrue(
+ "SOAPFault with a builder should start with done = false ",
+ !soapFaultTwo.isComplete());
+ assertNotNull("This SOAPFault must have a builder", soapFaultTwo.getBuilder());
+ }
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java?view=diff&rev=521935&r1=521934&r2=521935
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java Fri Mar 23 16:11:57 2007
@@ -49,6 +49,16 @@
fail("Empty localname was accepted!");
}
+ public void testWhitespaceLocalName() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ try {
+ factory.createOMAttribute(" ", null, null);
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ fail("Whitespace localname was accepted!");
+ }
+
public void testAddAttribute() throws Exception {
String xmlString =
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header name = \"jhon\"/><soapenv:Body><my:uploadFileUsingMTOM xmlns:my=\"http://localhost/my\"><my:folderName>/home/saliya/Desktop</my:folderName></my:uploadFileUsingMTOM></soapenv:Body><Body>TTTT</Body> </soapenv:Envelope>";
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org