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/07 10:54:26 UTC
svn commit: rev 53951 - in webservices/axis/trunk/java/dev/scratch/chinthaka: . OMAPI_with_Impl OMAPI_with_Impl/resources OMAPI_with_Impl/src OMAPI_with_Impl/src/java OMAPI_with_Impl/src/java/org OMAPI_with_Impl/src/java/org/apache OMAPI_with_Impl/src/java/org/apache/axis OMAPI_with_Impl/src/java/org/apache/axis/om OMAPI_with_Impl/src/java/org/apache/axis/om/impl OMAPI_with_Impl/src/test OMAPI_with_Impl/src/test/org OMAPI_with_Impl/src/test/org/apache OMAPI_with_Impl/src/test/org/apache/axis OMAPI_with_Impl/src/test/org/apache/axis/om
Author: aslom
Date: Thu Oct 7 01:54:25 2004
New Revision: 53951
Added:
webservices/axis/trunk/java/dev/scratch/chinthaka/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/readme.txt
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/soapmessage.xml
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/soapmessage1.xml
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/testFile.xml
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/tester-out.xml
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMAttribute.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMDocument.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMElement.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMException.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNamedNode.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNamespace.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNode.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMText.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/Printable.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMAttributeImpl.java
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMDocumentImpl.java
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/OMNavigator.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/OMTextImpl.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/test/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/
webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/Tester.java
Log:
Chinthaka patch applied
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/readme.txt
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/readme.txt Thu Oct 7 01:54:25 2004
@@ -0,0 +1,5 @@
+This is an implementations Linked List OM model, on top of the proposed OM API (in chinthaka_ajith area).
+
+There is a test class under the test package, one can run and test the system. Sample files are under the resources foler.
+
+Eran Chinthaka
\ No newline at end of file
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/soapmessage.xml
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/soapmessage.xml Thu Oct 7 01:54:25 2004
@@ -0,0 +1,15 @@
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
+ <soapenv:Header>
+ <wsa:MessageID soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>
+ <wsa:To soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To>
+ <wsa:From soapenv:mustUnderstand="0">
+ <Address xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</Address>
+ </wsa:From>
+ </soapenv:Header>
+ <soapenv:Body>
+ <ns1:getBalance soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://localhost:8081/axis/services/BankPort">
+ <accountNo href="#id0"/>
+ </ns1:getBalance>
+ <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1001</multiRef>
+ </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/soapmessage1.xml
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/soapmessage1.xml Thu Oct 7 01:54:25 2004
@@ -0,0 +1 @@
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"><soapenv:Header><wsa:MessageID soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID><wsa:To soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To><wsa:From soapenv:mustUnderstand="0"><Address xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</Address></wsa:From></soapenv:Header><soapenv:Body><ns1:getBalance soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://localhost:8081/axis/services/BankPort"><accountNo href="#id0"/></ns1:getBalance><multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1001</multiRef></soapenv:Body></soapenv:Envelope>
\ No newline at end of file
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/testFile.xml
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/testFile.xml Thu Oct 7 01:54:25 2004
@@ -0,0 +1,7 @@
+<root>
+ <name type="original">
+ <firstname>Ajith</firstname>
+ <surname>Ranabahu</surname>
+ </name>
+ <age>26</age>
+</root>
\ No newline at end of file
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/tester-out.xml
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/resources/tester-out.xml Thu Oct 7 01:54:25 2004
@@ -0,0 +1 @@
+<soapenv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsa:MessageID soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID><wsa:To soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To><wsa:From soapenv:mustUnderstand="0"><Address xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</Address></wsa:From><wsa:RelatesTo soapenv:mustUnderstand="0" RelationshipType="wsa:Reply">uuid:3821F4F0-D020-11D8-A10A-E4EE6425FCB0</wsa:RelatesTo></soapenv:Header></soapenv:Envelope>
\ No newline at end of file
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMAttribute.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMAttribute.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,28 @@
+package org.apache.axis.om;
+
+/**
+ * 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 4, 2004
+ * Time: 11:49:01 AM
+ * <p/>
+ * One must implement relevant constructors for the class implementing this interface
+ * all the things like namespace, parent, value, etc., that should come in this are defined in base classes
+ */
+public interface OMAttribute extends OMNamedNode {
+
+
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMDocument.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMDocument.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,31 @@
+package org.apache.axis.om;
+
+/**
+ * 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.
+ *
+ * @author Axis team
+ * Date: Oct 4, 2004
+ * Time: 4:48:10 PM
+ */
+public interface OMDocument extends OMNode {
+
+ /**
+ * Get the root element of this document
+ *
+ * @return the root element
+ */
+ OMElement getDocumentElement();
+
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMElement.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMElement.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,87 @@
+package org.apache.axis.om;
+
+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 4, 2004
+ * Time: 11:52:18 AM
+ * <p/>
+ * One must make sure to insert relevant constructors for the classes that are implementing this interface
+ */
+public interface OMElement extends OMNamedNode {
+
+ /**
+ * This will add child to the element. One can decide whether he append the child or he adds to the
+ * front of the children list
+ *
+ * @param omNode
+ */
+ public void addChild(OMNode omNode);
+
+ /**
+ * This returns a collection of this element.
+ * Children can be of types OMElement, OMText.
+ */
+ public Iterator getChildren();
+
+ /**
+ * THis will create a namespace in the current element scope
+ *
+ * @param uri
+ * @param prefix
+ * @return
+ */
+ public OMNamespace createNamespace(String uri, String prefix);
+
+ /**
+ * This will find a namespace with the given uri and prefix, in the scope of the docuemnt.
+ * This will start to find from the current element and goes up in the hiararchy until this finds one.
+ * If none is found, return null
+ *
+ * @param uri
+ * @param prefix
+ * @return
+ * @throws OMException
+ */
+ public OMNamespace resolveNamespace(String uri, String prefix) throws OMException;
+
+ /**
+ * This will returns the first attribute of the element or null, if none is present
+ *
+ * @return
+ */
+ public OMAttribute getFirstAttribute();
+
+ /**
+ * This will return a List of OMAttributes
+ *
+ * @return
+ */
+ public Iterator getAttributes();
+
+ /**
+ * This will insert attribute to this element. Implementor can decide as to insert this
+ * in the front or at the end of set of attributes
+ *
+ * @param attr
+ */
+ public void insertAttribute(OMAttribute attr);
+
+ public void removeAttribute(OMAttribute attr);
+
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMException.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMException.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,37 @@
+package org.apache.axis.om;
+
+/**
+ * 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 4, 2004
+ * Time: 11:47:19 AM
+ */
+public class OMException extends RuntimeException {
+ public OMException() {
+ }
+
+ public OMException(String message) {
+ super(message);
+ }
+
+ public OMException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public OMException(Throwable cause) {
+ super(cause);
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNamedNode.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNamedNode.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,39 @@
+package org.apache.axis.om;
+
+
+/**
+ * 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 4, 2004
+ * Time: 11:39:01 AM
+ * <p/>
+ * OMElement and OMAttribute must have namespace support and those two behave in same manner as far as the namespaces are concerned.
+ * So one can implement this interface specific methods in an abstract class.
+ */
+public interface OMNamedNode extends OMNode {
+
+ String getLocalName();
+
+ void setLocalName(String localName);
+
+
+ OMNamespace getNamespace() throws OMException;
+
+ /**
+ * @param namespace
+ */
+ void setNamespace(OMNamespace namespace);
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNamespace.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNamespace.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,34 @@
+package org.apache.axis.om;
+
+/**
+ * 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 4, 2004
+ * Time: 1:24:00 PM
+ */
+public interface OMNamespace extends OMNode {
+ //Constructors are not allowed in interfaces!!!!
+ //public OMNamespace(String uri, String prefix);
+
+ public boolean equals(OMNamespace ns);
+
+ public boolean equals(String uri, String prefix);
+
+
+ public boolean isDefaultNs();
+
+ public String getPrefix();
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNode.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMNode.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,124 @@
+package org.apache.axis.om;
+
+
+
+
+/**
+ * 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 1, 2004
+ * Time: 3:36:14 PM
+ */
+public interface OMNode {
+ //==================================================================================
+
+ // Followings are the codes for node types. Extracted these from DOM API
+ /**
+ * The node is an <code>Element</code>.
+ */
+ public static final short ELEMENT_NODE = 1;
+ /**
+ * The node is an <code>Attr</code>.
+ */
+ public static final short ATTRIBUTE_NODE = 2;
+ /**
+ * The node is a <code>Text</code> node.
+ */
+ public static final short TEXT_NODE = 3;
+ /**
+ * The node is a <code>CDATASection</code>.
+ */
+ public static final short CDATA_SECTION_NODE = 4;
+
+ /**
+ * The node is a <code>Comment</code>.
+ */
+ public static final short COMMENT_NODE = 8;
+ /**
+ * The node is a <code>Document</code>.
+ */
+ public static final short DOCUMENT_NODE = 9;
+
+ //==================================================================================
+
+ /**
+ * This method should return the immediate parent of the node.
+ * Parent is always an Element
+ *
+ * @return
+ * @throws OMException
+ */
+ public OMElement getParent() throws OMException;
+
+ public void setParent(OMElement element);
+
+ /**
+ * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+ *
+ * @return
+ * @throws OMException
+ */
+ public OMNode getNextSibling() throws OMException;
+
+ public void setNextSibling(OMNode node);
+
+ /**
+ * This will return the literal value of the node.
+ * OMText --> the text
+ * OMElement --> name of the element as a QName in String format
+ * OMAttribute --> the value of the attribue
+ *
+ * @return
+ * @throws OMException
+ */
+ public String getValue() throws OMException;
+
+ public void setValue(String value);
+
+ /**
+ * this will indicate whether parser has parsed this information item completely or not.
+ * If somethings info are not available in the item, one has to check this attribute to make sure that, this
+ * item has been parsed completely or not.
+ *
+ * @return
+ */
+ public boolean isComplete();
+
+ public void setComplete(boolean state);
+
+ /**
+ * This will remove this information item and its children, from the model completely
+ *
+ * @throws OMException
+ */
+ public void detach() throws OMException;
+
+ /**
+ * This will insert a sibling just after the current information item.
+ *
+ * @param sibling
+ * @throws OMException
+ */
+ public void insertSiblingAfter(OMNode sibling) throws OMException;
+
+ /**
+ * This will insert a sibling just before the current information item
+ *
+ * @param sibling
+ * @throws OMException
+ */
+ public void insertSiblingBefore(OMNode sibling) throws OMException;
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMText.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/OMText.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,32 @@
+package org.apache.axis.om;
+
+/**
+ * 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 4, 2004
+ * Time: 2:04:43 PM
+ */
+public interface OMText extends OMNode {
+ /**
+ * We use the OMText class to hold comments, text, characterData, CData, etc.,
+ * The codes are found in OMNode class
+ *
+ * @param type
+ */
+ public void setTextType(short type);
+
+ public short getTextType();
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/Printable.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/Printable.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,29 @@
+package org.apache.axis.om;
+
+import java.io.PrintStream;
+
+/**
+ * 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 6, 2004
+ * Time: 11:36:01 AM
+ * <p/>
+ * A component that implements this interface is printable to an outputstream
+ */
+public interface Printable {
+
+ public void print(PrintStream ps) throws OMException;
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMAttributeImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMAttributeImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,75 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNamespace;
+
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 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 6, 2004
+ * Time: 11:43:23 AM
+ */
+public class OMAttributeImpl extends OMNamedNodeImpl implements OMAttribute {
+ private static String QUOTE_ENTITY = """;
+ private static Matcher matcher = Pattern.compile("\"").matcher(null);
+
+ public OMAttributeImpl(String localName, OMNamespace ns, String value, OMElement parent) {
+ super(localName, ns, parent);
+ setValue(value);
+ }
+
+ public OMAttributeImpl(String localName, OMNamespace ns, String value) {
+ super(localName, ns, null);
+ setValue(value);
+ }
+
+ synchronized static String replaceQuoteWithEntity(String value) {
+ matcher.reset(value);
+ return matcher.replaceAll(QUOTE_ENTITY);
+ }
+
+ public void print(PrintStream s) throws OMException {
+ super.print(s);
+ s.print('=');
+ String v = value;
+ char quote = '"';
+ if (value.indexOf('"') != -1)
+ if (value.indexOf('\'') == -1)
+ quote = '\'';
+ else
+ v = replaceQuoteWithEntity(value);
+ s.print(quote);
+ s.print(v);
+ s.print(quote);
+ }
+
+ public void detach() throws OMException {
+ if (parent == null)
+ throw new OMException();
+ if (getPreviousSibling() == null)
+ parent.setFirstAttribute((OMAttributeImpl) nextSibling);
+ else
+ previousSibling.setNextSibling(nextSibling);
+ if (nextSibling != null)
+ nextSibling.setPreviousSibling(previousSibling);
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMDocumentImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMDocumentImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,56 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMDocument;
+import org.apache.axis.om.OMElement;
+
+/**
+ * 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 7, 2004
+ * Time: 10:52:17 AM
+ */
+public class OMDocumentImpl extends OMNodeImpl implements OMDocument {
+
+ private OMElementImpl root;
+ private OMXmlPullParserWrapper parserWrapper;
+
+ public OMDocumentImpl(OMXmlPullParserWrapper parserWrapper) {
+ this.parserWrapper = parserWrapper;
+ }
+
+ public OMElementImpl getRootElement() {
+ if (root == null) {
+ parserWrapper.next();
+ }
+ return root;
+ }
+
+ public void setRootElement(OMElementImpl root) {
+ this.root = root;
+ }
+
+ /**
+ * Get the root element of this document
+ *
+ * @return the root element
+ *
+ * This method should be changed as getRootElement
+ *
+ */
+ public OMElement getDocumentElement() {
+ return getRootElement();
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMElementImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMElementImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,235 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.*;
+
+import java.io.PrintStream;
+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 5, 2004
+ * Time: 1:16:10 PM
+ */
+public class OMElementImpl extends OMNamedNodeImpl implements OMElement {
+ private OMNodeImpl firstChild;
+ OMXmlPullParserWrapper builder;
+ OMAttributeImpl firstAttribute;
+ OMNamespaceImpl firstNamespace;
+
+ public OMElementImpl(OMElement parent) {
+ super(parent);
+ }
+
+ public OMElementImpl(String localName, OMNamespace ns) {
+ super(localName, ns, null);
+ done = true;
+ }
+
+ public OMElementImpl(String localName, OMNamespace ns, OMElement parent, OMXmlPullParserWrapper builder) {
+ super(localName, ns, parent);
+ this.builder = builder;
+
+ }
+
+ /**
+ * This will add child to the element. One can decide whether he append the child or he adds to the
+ * front of the children list
+ *
+ * @param child
+ */
+ public void addChild(OMNode child) {
+ addChild((OMNodeImpl) child);
+ }
+
+ private void addChild(OMNodeImpl child) {
+ if (firstChild == null && !done)
+ builder.next();
+ child.setPreviousSibling(null);
+ child.setNextSibling(firstChild);
+ if (firstChild != null)
+ firstChild.setPreviousSibling(child);
+ child.setParent(this);
+ firstChild = child;
+ }
+
+ /**
+ * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+ *
+ * @return
+ * @throws org.apache.axis.om.OMException
+ */
+ public OMNode getNextSibling() throws OMException {
+ while (!done)
+ builder.next();
+ return super.getNextSibling();
+ }
+
+ /**
+ * This returns a collection of this element.
+ * Children can be of types OMElement, OMText.
+ */
+ public Iterator getChildren() {
+ return null; //TODO implement this
+ }
+
+ /**
+ * THis will create a namespace in the current element scope
+ *
+ * @param uri
+ * @param prefix
+ * @return
+ */
+ public OMNamespace createNamespace(String uri, String prefix) {
+ OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
+ ns.setNextSibling(firstNamespace);
+ firstNamespace = ns;
+ return ns;
+ }
+
+ /**
+ * This will find a namespace with the given uri and prefix, in the scope of the docuemnt.
+ * This will start to find from the current element and goes up in the hiararchy until this finds one.
+ * If none is found, return null
+ *
+ * @param uri
+ * @param prefix
+ * @return
+ * @throws org.apache.axis.om.OMException
+ */
+ public OMNamespace resolveNamespace(String uri, String prefix) throws OMException {
+ OMNamespace ns = firstNamespace;
+ while (ns != null) {
+ if (ns.equals(uri, prefix))
+ return ns;
+ ns = (OMNamespace) ns.getNextSibling();
+ }
+ if (parent != null)
+ return parent.resolveNamespace(uri, prefix);
+ return null;
+ }
+
+ /**
+ * This will returns the first attribute of the element or null, if none is present
+ *
+ * @return
+ */
+ public OMAttribute getFirstAttribute() {
+ return firstAttribute;
+ }
+
+ /**
+ * This will return a List of OMAttributes
+ *
+ * @return
+ */
+ public Iterator getAttributes() {
+ return null; //TODO implement this
+ }
+
+ /**
+ * This will insert attribute to this element. Implementor can decide as to insert this
+ * in the front or at the end of set of attributes
+ *
+ * @param attr
+ */
+ public void insertAttribute(OMAttribute attr) {
+
+ OMAttributeImpl attrImpl = (OMAttributeImpl) attr;
+ attrImpl.setPreviousSibling(null);
+ attrImpl.setNextSibling(firstAttribute);
+ if (firstAttribute != null)
+ firstAttribute.setPreviousSibling(attrImpl);
+ attrImpl.setParent(this);
+ firstAttribute = attrImpl;
+ }
+
+ public void removeAttribute(OMAttribute attr) {
+ attr.detach();
+ }
+
+ /**
+ * This will force the parser to proceed, if parser has not yet finished with the XML input
+ */
+ public void buildNext() {
+ builder.next();
+ }
+
+ public OMNodeImpl getFirstChild() {
+ if (firstChild == null && !done)
+ buildNext();
+ return firstChild;
+ }
+
+
+ public void setFirstChild(OMNodeImpl firstChild) {
+ this.firstChild = firstChild;
+ }
+
+ public void print(PrintStream s) throws OMException {
+ s.print('<');
+ super.print(s);
+
+ OMNodeImpl node = firstAttribute;
+ while (node != null) {
+ s.print(" ");
+ node.print(s);
+ node = (OMNodeImpl) node.getNextSibling();
+ }
+
+ node = firstNamespace;
+ while (node != null) {
+ s.print(" ");
+ node.print(s);
+ node = (OMNodeImpl) node.getNextSibling();
+ }
+
+ node = getFirstChild();
+ if (node != null) {
+ s.print('>');
+ while (node != null) {
+ node.print(s);
+ node = (OMNodeImpl) node.getNextSibling();
+ }
+ s.print('<');
+ s.print('/');
+ super.print(s);
+ } else
+ s.print('/');
+ s.print('>');
+ }
+
+ /**
+ * This will remove this information item and its children, from the model completely
+ *
+ * @throws org.apache.axis.om.OMException
+ */
+ public void detach() throws OMException {
+ if (done)
+ super.detach();
+ else
+ builder.discard(this);
+ }
+
+ public void setFirstAttribute(OMAttributeImpl firstAttribute) {
+ this.firstAttribute = firstAttribute;
+ }
+
+
+ public boolean isComplete() {
+ return done;
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamedNodeImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamedNodeImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,71 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNamedNode;
+import org.apache.axis.om.OMNamespace;
+
+import java.io.PrintStream;
+
+/**
+ * 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 5, 2004
+ * Time: 1:17:37 PM
+ */
+public class OMNamedNodeImpl extends OMNodeImpl implements OMNamedNode {
+
+ OMNamespace ns;
+ String localName;
+
+
+ public OMNamedNodeImpl(String localName, OMNamespace ns, OMElement parent) {
+ super(parent);
+ this.localName = localName;
+ this.ns = ns;
+ }
+
+ public OMNamedNodeImpl(OMElement parent) {
+ super(parent);
+ }
+
+ public String getLocalName() {
+ return localName;
+ }
+
+ public void setLocalName(String localName) {
+ this.localName = localName;
+ }
+
+ public OMNamespace getNamespace() throws OMException {
+ return ns;
+ }
+
+ /**
+ * @param namespace
+ */
+ public void setNamespace(OMNamespace namespace) {
+ this.ns = namespace;
+ }
+
+ public void print(PrintStream ps) throws OMException {
+ if (ns != null && !ns.isDefaultNs()) {
+ ps.print(ns.getPrefix());
+ ps.print(':');
+ }
+ ps.print(localName);
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamespaceImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNamespaceImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,70 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMNode;
+
+import java.io.PrintStream;
+
+/**
+ * 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 6, 2004
+ * Time: 11:43:32 AM
+ */
+public class OMNamespaceImpl extends OMNodeImpl implements OMNamespace {
+ private String prefix;
+
+ protected OMNamespaceImpl(String uri, String prefix) {
+ value = uri;
+ this.prefix = prefix;
+ }
+
+
+ public boolean equals(OMNamespace ns) {
+ return ((prefix == null && ns.getPrefix() == null) || (prefix != null && prefix.equals(ns.getPrefix())))
+ && value.equals(ns.getValue());
+ }
+
+ public boolean equals(String uri, String prefix) {
+ return ((prefix == null && this.prefix == null) || (prefix != null && prefix.equals(this.prefix)))
+ && value.equals(uri);
+ }
+
+ public void print(PrintStream s) {
+ s.print("xmlns");
+ if (prefix != null) {
+ s.print(':');
+ s.print(prefix);
+ }
+ s.print('=');
+ s.print('"');
+ s.print(value);
+ s.print('"');
+ }
+
+ public boolean isDefaultNs() {
+ return prefix == null;
+ }
+
+ public String getPrefix() {
+ return prefix; //TODO implement this
+ }
+
+ public OMNode getNextSibling() throws OMException {
+ return nextSibling;
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNavigator.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNavigator.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2004 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.
+ *
+ */
+
+/*
+ * Created on Sep 25, 2004
+ *
+ */
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNode;
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class OMNavigator {
+ protected OMNode node;
+ private boolean visited;
+ private OMNode next;
+ private boolean backtracked;
+
+ public OMNavigator() {
+ }
+
+ public OMNavigator(OMNode node) {
+ init(node);
+ }
+
+ public void init(OMNode node) {
+ next = node;
+ backtracked = false;
+ }
+
+ public OMNode next() {
+ if (next == null)
+ return null;
+ node = next;
+ visited = backtracked;
+ backtracked = false;
+ if (next instanceof OMElement && !visited) {
+ OMElementImpl e = (OMElementImpl) next;
+ if (e.getFirstChild() != null)
+ next = e.getFirstChild();
+ else if (e.isComplete())
+ backtracked = true;
+ else
+ next = null;
+ return node;
+ }
+ OMNodeImpl n = (OMNodeImpl) next;
+ if (n.nextSibling != null)
+ next = n.nextSibling;
+ else if (n.parent != null && n.parent.isComplete()) {
+ next = n.parent;
+ backtracked = true;
+ } else
+ next = null;
+ return node;
+ }
+
+ public boolean visited() {
+ return visited;
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNodeImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMNodeImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,195 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.Printable;
+
+import java.io.PrintStream;
+
+/**
+ * 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 5, 2004
+ * Time: 12:54:08 PM
+ */
+public class OMNodeImpl implements OMNode, Printable {
+ protected OMElementImpl parent;
+ protected OMNodeImpl nextSibling;
+ protected OMNodeImpl previousSibling;
+ protected String value;
+ protected boolean done;
+
+ public OMNodeImpl() {
+ }
+
+ /**
+ * For a node to exist there must be a parent
+ *
+ * @param parent
+ */
+
+
+ public OMNodeImpl(OMElement parent) {
+ if (parent instanceof OMNodeImpl)
+ this.parent = (OMElementImpl) parent;
+ }
+
+ /**
+ * This method should return the immediate parent of the node.
+ * Parent is always an Element
+ *
+ * @return
+ * @throws org.apache.axis.om.OMException
+ */
+ public OMElement getParent() throws OMException {
+ return parent;
+ }
+
+ public void setParent(OMElement element) {
+ if (element instanceof OMNodeImpl)
+ this.parent = (OMElementImpl) element;
+ }
+
+ /**
+ * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+ *
+ * @return
+ * @throws org.apache.axis.om.OMException
+ */
+ public OMNode getNextSibling() throws OMException {
+ System.out.println("***********parent = " + parent);
+ System.out.println("++++++++++++nextSibling = " + nextSibling);
+ if (nextSibling == null && !parent.isComplete())
+ parent.buildNext();
+ return nextSibling;
+ }
+
+ public void setNextSibling(OMNode node) {
+ this.nextSibling = (OMNodeImpl) node;
+ }
+
+ /**
+ * This will return the literal value of the node.
+ * OMText --> the text
+ * OMElement --> name of the element as a QName in String format
+ * OMAttribute --> the value of the attribue
+ *
+ * @return
+ * @throws org.apache.axis.om.OMException
+ */
+ public String getValue() throws OMException {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * this will indicate whether parser has parsed this information item completely or not.
+ * If somethings info are not available in the item, one has to check this attribute to make sure that, this
+ * item has been parsed completely or not.
+ *
+ * @return
+ */
+ public boolean isComplete() {
+ return true;
+ }
+
+ public void setComplete(boolean state) {
+ this.done = state;
+ }
+
+ /**
+ * This will remove this information item and its children, from the model completely
+ *
+ * @throws org.apache.axis.om.OMException
+ */
+ public void detach() throws OMException {
+ if (parent == null)
+ throw new OMException();
+ OMNodeImpl nextSibling = (OMNodeImpl) getNextSibling();
+ if (previousSibling == null)
+ parent.setFirstChild(nextSibling);
+ else
+ previousSibling.setNextSibling(nextSibling);
+ if (nextSibling != null)
+ nextSibling.setPreviousSibling(previousSibling);
+
+ }
+
+ /**
+ * This will insert a sibling just after the current information item.
+ *
+ * @param sibling
+ * @throws org.apache.axis.om.OMException
+ */
+ public void insertSiblingAfter(OMNode sibling) throws OMException {
+ if (parent == null)
+ throw new OMException();
+ sibling.setParent(parent);
+
+ if (sibling instanceof OMNodeImpl) {
+ OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+ if (nextSibling == null)
+ getNextSibling();
+ siblingImpl.setPreviousSibling(this);
+ if (nextSibling != null)
+ nextSibling.setPreviousSibling(sibling);
+ sibling.setNextSibling(nextSibling);
+ nextSibling = siblingImpl;
+ }
+
+ }
+
+ /**
+ * This will insert a sibling just before the current information item
+ *
+ * @param sibling
+ * @throws org.apache.axis.om.OMException
+ */
+ public void insertSiblingBefore(OMNode sibling) throws OMException {
+ if (parent == null)
+ throw new OMException();
+ sibling.setParent(parent);
+
+ if (sibling instanceof OMNodeImpl) {
+ OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+ siblingImpl.setPreviousSibling(previousSibling);
+ siblingImpl.setNextSibling(this);
+ if (previousSibling == null)
+ parent.setFirstChild(siblingImpl);
+ else
+ previousSibling.setNextSibling(siblingImpl);
+ previousSibling = siblingImpl;
+ }
+ }
+
+ public OMNode getPreviousSibling() {
+ return previousSibling;
+ }
+
+ public void setPreviousSibling(OMNode previousSibling) {
+ this.previousSibling = (OMNodeImpl) previousSibling;
+ }
+
+ public void print(PrintStream ps) throws OMException {
+ throw new OMException();
+ }
+
+
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMTextImpl.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMTextImpl.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,69 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMText;
+
+import java.io.PrintStream;
+
+/**
+ * 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 6, 2004
+ * Time: 1:36:55 PM
+ */
+public class OMTextImpl extends OMNodeImpl implements OMText {
+
+ protected short textType;
+
+ public OMTextImpl(OMElement parent, String text) {
+ super(parent);
+ setValue(text);
+ done = true;
+ }
+
+ public OMTextImpl(String s) {
+ super();
+ setValue(s);
+ }
+
+ /**
+ * We use the OMText class to hold comments, text, characterData, CData, etc.,
+ * The codes are found in OMNode class
+ *
+ * @param type
+ */
+ public void setTextType(short type) {
+ this.textType = type;
+ }
+
+ public short getTextType() {
+ return textType; //TODO implement this
+ }
+
+ public OMNode getFirstChild() throws OMException {
+ throw new OMException();
+ }
+
+ public void setFirstChild(OMNode node) throws OMException {
+ throw new OMException();
+ }
+
+ public void print(PrintStream s) throws OMException {
+ s.print(value);
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMXmlPullParserWrapper.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/java/org/apache/axis/om/impl/OMXmlPullParserWrapper.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,333 @@
+package org.apache.axis.om.impl;
+
+import org.apache.axis.om.*;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ * 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 6, 2004
+ * Time: 11:42:44 AM
+ */
+public class OMXmlPullParserWrapper {
+ private XmlPullParser parser;
+ // private OMElementImpl root;
+ private OMDocumentImpl document;
+ private OMNodeImpl lastNode;
+ private boolean cache = true;
+ private boolean slip = false;
+ private boolean navigate = false;
+ private boolean done = false;
+ private OMNavigator navigator = new OMNavigator();
+
+ public OMXmlPullParserWrapper(XmlPullParser parser) {
+ this.parser = parser;
+ }
+
+// public OMElementImpl getDocument() throws OMException {
+// if (root == null)
+// next();
+// return root;
+// }
+ public OMDocumentImpl getDocument() throws OMException {
+ document = new OMDocumentImpl(this);
+ return document;
+ }
+
+ private OMNode createOMElement() throws OMException {
+ OMElementImpl node;
+ if (lastNode == null) {
+ node = new OMElementImpl(parser.getName(), null, null, this);
+ document.setRootElement(node);
+// root = new OMElementImpl(parser.getName(), null, null, this);
+// node = root;
+ } else if (lastNode.isComplete()) {
+ node = new OMElementImpl(parser.getName(), null, lastNode.getParent(), this);
+ lastNode.setNextSibling(node);
+ node.setPreviousSibling(lastNode);
+ } else {
+ System.out.println("lastNode = " + lastNode.getClass());
+ OMElementImpl e = (OMElementImpl) lastNode;
+ node = new OMElementImpl(parser.getName(), null, (OMElement) lastNode, this);
+ e.setFirstChild(node);
+ }
+
+ int i, j;
+ try {
+ j = parser.getNamespaceCount(parser.getDepth());
+ i = 0;
+ if (j > 1)
+ i = parser.getNamespaceCount(parser.getDepth() - 1);
+ while (i < j) {
+ node.createNamespace(parser.getNamespaceUri(i), parser.getNamespacePrefix(i));
+ i++;
+ }
+ } catch (XmlPullParserException e) {
+ throw new OMException(e);
+ }
+
+ node.setNamespace(node.resolveNamespace(parser.getNamespace(), parser.getPrefix()));
+
+ j = parser.getAttributeCount();
+ for (i = 0; i < j; i++) {
+ OMNamespace ns = null;
+ String uri = parser.getAttributeNamespace(i);
+ if (uri.hashCode() != 0)
+ ns = node.resolveNamespace(uri, parser.getAttributePrefix(i));
+ node.insertAttribute(new OMAttributeImpl(parser.getAttributeName(i), ns, parser.getAttributeValue(i), node));
+ }
+
+ return node;
+ }
+
+ private OMNode createOMText() throws OMException {
+ if (lastNode == null)
+ throw new OMException();
+ OMNodeImpl node;
+ if (lastNode.isComplete()) {
+ node = new OMTextImpl(lastNode.getParent(), parser.getText());
+ lastNode.setNextSibling(node);
+ node.setPreviousSibling(lastNode);
+ } else {
+ OMElementImpl e = (OMElementImpl) lastNode;
+ node = new OMTextImpl(e, parser.getText());
+ e.setFirstChild(node);
+ }
+ return node;
+ }
+
+ public void reset(OMNode node) throws OMException {
+ navigate = true;
+ lastNode = null;
+ navigator.init(node);
+ }
+
+ // TODO:
+ public int next() throws OMException {
+ try {
+ if (navigate) {
+ OMNodeImpl next = (OMNodeImpl) navigator.next();
+ if (next != null) {
+ lastNode = next;
+ if (lastNode instanceof OMText)
+ return XmlPullParser.TEXT;
+ else if (navigator.visited())
+ return XmlPullParser.END_TAG;
+ else
+ return XmlPullParser.START_TAG;
+ }
+ navigate = false;
+ if (done)
+ return XmlPullParser.END_DOCUMENT;
+ if (slip)
+ throw new OMException();
+ }
+
+ if (done)
+ throw new OMException();
+
+ int token = parser.nextToken();
+
+ if (!cache) {
+ slip = true;
+ return token;
+ }
+
+ switch (token) {
+ case XmlPullParser.START_TAG:
+ lastNode = (OMNodeImpl) createOMElement();
+ break;
+
+ case XmlPullParser.TEXT:
+ lastNode = (OMNodeImpl) createOMText();
+ break;
+
+ case XmlPullParser.END_TAG:
+ if (lastNode.isComplete()) {
+ OMElement parent = lastNode.getParent();
+ parent.setComplete(true);
+ lastNode = (OMNodeImpl) parent;
+ } else {
+ OMElement e = (OMElement) lastNode;
+ e.setComplete(true);
+ }
+ break;
+
+ case XmlPullParser.END_DOCUMENT:
+ done = true;
+ break;
+
+ default :
+ throw new OMException();
+ }
+ return token;
+ } catch (OMException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new OMException(e);
+ }
+ }
+
+ public void discard(OMElementImpl el) throws OMException {
+ if (el.isComplete() || !cache)
+ throw new OMException();
+ try {
+ cache = false;
+ do {
+ while (parser.next() != XmlPullParser.END_TAG) ;
+ // TODO:
+ } while (!parser.getName().equals(el.getLocalName()));
+ lastNode = (OMNodeImpl) el.getPreviousSibling();
+ if (lastNode != null)
+ lastNode.setNextSibling(null);
+ else {
+ OMElementImpl parent = (OMElementImpl) el.getParent();
+ if (parent == null)
+ throw new OMException();
+ parent.setFirstChild(null);
+ lastNode = parent;
+ }
+ slip = false;
+ cache = true;
+ } catch (OMException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+
+ public void setCache(boolean b) {
+ cache = b;
+ }
+
+ public String getName() throws OMException {
+ if (navigate) {
+ try {
+ OMElement e = (OMElement) lastNode;
+ return e.getLocalName();
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+ return parser.getName();
+ }
+
+ public String getText() throws OMException {
+ if (navigate) {
+ try {
+ return (String) lastNode.getValue();
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+ return parser.getText();
+ }
+
+ public String getNamespace() throws OMException {
+ if (navigate) {
+ if (lastNode instanceof OMElement) {
+ OMElement node = (OMElement) lastNode;
+ OMNamespace ns = node.getNamespace();
+ if (ns != null)
+ return ns.getValue();
+ // TODO: else
+ }
+ throw new OMException();
+ }
+ return parser.getNamespace();
+ }
+
+ public int getNamespaceCount(int arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ try {
+ return parser.getNamespaceCount(arg);
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+
+ public String getNamespacePrefix(int arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ try {
+ return parser.getNamespacePrefix(arg);
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+
+ public String getNamespaceUri(int arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ try {
+ return parser.getNamespaceUri(arg);
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+
+ public String getNamespace(String arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ try {
+ return parser.getNamespace(arg);
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+
+ public String getPrefix() throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ return parser.getPrefix();
+ }
+
+ public int getAttributeCount() throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ return parser.getAttributeCount();
+ }
+
+ public String getAttributeNamespace(int arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ return parser.getAttributeNamespace(arg);
+ }
+
+ public String getAttributeName(int arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ return parser.getAttributeNamespace(arg);
+ }
+
+ public String getAttributePrefix(int arg) throws OMException {
+ if (navigate)
+ // TODO:
+ throw new OMException();
+ return parser.getAttributeNamespace(arg);
+ }
+}
Added: webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/Tester.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/chinthaka/OMAPI_with_Impl/src/test/org/apache/axis/om/Tester.java Thu Oct 7 01:54:25 2004
@@ -0,0 +1,201 @@
+/*
+ * Created on Sep 26, 2004
+ * Copyright 2004 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.axis.om;
+
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserFactory;
+import org.apache.axis.om.impl.*;
+
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class Tester extends TestCase {
+ private static final String IN_FILE_NAME = "resources/soapmessage.xml";
+ private static final String OUT_FILE_NAME = "resources/tester-out.xml";
+
+ public void test1() throws Exception {
+ System.out.println("\n+++");
+ OMElementImpl root= getOMBuilder().getDocument().getRootElement();
+ System.out.println(root.isComplete());
+ root.print(System.out);
+ }
+
+ public void test2() throws Exception {
+ System.out.println("\n+++");
+ OMElementImpl root= getOMBuilder().getDocument().getRootElement();
+
+ System.out.println(root.isComplete());
+ root.getFirstChild().detach();
+
+ System.out.println("---");
+ navigate(root);
+
+ OMElement header= (OMElement)root.getFirstChild();
+ // we read the header completely but do not cache it
+ header.detach();
+
+ System.out.println("---");
+ navigate(root);
+
+ System.out.println("---");
+ root.print(System.out);
+ }
+
+ public void test3() throws Exception {
+ System.out.println("\n+++");
+ OMElementImpl root= getOMBuilder().getDocument().getRootElement();
+
+ OMNamespace soapenv= root.resolveNamespace("http://schemas.xmlsoap.org/soap/envelope/", "soapenv");
+ OMNamespace wsa= root.resolveNamespace("http://schemas.xmlsoap.org/ws/2004/03/addressing", "wsa");
+
+ OMElement relatesTo= new OMElementImpl("RelatesTo", wsa);
+ relatesTo.insertAttribute(new OMAttributeImpl("RelationshipType", null, "wsa:Reply", relatesTo));
+ relatesTo.insertAttribute(new OMAttributeImpl("mustUnderstand", soapenv, "0", relatesTo));
+ relatesTo.addChild(new OMTextImpl(relatesTo, "uuid:3821F4F0-D020-11D8-A10A-E4EE6425FCB0"));
+
+ System.out.println(root.isComplete());
+ root.addChild(relatesTo);
+
+ OMNavigator navigator= new OMNavigator(root);
+ OMNode node= navigator.next();
+ do {
+ if (node instanceof OMElement) {
+ OMElement el= (OMElement)node;
+ System.out.println("OMElement= " + el.getLocalName());
+ }
+ else
+ System.out.println("OMText= " + node.getValue());
+ node= navigator.next();
+ }
+ while (node != null);
+
+ root.print(System.out);
+ }
+
+ public void test4() throws Exception {
+ System.out.println("\n+++");
+ OMElementImpl root= new OMElementImpl("Envelope", null);
+ OMNamespace soapenv= root.createNamespace("http://schemas.xmlsoap.org/soap/envelope/", "soapenv");
+ root.setNamespace(soapenv);
+ OMElement header= new OMElementImpl("Header", soapenv);
+ root.addChild(header);
+ OMNamespace xsd= root.createNamespace("http://www.w3.org/2001/XMLSchema", "xsd");
+ OMNamespace xsi= root.createNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
+ OMNamespace wsa= root.createNamespace("http://schemas.xmlsoap.org/ws/2004/03/addressing", "wsa");
+
+ OMElement messageID= new OMElementImpl("MessageID", wsa);
+ messageID.addChild(new OMTextImpl("uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5"));
+ messageID.insertAttribute(new OMAttributeImpl("mustUnderstand", soapenv, "0"));
+
+ OMElement from= new OMElementImpl("From", wsa);
+ OMElement address= new OMElementImpl("Address", null);
+ address.createNamespace("http://schemas.xmlsoap.org/ws/2004/03/addressing", null);
+ address.setNamespace(
+ address.resolveNamespace("http://schemas.xmlsoap.org/ws/2004/03/addressing", null));
+ address.addChild(new OMTextImpl("http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous"));
+ from.addChild(address);
+ // FIXME: cannot reuse the attribute object created earlier. linked list--
+ from.insertAttribute(new OMAttributeImpl("mustUnderstand", soapenv, "0"));
+
+ OMElement to= new OMElementImpl("To", wsa);
+ to.addChild(new OMTextImpl("http://localhost:8081/axis/services/BankPort"));
+ to.insertAttribute(new OMAttributeImpl("mustUnderstand", soapenv, "0"));
+
+ OMElement relatesTo= new OMElementImpl("RelatesTo", wsa);
+ relatesTo.insertAttribute(new OMAttributeImpl("RelationshipType", null, "wsa:Reply"));
+ relatesTo.insertAttribute(new OMAttributeImpl("mustUnderstand", soapenv, "0"));
+ relatesTo.addChild(new OMTextImpl("uuid:3821F4F0-D020-11D8-A10A-E4EE6425FCB0"));
+
+ header.addChild(from);
+ from.insertSiblingAfter(relatesTo);
+ from.insertSiblingBefore(to);
+ to.insertSiblingBefore(messageID);
+
+ root.print(new PrintStream(new FileOutputStream(OUT_FILE_NAME)));
+ }
+
+ public void test5() throws Exception {
+ System.out.println("\n+++");
+ OMXmlPullParserWrapper omBuilder= getOMBuilder();
+ OMElementImpl root= omBuilder.getDocument().getRootElement();
+
+ System.out.println("root.isComplete() = " + root.isComplete());
+ root.getFirstChild().detach();
+ OMElement header= (OMElement)root.getFirstChild();
+ while (!header.isComplete())
+ omBuilder.next();
+ navigate(root);
+ System.out.println("---");
+ omBuilder.reset(header);
+ int event;
+ do {
+ event= omBuilder.next();
+ System.out.print(getFieldName(event)+"= ");
+ if (event == XmlPullParser.TEXT)
+ System.out.println(omBuilder.getText());
+ else {
+ System.out.println("{"+omBuilder.getNamespace()+"}"+omBuilder.getName());
+ }
+ }while (event != XmlPullParser.END_DOCUMENT);
+ System.out.println("---");
+ root.print(System.out);
+ }
+
+ private void navigate(OMNode node) throws Exception {
+ OMNavigator navigator= new OMNavigator(node);
+ node= navigator.next();
+ do {
+ if (node instanceof OMElement) {
+ OMElement el= (OMElement)node;
+ System.out.print("OMElement= " + el.getLocalName());
+ }
+ else
+ System.out.print("OMText= " + node.getValue());
+ System.out.println(" isComplete= " + node.isComplete());
+ node= navigator.next();
+ }
+ while (node != null);
+ }
+
+ private OMXmlPullParserWrapper getOMBuilder() throws Exception {
+ XmlPullParser parser= XmlPullParserFactory.newInstance().newPullParser();
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
+ parser.setInput(new FileReader(IN_FILE_NAME));
+ return new OMXmlPullParserWrapper(parser);
+ }
+
+ private static Field[] flds= XmlPullParser.class.getDeclaredFields();
+
+ public static String getFieldName(int field) throws Exception {
+ for (int i= 1; i < flds.length + 1; i++) {
+ if (flds[i].getInt(null) == field)
+ return flds[i].getName();
+ }
+ return null;
+ }
+}