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 da...@apache.org on 2005/03/21 10:04:02 UTC
svn commit: r158420 -
webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/SAXOMBuilder.java
Author: dasarath
Date: Mon Mar 21 01:03:58 2005
New Revision: 158420
URL: http://svn.apache.org/viewcvs?view=rev&rev=158420
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/impl/llom/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/SAXOMBuilder.java?view=auto&rev=158420
==============================================================================
--- 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.
+ *
+ * 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.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 = null;
+
+ OMNode lastNode = null;
+
+ OMElement nextElem = null;
+
+ OMFactory factory = OMFactory.newInstance();
+
+ List prefixMappings = new ArrayList();
+
+ public void setDocumentLocator(Locator arg0) {
+ }
+
+ public void startDocument() throws SAXException {
+
+ }
+
+ public void endDocument() throws SAXException {
+ }
+
+ protected OMElement createNextElement(String localName) throws OMException {
+ OMElement e;
+ if (lastNode == null) {
+ root = e = factory.createOMElement(localName, null, null, null);
+ } else if (lastNode.isComplete()) {
+ e = factory.createOMElement(localName, null, lastNode.getParent(),
+ null);
+ lastNode.setNextSibling(e);
+ e.setPreviousSibling(lastNode);
+ } else {
+ OMElement parent = (OMElement) lastNode;
+ e = factory.createOMElement(localName, null, (OMElement) lastNode,
+ null);
+ parent.setFirstChild(e);
+ }
+ return e;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
+ * java.lang.String)
+ */
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ if (nextElem == null)
+ nextElem = createNextElement(null);
+ nextElem.declareNamespace(uri, prefix);
+ }
+
+ public void endPrefixMapping(String arg0) throws SAXException {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @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 == null || localName.trim().equals(""))
+ localName = qName.substring(qName.indexOf(':') + 1);
+ if (nextElem == null)
+ nextElem = createNextElement(localName);
+ else
+ nextElem.setLocalName(localName);
+ nextElem
+ .setNamespace(nextElem.findInScopeNamespace(namespaceURI, null));
+ int j = atts.getLength();
+ for (int i = 0; i < j; i++)
+ nextElem.insertAttribute(atts.getLocalName(i), atts.getValue(i),
+ nextElem.findInScopeNamespace(atts.getURI(i), null));
+ lastNode = nextElem;
+ nextElem = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @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 = lastNode.getParent();
+ parent.setComplete(true);
+ lastNode = parent;
+ } else {
+ OMElement e = (OMElement) lastNode;
+ e.setComplete(true);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ if (lastNode == null) {
+ throw new SAXException("");
+ }
+ OMNode node;
+ if (lastNode.isComplete()) {
+ node = factory.createText(lastNode.getParent(), new String(ch,
+ start, length));
+ lastNode.setNextSibling(node);
+ node.setPreviousSibling(lastNode);
+ } else {
+ OMElement e = (OMElement) lastNode;
+ node = factory.createText(e, new String(ch, start, length));
+ e.setFirstChild(node);
+ }
+ lastNode = 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