You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by as...@apache.org on 2004/10/15 20:11:05 UTC
svn commit: rev 54859 - in webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src: java/org/apache/axis/om/impl java/org/apache/axis/om/impl/util test/org/apache/axis/om test/org/apache/axis/om/util
Author: aslom
Date: Fri Oct 15 11:11:04 2004
New Revision: 54859
Added:
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/OMElementTest.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/util/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/util/OMNodeBuilder.java
Modified:
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMElementImpl.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamedNodeImpl.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamespaceImpl.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNodeImpl.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMXmlPullParserWrapper.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenIterator.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenQNameIterator.java
Log:
applied patch
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMElementImpl.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMElementImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMElementImpl.java Fri Oct 15 11:11:04 2004
@@ -79,6 +79,7 @@
if (firstChild != null)
firstChild.setPreviousSibling(child);
child.setParent(this);
+ child.setComplete(true);
firstChild = child;
}
@@ -263,7 +264,7 @@
/**
* This will return the literal value of the node.
* OMText --> the text
- * OMElement --> name of the element as a QName in String format
+ * OMElement --> local name of the element in String format
* OMAttribute --> the value of the attribue
*
* @return
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamedNodeImpl.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamedNodeImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamedNodeImpl.java Fri Oct 15 11:11:04 2004
@@ -70,8 +70,30 @@
ps.print(localName);
}
- public QName getQName(){
+ public QName getQName() {
QName qName = new QName(ns.getValue(), ns.getPrefix(), localName);
return qName;
}
+
+// /**
+// * Equals method of QName seems doesn't working the way I need in this situation.
+// * So implementing my own !!
+// *
+// * @param qName
+// * @return
+// */
+// public boolean isQNameEquals(QName qName) {
+// String thatLocalName = qName.getLocalName();
+//
+// return ((thatLocalName == null && this.localName == null) || (thatLocalName != null && thatLocalName.equalsIgnoreCase(this.localName)))
+// && ns.equals(qName.getNamespaceURI(), qName.getPrefix());
+// }
+//
+// private String getStringValue(String s) {
+// if (s == null) {
+// return "null";
+// }
+//
+// return s;
+// }
}
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamespaceImpl.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamespaceImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamespaceImpl.java Fri Oct 15 11:11:04 2004
@@ -28,7 +28,12 @@
public class OMNamespaceImpl extends OMNodeImpl implements OMNamespace {
private String prefix;
- protected OMNamespaceImpl(String uri, String prefix) {
+ /**
+ *
+ * @param uri
+ * @param prefix
+ */
+ public OMNamespaceImpl(String uri, String prefix) {
value = uri;
this.prefix = prefix;
}
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNodeImpl.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNodeImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNodeImpl.java Fri Oct 15 11:11:04 2004
@@ -83,7 +83,7 @@
/**
* This will return the literal value of the node.
* OMText --> the text
- * OMElement --> name of the element as a QName in String format
+ * OMElement --> local name of the element in String format
* OMAttribute --> the value of the attribue
*
* @return
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMXmlPullParserWrapper.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMXmlPullParserWrapper.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMXmlPullParserWrapper.java Fri Oct 15 11:11:04 2004
@@ -116,7 +116,7 @@
navigator.init(node);
}
- // TODO:
+
public int next() throws OMException {
try {
if (navigate) {
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenIterator.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenIterator.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenIterator.java Fri Oct 15 11:11:04 2004
@@ -59,7 +59,7 @@
* @return <tt>true</tt> if the iterator has more elements.
*/
public boolean hasNext() {
- return (currentChild != null && currentChild.getNextSibling() != null);
+ return (currentChild != null);
}
/**
@@ -72,89 +72,9 @@
public Object next() {
if (hasNext()) {
+ OMNode returnNode = currentChild;
currentChild = currentChild.getNextSibling();
- return currentChild;
- }
- return null;
-
- }
-}
-package org.apache.axis.om.impl.util;
-
-import org.apache.axis.om.OMNode;
-
-import java.util.Iterator;
-
-/**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
- * User: Eran Chinthaka - Lanka Software Foundation
- * Date: Oct 11, 2004
- * Time: 11:23:07 AM
- */
-public class OMChildrenIterator implements Iterator {
-
- private OMNode currentChild;
-
- public OMChildrenIterator(OMNode currentChild) {
- this.currentChild = currentChild;
- }
-
- /**
- * Removes from the underlying collection the last element returned by the
- * iterator (optional operation). This method can be called only once per
- * call to <tt>next</tt>. The behavior of an iterator is unspecified if
- * the underlying collection is modified while the iteration is in
- * progress in any way other than by calling this method.
- *
- * @throws UnsupportedOperationException if the <tt>remove</tt>
- * operation is not supported by this Iterator.
- * @throws IllegalStateException if the <tt>next</tt> method has not
- * yet been called, or the <tt>remove</tt> method has already
- * been called after the last call to the <tt>next</tt>
- * method.
- */
- public void remove() {
- OMNode temp = currentChild.getNextSibling();
- currentChild.detach();
- currentChild = temp;
- }
-
- /**
- * Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if <tt>next</tt> would return an element
- * rather than throwing an exception.)
- *
- * @return <tt>true</tt> if the iterator has more elements.
- */
- public boolean hasNext() {
- return (currentChild == null || currentChild.getNextSibling() == null);
- }
-
- /**
- * Returns the next element in the iteration.
- *
- * @return the next element in the iteration.
- * @throws java.util.NoSuchElementException
- * iteration has no more elements.
- */
- public Object next() {
-
- if (hasNext()) {
- currentChild = currentChild.getNextSibling();
- return currentChild;
+ return returnNode;
}
return null;
Modified: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenQNameIterator.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenQNameIterator.java (original)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/util/OMChildrenQNameIterator.java Fri Oct 15 11:11:04 2004
@@ -28,7 +28,6 @@
*/
public class OMChildrenQNameIterator implements Iterator {
- private OMNamedNodeImpl currentNamedNode;
private OMNode omNode;
private QName qName;
@@ -66,36 +65,30 @@
*/
public boolean hasNext() {
- if (omNode != null) {
+ boolean needToMoveForward = true;
+ boolean isMatchingNodeFound = false;
- if(picked){
- omNode = omNode.getNextSibling();
- picked = false;
- }
-
- if ((omNode instanceof OMNamedNodeImpl) && ((OMNamedNodeImpl)omNode).getQName().equals(qName)) {
- currentNamedNode = (OMNamedNodeImpl) omNode;
- return true;
- }
+ while (needToMoveForward) {
+ if (omNode != null) {
- while (!(omNode.getNextSibling() instanceof OMNamedNodeImpl)) {
- omNode = omNode.getNextSibling();
- if (omNode == null) {
- return false;
+ System.out.println("Checking the current node, *" + omNode.getValue() + "*");
+ // check the current node for the criteria
+ if ((omNode instanceof OMNamedNodeImpl) && ((OMNamedNodeImpl) omNode).getQName().equals(qName)) {
+ isMatchingNodeFound = true;
+ needToMoveForward = false;
+ System.out.println("One Found");
+ } else {
+
+ System.out.println("Moving to next Sibling ...");
+ // get the next named node
+ omNode = omNode.getNextSibling();
+ isMatchingNodeFound = needToMoveForward = !(omNode == null);
}
- }
-
- // now the currentNode holds an instance of an OMNamedNode
- omNode = omNode.getNextSibling();
- currentNamedNode = (OMNamedNodeImpl) omNode;
- if (currentNamedNode.getQName().equals(qName)) {
- return true;
} else {
- return hasNext();
+ needToMoveForward = false;
}
-
}
- return false;
+ return isMatchingNodeFound;
}
/**
@@ -106,11 +99,10 @@
* iteration has no more elements.
*/
public Object next() {
- if (hasNext()) {
- picked = true;
- return currentNamedNode;
- }
-
- return null;
+ OMNode tempNode = omNode;
+ omNode = omNode.getNextSibling();
+ return tempNode;
}
+
+
}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/OMElementTest.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/OMElementTest.java Fri Oct 15 11:11:04 2004
@@ -0,0 +1,197 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * Author: Eran Chinthaka - Lanka Software Foundation
+ * Date: Oct 14, 2004
+ * Time: 12:42:46 PM
+ */
+package org.apache.axis.om;
+
+import junit.framework.TestCase;
+import org.apache.axis.om.impl.OMXmlPullParserWrapper;
+import org.apache.axis.om.util.OMNodeBuilder;
+import org.apache.xml.utils.QName;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserFactory;
+
+import java.io.FileReader;
+import java.util.Iterator;
+
+
+public class OMElementTest extends TestCase {
+ private static final String IN_FILE_NAME = "resources/soapmessage.xml";
+ private OMElement root;
+ private OMXmlPullParserWrapper omXmlPullParserWrapper;
+
+ public static void main(String[] args) {
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ root = getOMBuilder().getDocument().getRootElement();
+ }
+
+ private OMXmlPullParserWrapper getOMBuilder() throws Exception {
+ XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
+ parser.setInput(new FileReader(IN_FILE_NAME));
+ omXmlPullParserWrapper = new OMXmlPullParserWrapper(parser);
+ return omXmlPullParserWrapper;
+ }
+
+ public final void testAddChild() {
+
+ System.out.print("Testing addChild(OMNode) .....");
+
+ // add new child with the name TestElement
+ OMNamespace omNamespace = OMNodeBuilder.createOMNamespace("http://opensource.lk/chinthaka", "prefix");
+ root.addChild(OMNodeBuilder.createOMElement("TestElement", omNamespace, root, omXmlPullParserWrapper));
+
+ // search for the child
+ boolean newChildFound = false;
+ Iterator iterator = root.getChildren();
+ while (iterator.hasNext()) {
+ OMNode omNode = (OMNode) iterator.next();
+ if (omNode.getValue().equalsIgnoreCase("TestElement")) {
+ newChildFound = true;
+ }
+ }
+ assertTrue(newChildFound);
+ }
+
+
+ public final void testGetChildrenWithName() {
+ System.out.println("Testing getChildrenWithQName(QName) ......");
+
+ // add new child with the name TestElement
+ OMNamespace omNamespace = OMNodeBuilder.createOMNamespace("http://opensource.lk/chinthaka", "prefix");
+ root.addChild(OMNodeBuilder.createOMElement("TestElement", omNamespace, root, omXmlPullParserWrapper));
+
+ Iterator iter = root.getChildrenWithName(new QName("http://opensource.lk/chinthaka", "TestElement"));
+ int childrenCount = 0;
+ while (iter.hasNext()) {
+ iter.next();
+ childrenCount ++;
+ }
+
+ assertTrue("getChildrenWithName is not working properly", childrenCount == 1);
+
+ }
+
+ public final void testGetChildren() {
+ Iterator childrenIterator = root.getChildren();
+
+ while (childrenIterator.hasNext()) {
+ OMNode omNode = (OMNode) childrenIterator.next();
+
+ }
+ }
+
+ public final void testCreateNamespace() {
+ //TODO Implement createNamespace().
+ }
+
+ public final void testResolveNamespace() {
+ //TODO Implement resolveNamespace().
+ }
+
+ public final void testGetAttributeWithQName() {
+ //TODO Implement getAttributeWithQName().
+ }
+
+ public final void testGetAttributes() {
+ //TODO Implement getAttributes().
+ }
+
+ public final void testInsertAttribute() {
+ //TODO Implement insertAttribute().
+ }
+
+ public final void testRemoveAttribute() {
+ //TODO Implement removeAttribute().
+ }
+
+ public final void testGetLocalName() {
+ //TODO Implement getLocalName().
+ }
+
+ public final void testSetLocalName() {
+ //TODO Implement setLocalName().
+ }
+
+ public final void testGetNamespace() {
+ //TODO Implement getNamespace().
+ }
+
+ public final void testSetNamespace() {
+ //TODO Implement setNamespace().
+ }
+
+ public final void testGetParent() {
+ //TODO Implement getParent().
+ }
+
+ public final void testSetParent() {
+ //TODO Implement setParent().
+ }
+
+ public final void testGetNextSibling() {
+ //TODO Implement getNextSibling().
+ }
+
+ public final void testSetNextSibling() {
+ //TODO Implement setNextSibling().
+ }
+
+ public final void testGetValue() {
+ //TODO Implement getValue().
+ }
+
+ public final void testSetValue() {
+ //TODO Implement setValue().
+ }
+
+ public final void testIsComplete() {
+ //TODO Implement isComplete().
+ }
+
+ public final void testSetComplete() {
+ //TODO Implement setComplete().
+ }
+
+ public final void testDetach() {
+ //TODO Implement detach().
+ }
+
+ public final void testInsertSiblingAfter() {
+ //TODO Implement insertSiblingAfter().
+ }
+
+ public final void testInsertSiblingBefore() {
+ //TODO Implement insertSiblingBefore().
+ }
+
+ public final void testGetType() {
+ //TODO Implement getType().
+ }
+
+ public final void testSetType() {
+ //TODO Implement setType().
+ }
+
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/util/OMNodeBuilder.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/util/OMNodeBuilder.java Fri Oct 15 11:11:04 2004
@@ -0,0 +1,72 @@
+package org.apache.axis.om.util;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.impl.OMElementImpl;
+import org.apache.axis.om.impl.OMXmlPullParserWrapper;
+import org.apache.axis.om.impl.OMNamespaceImpl;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * User: Eran Chinthaka - Lanka Software Foundation
+ * Date: Oct 14, 2004
+ * Time: 1:19:29 PM
+ *
+ * I created this class to be dependant on the implementation, so that one has to change only this class
+ * to test a different implementation which implements the proposed OM API
+ */
+public class OMNodeBuilder {
+ /**
+ *
+ * @param parent
+ * @return
+ */
+ public static OMElement createOMElement(OMElement parent){
+ return new OMElementImpl(parent);
+ }
+
+ /**
+ *
+ * @param localName
+ * @param namespace
+ * @return
+ */
+ public static OMElement createOMElement(String localName, OMNamespace namespace){
+ return new OMElementImpl(localName, namespace);
+ }
+
+ /**
+ *
+ * @param localName
+ * @param namespace
+ * @param parent
+ * @param pullParserWrapper
+ * @return
+ */
+ public static OMElement createOMElement(String localName, OMNamespace namespace, OMElement parent, OMXmlPullParserWrapper pullParserWrapper){
+ return new OMElementImpl(localName, namespace, parent, pullParserWrapper);
+ }
+
+ /**
+ *
+ * @param uri
+ * @param prefix
+ * @return
+ */
+ public static OMNamespace createOMNamespace(String uri, String prefix){
+ return new OMNamespaceImpl(uri, prefix);
+ }
+}