Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 33250 invoked from network); 21 Mar 2005 09:04:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Mar 2005 09:04:06 -0000 Received: (qmail 62277 invoked by uid 500); 21 Mar 2005 09:04:05 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 62012 invoked by uid 500); 21 Mar 2005 09:04:04 -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 61997 invoked by uid 99); 21 Mar 2005 09:04:04 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,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; Mon, 21 Mar 2005 01:04:03 -0800 Received: (qmail 33219 invoked by uid 65534); 21 Mar 2005 09:04:02 -0000 Message-ID: <20050321090402.33218.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Mon, 21 Mar 2005 09:04:02 -0000 Subject: svn commit: r158420 - webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/SAXOMBuilder.java To: axis-cvs@ws.apache.org From: dasarath@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: dasarath Date: Mon Mar 21 01:03:58 2005 New Revision: 158420 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D158420 Log: (empty) Added: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl= /llom/builder/SAXOMBuilder.java Added: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/i= mpl/llom/builder/SAXOMBuilder.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/s= rc/java/org/apache/axis/om/impl/llom/builder/SAXOMBuilder.java?view=3Dauto&= rev=3D158420 =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/om/src/java/org/apache/axis/om/impl= /llom/builder/SAXOMBuilder.java (added) +++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl= /llom/builder/SAXOMBuilder.java Mon Mar 21 01:03:58 2005 @@ -0,0 +1,169 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + *=20 + * 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 c= opy of + * the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHO= UT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See th= e + * License for the specific language governing permissions and limitations= under + * the License. + */ + +package org.apache.axis.om.impl.llom.builder; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.axis.om.OMElement; +import org.apache.axis.om.OMException; +import org.apache.axis.om.OMFactory; +import org.apache.axis.om.OMNode; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class SAXOMBuilder extends DefaultHandler { + OMElement root =3D null; + + OMNode lastNode =3D null; + + OMElement nextElem =3D null; + + OMFactory factory =3D OMFactory.newInstance(); + + List prefixMappings =3D new ArrayList(); + + public void setDocumentLocator(Locator arg0) { + } + + public void startDocument() throws SAXException { + + } + + public void endDocument() throws SAXException { + } + + protected OMElement createNextElement(String localName) throws OMExceptio= n { + OMElement e; + if (lastNode =3D=3D null) { + root =3D e =3D factory.createOMElement(localName, null, null, null); + } else if (lastNode.isComplete()) { + e =3D factory.createOMElement(localName, null, lastNode.getParent(), + null); + lastNode.setNextSibling(e); + e.setPreviousSibling(lastNode); + } else { + OMElement parent =3D (OMElement) lastNode; + e =3D factory.createOMElement(localName, null, (OMElement) lastNode, + null); + parent.setFirstChild(e); + } + return e; + } + + /* + * (non-Javadoc) + *=20 + * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, + * java.lang.String) + */ + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + if (nextElem =3D=3D null) + nextElem =3D createNextElement(null); + nextElem.declareNamespace(uri, prefix); + } + + public void endPrefixMapping(String arg0) throws SAXException { + } + + /* + * (non-Javadoc) + *=20 + * @see org.xml.sax.ContentHandler#startElement(java.lang.String, + * java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + public void startElement(String namespaceURI, String localName, + String qName, Attributes atts) throws SAXException { + if (localName =3D=3D null || localName.trim().equals("")) + localName =3D qName.substring(qName.indexOf(':') + 1); + if (nextElem =3D=3D null) + nextElem =3D createNextElement(localName); + else + nextElem.setLocalName(localName); + nextElem + .setNamespace(nextElem.findInScopeNamespace(namespaceURI, null)); + int j =3D atts.getLength(); + for (int i =3D 0; i < j; i++) + nextElem.insertAttribute(atts.getLocalName(i), atts.getValue(i), + nextElem.findInScopeNamespace(atts.getURI(i), null)); + lastNode =3D nextElem; + nextElem =3D null; + } + + /* + * (non-Javadoc) + *=20 + * @see org.xml.sax.ContentHandler#endElement(java.lang.String, + * java.lang.String, java.lang.String) + */ + public void endElement(String arg0, String arg1, String arg2) + throws SAXException { + if (lastNode.isComplete()) { + OMElement parent =3D lastNode.getParent(); + parent.setComplete(true); + lastNode =3D parent; + } else { + OMElement e =3D (OMElement) lastNode; + e.setComplete(true); + } + } + + /* + * (non-Javadoc) + *=20 + * @see org.xml.sax.ContentHandler#characters(char[], int, int) + */ + public void characters(char[] ch, int start, int length) + throws SAXException { + if (lastNode =3D=3D null) { + throw new SAXException(""); + } + OMNode node; + if (lastNode.isComplete()) { + node =3D factory.createText(lastNode.getParent(), new String(ch, + start, length)); + lastNode.setNextSibling(node); + node.setPreviousSibling(lastNode); + } else { + OMElement e =3D (OMElement) lastNode; + node =3D factory.createText(e, new String(ch, start, length)); + e.setFirstChild(node); + } + lastNode =3D node; + } + + public void ignorableWhitespace(char[] arg0, int arg1, int arg2) + throws SAXException { + } + + public void processingInstruction(String arg0, String arg1) + throws SAXException { + } + + public void skippedEntity(String arg0) throws SAXException { + } + + /** + * @return Returns the root. + */ + public OMElement getRootElement() { + return root; + } +} \ No newline at end of file