You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2005/02/01 13:28:32 UTC
svn commit: r149390 - in
webservices/axis/trunk/java/dev/scratch/prototype2/src:
java/org/apache/axis/impl/llom/ java/org/apache/axis/impl/llom/serialize/
java/org/apache/axis/om/ test/org/apache/axis/om/impl/seriliazer/
Author: ajith
Date: Tue Feb 1 04:28:28 2005
New Revision: 149390
URL: http://svn.apache.org/viewcvs?view=rev&rev=149390
Log:
Changed the serialiation mechanism so that the namespace serialization is taken care of the XMLStreamWriter
Modified:
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMElementImpl.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMNodeImpl.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMTextImpl.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMNode.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMSerializer.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/ElementSerializerTest.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/OMSerailizerTest.java
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMElementImpl.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMElementImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMElementImpl.java Tue Feb 1 04:28:28 2005
@@ -44,46 +44,42 @@
* <p/>
*/
public class OMElementImpl extends OMNamedNodeImpl implements OMElement, OMConstants {
- private OMNode firstChild;
+ private OMNode firstChild;
protected OMXMLParserWrapper builder;
private HashMap namespaces;
private HashMap attributes;
- private Stack namespaceStack;
- public OMElementImpl(){
+ public OMElementImpl(){
namespaces = new HashMap(5);
this.attributes = new HashMap();
}
+ public void free(){
+ this.namespaces.clear();
+ this.attributes.clear();
+ firstChild.free();
+ OMFactory.newInstance().free(this);
+ nextSibling.free();
+ }
- public void free(){
- this.namespaces.clear();
- this.attributes.clear();
- firstChild.free();
- OMFactory.newInstance().free(this);
- nextSibling.free();
- }
-
-
- public void init(String localName, OMNamespace ns, OMElement parent, OMXMLParserWrapper builder) {
+ public void init(String localName, OMNamespace ns, OMElement parent, OMXMLParserWrapper builder) {
super.init(localName, null, parent);
if (ns != null) {
setNamespace(handleNamespace(ns));
}
this.builder = builder;
- namespaceStack = null;
+
firstChild = null;
}
-
public void init(String localName, OMNamespace ns) {
super.init(localName, null, null);
this.done = true;
if (ns != null) {
setNamespace(handleNamespace(ns));
}
- done = true;
+
}
private OMNamespace handleNamespace(OMNamespace ns) {
@@ -227,7 +223,7 @@
*/
public OMNamespace findDeclaredNamespace(String uri, String prefix) throws OMException {
if (prefix == null) {
- Iterator namespaceListIterator = namespaces.values().iterator();
+ Iterator namespaceListIterator = namespaces.values().iterator();
while (namespaceListIterator.hasNext()) {
OMNamespace omNamespace = (OMNamespace) namespaceListIterator.next();
if (omNamespace.getName().equals(uri)) {
@@ -279,7 +275,7 @@
}
public void removeAttribute(OMAttribute attr) {
- attributes.remove(attr.getQName());
+ attributes.remove(attr.getQName());
}
public OMAttribute insertAttribute(String attributeName, String value, OMNamespace ns) {
@@ -311,7 +307,7 @@
}
public OMNode getFirstChild() {
- if (firstChild == null && !done)
+ while (firstChild == null && !done)
buildNext();
return firstChild;
}
@@ -371,17 +367,9 @@
}
- public void serialize(XMLStreamWriter writer, boolean cache, Stack namespacePrefixStack) throws XMLStreamException {
+ public void serialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
boolean firstElement = false;
- if (namespacePrefixStack == null) {
- this.namespaceStack = new Stack();
- firstElement = true;
- } else {
- this.namespaceStack = namespacePrefixStack;
- }
-
- int namespaceCount = 0;
short builderType = PULL_TYPE_BUILDER; //default is pull type
if (builder != null)
@@ -395,7 +383,6 @@
if (!cache) {
if (firstChild == null && nextSibling == null && !isComplete() && builderType == PULL_TYPE_BUILDER) {
StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
- streamingOMSerializer.setNamespacePrefixStack(namespaceStack);
streamingOMSerializer.serialize(this.getPullParser(!cache), writer);
return;
}
@@ -408,7 +395,7 @@
if (nextSibling != null) {
//serilize next sibling
- nextSibling.serialize(writer, cache, namespaceStack);
+ nextSibling.serialize(writer, cache);
} else {
if (parent == null) {
return;
@@ -417,23 +404,23 @@
} else {
//do the special serialization
//Only the push serializer is left now
- builder.setCache(cache);
+ builder.setCache(cache);
builder.next();
}
}
} else if (firstChild != null) {
- namespaceCount = serializeStartpart(writer);
- firstChild.serialize(writer, cache, namespaceStack);
- serializeEndpart(writer, namespaceCount);
+ serializeStartpart(writer);
+ firstChild.serialize(writer, cache);
+ serializeEndpart(writer);
} else {
//do the special serilization
//Only the push serializer is left now
builder.setCache(cache);
- namespaceCount = serializeStartpart(writer);
+ serializeStartpart(writer);
builder.next();
- serializeEndpart(writer, namespaceCount);
+ serializeEndpart(writer);
}
@@ -442,8 +429,9 @@
serializeNormal(writer, cache);
//serialize the siblings if this is not the first element
if (!firstElement){
- if (this.getNextSibling() != null) {
- this.getNextSibling().serialize(writer, cache, namespaceStack);
+ OMNode nextSibling = this.getNextSibling();
+ if (nextSibling != null) {
+ nextSibling.serialize(writer, cache);
}
}
}
@@ -451,56 +439,54 @@
}
- private int serializeStartpart(XMLStreamWriter writer) throws XMLStreamException {
- int nsPushCount = 0;
- String prefix = null;
+ private void serializeStartpart(XMLStreamWriter writer) throws XMLStreamException {
+
String nameSpaceName = null;
if (ns != null) {
- prefix = ns.getPrefix();
nameSpaceName = ns.getName();
- if (prefix != null && nameSpaceName != null) {
- writer.writeStartElement(prefix, this.getLocalName(), nameSpaceName);
- if (serializeNamespace(ns, writer)) nsPushCount++;
+ if (nameSpaceName != null) {
+ writer.writeStartElement( nameSpaceName, this.getLocalName());
+ serializeNamespace(ns, writer);
} else {
- writer.writeStartElement(nameSpaceName, this.getLocalName());
+ throw new OMException("Non namespace qualified elements are not allowed");
}
+
+ }else{
+ throw new OMException("Non namespace qualified elements are not allowed");
}
+
//add the elements attributes
if (attributes != null) {
- Iterator attributesList = attributes.values().iterator();
+ Iterator attributesList = attributes.values().iterator();
while(attributesList.hasNext()) {
serializeAttribute((OMAttribute) attributesList.next(), writer);
}
}
+
//add the namespaces
Iterator namespaces = this.getAllDeclaredNamespaces();
while (namespaces.hasNext()) {
- if (serializeNamespace((OMNamespace) namespaces.next(), writer)) nsPushCount++;
+ serializeNamespace((OMNamespace) namespaces.next(), writer) ;
}
- return nsPushCount;
- }
- private void serializeEndpart(XMLStreamWriter writer, int namespaceCount) throws XMLStreamException {
-
- for (int i = 0; i < namespaceCount; i++) {
- namespaceStack.pop();
- }
+ }
+ private void serializeEndpart(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEndElement();
}
private void serializeNormal(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
+ serializeStartpart(writer);
- int namespaceCount = serializeStartpart(writer);
-
- if (getFirstChild() != null) {
- getFirstChild().serialize(writer, cache, namespaceStack);
+ OMNode firstChild = getFirstChild();
+ if (firstChild != null) {
+ firstChild.serialize(writer, cache);
}
- serializeEndpart(writer, namespaceCount);
+ serializeEndpart(writer);
}
@@ -522,24 +508,23 @@
}
}
- protected boolean serializeNamespace(OMNamespace namespace, XMLStreamWriter writer) throws XMLStreamException {
- boolean nsWritten = false;
+ protected void serializeNamespace(OMNamespace namespace, XMLStreamWriter writer) throws XMLStreamException {
+
if (namespace != null) {
- String prefix = namespace.getPrefix();
- if (!namespaceStack.contains(prefix)) {
- writer.writeNamespace(prefix, namespace.getName());
- namespaceStack.push(prefix);
- nsWritten = true;
+ String uri = namespace.getName();
+ String prefix = writer.getPrefix(uri);
+ String ns_prefix = namespace.getPrefix();
+ if (prefix==null) {
+ writer.writeNamespace(ns_prefix, namespace.getName());
+ writer.setPrefix(ns_prefix,uri);
}
}
-
- return nsWritten;
}
- protected void finalize() throws Throwable {
- CollectionPool.returnHashMap(attributes);
- CollectionPool.returnHashMap(namespaces);
- super.finalize();
- }
+ protected void finalize() throws Throwable {
+ CollectionPool.returnHashMap(attributes);
+ CollectionPool.returnHashMap(namespaces);
+ super.finalize();
+ }
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMNodeImpl.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMNodeImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMNodeImpl.java Tue Feb 1 04:28:28 2005
@@ -201,16 +201,14 @@
this.previousSibling = (OMNodeImpl) previousSibling;
}
- public void serialize(XMLStreamWriter writer, boolean cache, Stack namespacePrefixStack) throws XMLStreamException {
+ public void serialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
//Do nothing. Relevant children will put relevant things here
}
- public void serialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
- serialize(writer,cache,null);
- }
public void free(){
OMFactory.newInstance().free(this);
nextSibling.free();
}
+
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMTextImpl.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMTextImpl.java Tue Feb 1 04:28:28 2005
@@ -75,14 +75,11 @@
/**
* @param writer
* @param cache
- * @param namespacePrefixStack
* @throws XMLStreamException
*/
- public void serialize(XMLStreamWriter writer, boolean cache, Stack namespacePrefixStack) throws XMLStreamException {
- boolean isFirst = false;
- if (namespacePrefixStack == null) {
- isFirst = true;
- }
+ public void serialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
+
+
if (textType == TEXT_NODE)
writer.writeCharacters(this.value);
else if (textType == COMMENT_NODE)
@@ -90,14 +87,11 @@
else if (textType == CDATA_SECTION_NODE) {
writer.writeCData(this.value);
}
- //In this case we have to advance the parser (even when not cached) upto the
- //next *element*. You cannot ask for a pull parser from the text node!!!
- //by advancing the parser
- if (!isFirst) {
- OMNode nextSibling = this.getNextSibling();
- if (nextSibling != null) {
- nextSibling.serialize(writer, cache, namespacePrefixStack);
- }
+
+ OMNode nextSibling = this.getNextSibling();
+ if (nextSibling != null) {
+ nextSibling.serialize(writer, cache);
}
}
}
+
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java Tue Feb 1 04:28:28 2005
@@ -1,12 +1,13 @@
package org.apache.axis.impl.llom.serialize;
import org.apache.axis.om.OMSerializer;
+import org.apache.axis.om.OMException;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
-import java.util.Stack;
+//import java.util.Stack;
/**
@@ -26,17 +27,17 @@
*/
public class StreamingOMSerializer implements XMLStreamConstants, OMSerializer {
- private Stack namespacePrefixStack = new Stack();
- private Stack namespaceCountStack = new Stack();
+// private Stack namespacePrefixStack = new Stack();
+// private Stack namespaceCountStack = new Stack();
- public Stack getNamespacePrefixStack() {
- return namespacePrefixStack;
- }
-
- public void setNamespacePrefixStack(Stack namespacePrefixStack) {
- if (namespacePrefixStack != null)
- this.namespacePrefixStack = namespacePrefixStack;
- }
+// public Stack getNamespacePrefixStack() {
+// return namespacePrefixStack;
+// }
+//
+// public void setNamespacePrefixStack(Stack namespacePrefixStack) {
+// if (namespacePrefixStack != null)
+// this.namespacePrefixStack = namespacePrefixStack;
+// }
public void serialize(Object obj, XMLStreamWriter writer) throws XMLStreamException {
if (!(obj instanceof XMLStreamReader)) {
@@ -78,17 +79,14 @@
*/
protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- int nsPushCount = 0;
-
String prefix = reader.getPrefix();
String nameSpaceName = reader.getNamespaceURI();
- if (prefix != null) {
- writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
- if (serializeNamespace(prefix, nameSpaceName, writer)) nsPushCount++;
+ if (nameSpaceName != null) {
+ writer.writeStartElement(nameSpaceName ,reader.getLocalName() );
+ serializeNamespace(prefix, nameSpaceName, writer);
} else {
- writer.writeStartElement(nameSpaceName, reader.getLocalName());
- //add the own namespace
+ throw new OMException("Non namespace qualified elements are not allowed");
}
//add attributes
@@ -96,20 +94,20 @@
//add the namespaces
int count = reader.getNamespaceCount();
for (int i = 0; i < count; i++) {
- if (serializeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i), writer)) nsPushCount++;
+ serializeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i), writer);
}
- namespaceCountStack.push(new Integer(nsPushCount));
+ //namespaceCountStack.push(new Integer(nsPushCount));
}
protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
- if (!namespaceCountStack.isEmpty()) {
- Integer removeCount = (Integer) namespaceCountStack.pop();
- int count = removeCount.intValue();
- for (int i = 0; i < count; i++)
- namespacePrefixStack.pop();
- }
+// if (!namespaceCountStack.isEmpty()) {
+// Integer removeCount = (Integer) namespaceCountStack.pop();
+// int count = removeCount.intValue();
+// for (int i = 0; i < count; i++)
+// namespacePrefixStack.pop();
+// }
writer.writeEndElement();
}
@@ -155,14 +153,13 @@
}
}
- private boolean serializeNamespace(String prefix, String URI, XMLStreamWriter writer) throws XMLStreamException {
- boolean nsWritten = false;
- if (!namespacePrefixStack.contains(prefix)) {
- writer.writeNamespace(prefix, URI);
- namespacePrefixStack.push(prefix);
- nsWritten = true;
- }
- return nsWritten;
+ private void serializeNamespace(String prefix, String URI, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix1 = writer.getPrefix(URI);
+ if (prefix1==null) {
+ writer.writeNamespace(prefix, URI);
+ writer.setPrefix(prefix,URI);
+ }
+
}
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMNode.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMNode.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMNode.java Tue Feb 1 04:28:28 2005
@@ -142,14 +142,7 @@
*/
public void setPreviousSibling(OMNode previousSibling);
- /**
- * Writes the necessary serialization to a XMLStreamWriter object
- * @param writer
- * @param cache
- * @param namespacePrefixStack
- */
- public void serialize(XMLStreamWriter writer, boolean cache, Stack namespacePrefixStack) throws XMLStreamException ;
-
+
/**
*
* @param writer
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMSerializer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMSerializer.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMSerializer.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/om/OMSerializer.java Tue Feb 1 04:28:28 2005
@@ -21,7 +21,7 @@
*/
public interface OMSerializer {
void serialize(Object obj,XMLStreamWriter writer) throws XMLStreamException ;
- Stack getNamespacePrefixStack();
- void setNamespacePrefixStack(Stack namespacePrefixStack);
+// Stack getNamespacePrefixStack();
+// void setNamespacePrefixStack(Stack namespacePrefixStack);
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/ElementSerializerTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/ElementSerializerTest.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/ElementSerializerTest.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/ElementSerializerTest.java Tue Feb 1 04:28:28 2005
@@ -50,7 +50,7 @@
public void testElementSerilization() throws Exception{
OMElement elt = builder.getDocumentElement();
- elt.serialize(writer,true, null);
+ elt.serialize(writer,true);
}
@@ -124,6 +124,7 @@
}
protected void tearDown() throws Exception {
+ writer.flush();
tempFile.delete();
}
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/OMSerailizerTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/OMSerailizerTest.java?view=diff&r1=149389&r2=149390
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/OMSerailizerTest.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/seriliazer/OMSerailizerTest.java Tue Feb 1 04:28:28 2005
@@ -56,7 +56,7 @@
public void testRawSerializer() throws Exception {
StreamingOMSerializer serializer = new StreamingOMSerializer();
- serializer.setNamespacePrefixStack(new Stack());
+ //serializer.setNamespacePrefixStack(new Stack());
serializer.serialize(reader,writer);
}
@@ -89,6 +89,7 @@
protected void tearDown() throws Exception {
+ writer.flush();
tempFile.delete();
}
}