Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 22549 invoked from network); 3 May 2005 10:22:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 May 2005 10:22:37 -0000 Received: (qmail 80048 invoked by uid 500); 3 May 2005 10:23:25 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 79862 invoked by uid 500); 3 May 2005 10:23:24 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 79800 invoked by uid 99); 3 May 2005 10:23:24 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 03 May 2005 03:23:21 -0700 Received: (qmail 21238 invoked by uid 65534); 3 May 2005 10:21:37 -0000 Message-ID: <20050503102137.21237.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r167896 - in /webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llom: OMElementImpl.java OMSerializerUtil.java util/EmptyIterator.java Date: Tue, 03 May 2005 10:21:36 -0000 To: axis-cvs@ws.apache.org From: ajith@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: ajith Date: Tue May 3 03:21:36 2005 New Revision: 167896 URL: http://svn.apache.org/viewcvs?rev=3D167896&view=3Drev Log: Changing the OM Serializer implementation. Now the code is cleaner and prob= ably slightly faster as well Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/OMSerializerUtil.java webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/util/EmptyIterator.java Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/OMElementImpl.java Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/im= pl/llom/OMElementImpl.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/= src/org/apache/axis/om/impl/llom/OMElementImpl.java?rev=3D167896&r1=3D16789= 5&r2=3D167896&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/OMElementImpl.java (original) +++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/OMElementImpl.java Tue May 3 03:21:36 2005 @@ -20,6 +20,7 @@ import org.apache.axis.om.impl.llom.serialize.StreamingOMSerializer; import org.apache.axis.om.impl.llom.traverse.OMChildrenIterator; import org.apache.axis.om.impl.llom.traverse.OMChildrenQNameIterator; +import org.apache.axis.om.impl.llom.util.EmptyIterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; =20 @@ -52,12 +53,12 @@ /** * Field namespaces */ - private HashMap namespaces =3D null; + protected HashMap namespaces =3D null; =20 /** * Field attributes */ - private HashMap attributes =3D null; + protected HashMap attributes =3D null; =20 /** * Field log @@ -67,7 +68,7 @@ /** * Field noPrefixNamespaceCounter */ - private int noPrefixNamespaceCounter =3D 0; + protected int noPrefixNamespaceCounter =3D 0; =20 /** * Constructor OMElementImpl @@ -241,7 +242,7 @@ =20 =20 child.setParent(this); - =20 + child.setPreviousSibling(null); child.setNextSibling(firstChild); if (firstChild !=3D null) { @@ -390,26 +391,13 @@ */ public Iterator getAttributes() { if (attributes =3D=3D null) { - return new Iterator(){ - - public void remove() { - throw new UnsupportedOperationException(); - - } - - public boolean hasNext() { - return false; //To change body of implemented methods= use File | Settings | File Templates. - } - - public Object next() { - throw new UnsupportedOperationException(); - } - }; + return new EmptyIterator(); } return attributes.values().iterator(); } =20 public Iterator getAttributes(QName qname) { + //would there be multiple attributes with the same QName return null; //ToDO } =20 @@ -448,7 +436,7 @@ * @return */ public OMAttribute addAttribute(String attributeName, String value, - OMNamespace ns) { + OMNamespace ns) { OMNamespace namespace =3D null; if (ns !=3D null) { namespace =3D findNamespace(ns.getName(), ns.getPrefix()); @@ -579,7 +567,7 @@ * @param text */ public void setText(String text) { - =20 + OMNode child =3D this.getFirstChild(); while(child !=3D null){ if(child.getType() =3D=3D OMNode.TEXT_NODE){ @@ -622,9 +610,13 @@ public void serializeWithCache(XMLStreamWriter writer) throws XMLStre= amException { serialize(writer,true); } + + //////////////////////////////////////////////////////////////////////= ///////////////////////// + //////////////////////////////////////////////////////////////////////= //////////////////////// + private void serialize(XMLStreamWriter writer,boolean cache)throws XML= StreamException { =20 - boolean firstElement =3D false; + // select the builder short builderType =3D PULL_TYPE_BUILDER; // default is pull typ= e if (builder !=3D null) { builderType =3D this.builder.getBuilderType(); @@ -633,74 +625,51 @@ && (builder.getRegisteredContentHandler() =3D=3D null)) { builder.registerExternalContentHandler( new StreamWriterToContentHandlerConverter(writer)); - - // for now only SAX } =20 - // Special case for the pull type building with cache off - // The getXMLStreamReader method returns the current elements itse= lf. - if (!cache) { - if ((firstChild =3D=3D null) && (nextSibling =3D=3D null) && != isComplete() - && (builderType =3D=3D PULL_TYPE_BUILDER)) { - StreamingOMSerializer streamingOMSerializer =3D - new StreamingOMSerializer(); - streamingOMSerializer.serialize(this.getXMLStreamReader(!c= ache), - writer); - return; - } - } - if (!cache) { - if (isComplete()) { =20 - // serializeWithCache own normally - serializeNormal(writer, cache); - if (nextSibling !=3D null) { - - // serilize next sibling - nextSibling.serialize(writer); - } else { - if (parent =3D=3D null) { - return; - } else if (parent.isComplete()) { - return; - } else { - - // do the special serialization - // Only the push serializer is left now - builder.setCache(cache); - builder.next(); - } - } - } else if (firstChild !=3D null) { - serializeStartpart(writer); - log.info("Serializing the Element from " + localName - + " the generated OM tree"); + if (!cache) { + //No caching + if (this.firstChild!=3Dnull){ + OMSerializerUtil.serializeStartpart(this,writer); firstChild.serialize(writer); - serializeEndpart(writer); - } else { - - // do the special serilization - // Only the push serializer is left now - builder.setCache(cache); - serializeStartpart(writer); - builder.next(); - serializeEndpart(writer); + OMSerializerUtil.serializeEndpart(writer); + }else if (!this.done){ + if (builderType=3D=3DPULL_TYPE_BUILDER){ + OMSerializerUtil.serializeByPullStream(this,writer); + }else{ + OMSerializerUtil.serializeStartpart(this,writer); + builder.setCache(cache); + builder.next(); + OMSerializerUtil.serializeEndpart(writer); + } + }else{ + OMSerializerUtil.serializeNormal(this,writer, cache); } - } else { =20 - // serializeWithCache own normally - serializeNormal(writer, cache); - - // serializeWithCache the siblings if this is not the first el= ement - if (!firstElement) { - OMNode nextSibling =3D this.getNextSibling(); - if (nextSibling !=3D null) { - nextSibling.serializeWithCache(writer); + //serilize siblings + if (this.nextSibling!=3Dnull){ + nextSibling.serialize(writer); + }else if (this.parent!=3Dnull){ + if (!this.parent.done){ + builder.setCache(cache); + builder.next(); } } + }else{ + //Cached + OMSerializerUtil.serializeNormal(this,writer, cache); + // serialize the siblings + OMNode nextSibling =3D this.getNextSibling(); + if (nextSibling !=3D null) { + nextSibling.serializeWithCache(writer); + } } } =20 + //////////////////////////////////////////////////////////////////////= ////////////////////////// + //////////////////////////////////////////////////////////////////////= ////////////////////////// + /** * This was requested during the second Axis2 summit. When one call th= is method, this will * serialise without building the object structure in the memory. Misu= se of this method will @@ -715,149 +684,6 @@ =20 =20 =20 - /** - * Method serializeStartpart - * - * @param writer - * @throws XMLStreamException - */ - private void serializeStartpart(XMLStreamWriter writer) - throws XMLStreamException { - String nameSpaceName =3D null; - String writer_prefix =3D null; - String prefix =3D null; - if (ns !=3D null) { - nameSpaceName =3D ns.getName(); - writer_prefix =3D writer.getPrefix(nameSpaceName); - prefix =3D ns.getPrefix(); - if (nameSpaceName !=3D null) { - if (writer_prefix !=3D null) { - writer.writeStartElement(nameSpaceName, - this.getLocalName()); - } else { - if (prefix !=3D null) { - writer.writeStartElement(prefix, this.getLocalName= (), - nameSpaceName); - writer.writeNamespace(prefix, nameSpaceName); - writer.setPrefix(prefix, nameSpaceName); - } else { - writer.writeStartElement(nameSpaceName, - this.getLocalName()); - writer.writeDefaultNamespace(nameSpaceName); - writer.setDefaultNamespace(nameSpaceName); - } - } - } else { - writer.writeStartElement(this.getLocalName()); -// throw new OMException( -// "Non namespace qualified elements are not allowe= d"); - } - } else { - writer.writeStartElement(this.getLocalName()); -// throw new OMException( -// "Non namespace qualified elements are not allowed"); - } - - // add the elements attributes - if (attributes !=3D null) { - Iterator attributesList =3D attributes.values().iterator(); - while (attributesList.hasNext()) { - serializeAttribute((OMAttribute) attributesList.next(), wr= iter); - } - } - - // add the namespaces - Iterator namespaces =3D this.getAllDeclaredNamespaces(); - if (namespaces !=3D null) { - while (namespaces.hasNext()) { - serializeNamespace((OMNamespace) namespaces.next(), writer= ); - } - } - } - - /** - * Method serializeEndpart - * - * @param writer - * @throws XMLStreamException - */ - private void serializeEndpart(XMLStreamWriter writer) - throws XMLStreamException { - writer.writeEndElement(); - } - - /** - * Method serializeNormal - * - * @param writer - * @param cache - * @throws XMLStreamException - */ - private void serializeNormal(XMLStreamWriter writer, boolean cache) - throws XMLStreamException { - serializeStartpart(writer); - OMNode firstChild =3D getFirstChild();//todo - if (firstChild !=3D null) { - if (cache){ - firstChild.serializeWithCache(writer); - }else{ - firstChild.serialize(writer); - } - } - serializeEndpart(writer); - } - - /** - * Method serializeAttribute - * - * @param attr - * @param writer - * @throws XMLStreamException - */ - protected void serializeAttribute(OMAttribute attr, XMLStreamWriter wr= iter) - throws XMLStreamException { - - // first check whether the attribute is associated with a namespac= e - OMNamespace ns =3D attr.getNamespace(); - String prefix =3D null; - String namespaceName =3D null; - if (ns !=3D null) { - - // add the prefix if it's availble - prefix =3D ns.getPrefix(); - namespaceName =3D ns.getName(); - if (prefix !=3D null) { - writer.writeAttribute(prefix, namespaceName, - attr.getLocalName(), attr.getValue()); - } else { - writer.writeAttribute(namespaceName, attr.getLocalName(), - attr.getValue()); - } - } else { - writer.writeAttribute(attr.getLocalName(), attr.getValue()); - } - } - - /** - * Method serializeNamespace - * - * @param namespace - * @param writer - * @throws XMLStreamException - */ - protected void serializeNamespace( - OMNamespace namespace, XMLStreamWriter writer) - throws XMLStreamException { - if (namespace !=3D null) { - String uri =3D namespace.getName(); - String prefix =3D writer.getPrefix(uri); - String ns_prefix =3D namespace.getPrefix(); - if (prefix =3D=3D null) { - writer.writeNamespace(ns_prefix, namespace.getName()); - writer.setPrefix(ns_prefix, uri); - } - } - } =20 /** * Method getNextNamespacePrefix Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/= llom/OMSerializerUtil.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/= src/org/apache/axis/om/impl/llom/OMSerializerUtil.java?rev=3D167896&view=3D= auto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/OMSerializerUtil.java (added) +++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/OMSerializerUtil.java Tue May 3 03:21:36 2005 @@ -0,0 +1,188 @@ +package org.apache.axis.om.impl.llom; + +import org.apache.axis.om.OMAttribute; +import org.apache.axis.om.OMNamespace; +import org.apache.axis.om.OMElement; +import org.apache.axis.om.OMNode; +import org.apache.axis.om.impl.llom.serialize.StreamingOMSerializer; + +import javax.xml.stream.XMLStreamWriter; +import javax.xml.stream.XMLStreamException; +import java.util.Iterator; + +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= . + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=20 + */ +class OMSerializerUtil { + + /** + * Method serializeEndpart + * + * @param writer + * @throws javax.xml.stream.XMLStreamException + */ + static void serializeEndpart(XMLStreamWriter writer) + throws XMLStreamException { + writer.writeEndElement(); + } + + /** + * Method serializeAttribute + * + * @param attr + * @param writer + * @throws XMLStreamException + */ + static void serializeAttribute(OMAttribute attr, XMLStreamWriter write= r) + throws XMLStreamException { + + // first check whether the attribute is associated with a namespac= e + OMNamespace ns =3D attr.getNamespace(); + String prefix =3D null; + String namespaceName =3D null; + if (ns !=3D null) { + + // add the prefix if it's availble + prefix =3D ns.getPrefix(); + namespaceName =3D ns.getName(); + if (prefix !=3D null) { + writer.writeAttribute(prefix, namespaceName, + attr.getLocalName(), attr.getValue()); + } else { + writer.writeAttribute(namespaceName, attr.getLocalName(), + attr.getValue()); + } + } else { + writer.writeAttribute(attr.getLocalName(), attr.getValue()); + } + } + + /** + * Method serializeNamespace + * + * @param namespace + * @param writer + * @throws XMLStreamException + */ + static void serializeNamespace(OMNamespace namespace, XMLStreamWriter = writer) + throws XMLStreamException { + if (namespace !=3D null) { + String uri =3D namespace.getName(); + String prefix =3D writer.getPrefix(uri); + String ns_prefix =3D namespace.getPrefix(); + if (prefix =3D=3D null) { + writer.writeNamespace(ns_prefix, namespace.getName()); + writer.setPrefix(ns_prefix, uri); + } + } + } + + + /** + * Method serializeStartpart + * + * @param writer + * @throws XMLStreamException + */ + static void serializeStartpart(OMElementImpl element,XMLStreamWriter w= riter) + throws XMLStreamException { + String nameSpaceName =3D null; + String writer_prefix =3D null; + String prefix =3D null; + if (element.ns !=3D null) { + nameSpaceName =3D element.ns.getName(); + writer_prefix =3D writer.getPrefix(nameSpaceName); + prefix =3D element.ns.getPrefix(); + if (nameSpaceName !=3D null) { + if (writer_prefix !=3D null) { + writer.writeStartElement(nameSpaceName, + element.getLocalName()); + } else { + if (prefix !=3D null) { + writer.writeStartElement(prefix, element.getLocalN= ame(), + nameSpaceName); + writer.writeNamespace(prefix, nameSpaceName); + writer.setPrefix(prefix, nameSpaceName); + } else { + writer.writeStartElement(nameSpaceName, + element.getLocalName()); + writer.writeDefaultNamespace(nameSpaceName); + writer.setDefaultNamespace(nameSpaceName); + } + } + } else { + writer.writeStartElement(element.getLocalName()); +// throw new OMException( +// "Non namespace qualified elements are not allowe= d"); + } + } else { + writer.writeStartElement(element.getLocalName()); +// throw new OMException( +// "Non namespace qualified elements are not allowed"); + } + + // add the elements attributes + if (element.attributes !=3D null) { + Iterator attributesList =3D element.attributes.values().iterat= or(); + while (attributesList.hasNext()) { + serializeAttribute((OMAttribute) attributesList.next(), wr= iter); + } + } + + // add the namespaces + Iterator namespaces =3D element.getAllDeclaredNamespaces(); + if (namespaces !=3D null) { + while (namespaces.hasNext()) { + serializeNamespace((OMNamespace) namespaces.next(), writer= ); + } + } + } + + + /** + * Method serializeNormal + * + * @param writer + * @param cache + * @throws XMLStreamException + */ + static void serializeNormal(OMElementImpl element,XMLStreamWriter writ= er, boolean cache) + throws XMLStreamException { + + if (cache){ + element.build(); + } + + serializeStartpart(element,writer); + OMNode firstChild =3D element.firstChild; + if (firstChild !=3D null) { + if (cache){ + firstChild.serializeWithCache(writer); + }else{ + firstChild.serialize(writer); + } + } + serializeEndpart(writer); + } + + static void serializeByPullStream(OMElementImpl element,XMLStreamWrite= r writer) throws XMLStreamException { + StreamingOMSerializer streamingOMSerializer =3D new StreamingOMSeria= lizer(); + streamingOMSerializer.serialize(element.getXMLStreamRea= derWithoutCaching(), + writer); + return; + } +} Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/= llom/util/EmptyIterator.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/= src/org/apache/axis/om/impl/llom/util/EmptyIterator.java?rev=3D167896&view= =3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/util/EmptyIterator.java (added) +++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis/om/impl/llo= m/util/EmptyIterator.java Tue May 3 03:21:36 2005 @@ -0,0 +1,36 @@ +package org.apache.axis.om.impl.llom.util; + +import java.util.Iterator; + +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* An empty Iterator implementation +*/ +public class EmptyIterator implements Iterator { + public void remove() { + throw new UnsupportedOperationException(); + + } + + public boolean hasNext() { + return false; + } + + public Object next() { + throw new UnsupportedOperationException(); + } +} +