You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/02/04 23:44:43 UTC
svn commit: r1728563 - in
/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common:
OMContentHandler.java SAXResultContentHandler.java factory/SAXOMBuilder.java
Author: veithen
Date: Thu Feb 4 22:44:43 2016
New Revision: 1728563
URL: http://svn.apache.org/viewvc?rev=1728563&view=rev
Log:
Refactor OMContentHandler and subclasses so that we can start using BuilderHandler in SAXOMBuilder.
Modified:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java?rev=1728563&r1=1728562&r2=1728563&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java Thu Feb 4 22:44:43 2016
@@ -19,7 +19,6 @@
package org.apache.axiom.om.impl.common;
import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
@@ -37,8 +36,6 @@ import java.util.Map;
public abstract class OMContentHandler implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
private final boolean expandEntityReferences;
- private OMContainer root;
-
/**
* Stores the root name if there is a DTD.
*/
@@ -68,8 +65,6 @@ public abstract class OMContentHandler i
* Flag indicating that the parser is processing the external subset.
*/
private boolean inExternalSubset;
-
- private OMContainer target;
/**
* Stores namespace declarations reported to {@link #startPrefixMapping(String, String)}. These
@@ -97,15 +92,11 @@ public abstract class OMContentHandler i
}
public final void startDocument() throws SAXException {
- target = root = doStartDocument();
+ doStartDocument();
}
public final void endDocument() throws SAXException {
- if (target != root) {
- throw new IllegalStateException();
- }
doEndDocument();
- target = null;
}
public final void startDTD(String name, String publicId, String systemId) throws SAXException {
@@ -205,7 +196,7 @@ public abstract class OMContentHandler i
}
public final void endDTD() throws SAXException {
- createOMDocType(target, dtdName, dtdPublicId, dtdSystemId,
+ createOMDocType(dtdName, dtdPublicId, dtdSystemId,
internalSubset.length() == 0 ? null : internalSubset.toString());
internalSubset = null;
}
@@ -247,7 +238,7 @@ public abstract class OMContentHandler i
localName = qName.substring(qName.indexOf(':') + 1);
int idx = qName.indexOf(':');
String prefix = idx == -1 ? "" : qName.substring(0, idx);
- OMElement element = createOMElement(target, localName, namespaceURI, prefix, namespaces, namespaceCount);
+ OMElement element = createOMElement(localName, namespaceURI, prefix, namespaces, namespaceCount);
namespaceCount = 0;
int j = atts.getLength();
@@ -276,8 +267,6 @@ public abstract class OMContentHandler i
attr.setAttributeType(atts.getType(i));
}
}
-
- target = element;
}
}
@@ -290,8 +279,7 @@ public abstract class OMContentHandler i
public final void endElement(String uri, String localName, String qName)
throws SAXException {
if (!inEntityReference) {
- completed((OMElement)target);
- target = ((OMNode)target).getParent();
+ completed();
}
}
@@ -310,7 +298,7 @@ public abstract class OMContentHandler i
private void characterData(char[] ch, int start, int length, int nodeType)
throws SAXException {
if (!inEntityReference) {
- createOMText(target, new String(ch, start, length), nodeType);
+ createOMText(new String(ch, start, length), nodeType);
}
}
@@ -331,18 +319,18 @@ public abstract class OMContentHandler i
public final void processingInstruction(String piTarget, String data)
throws SAXException {
if (!inEntityReference) {
- createOMProcessingInstruction(target, piTarget, data);
+ createOMProcessingInstruction(piTarget, data);
}
}
public final void comment(char[] ch, int start, int length) throws SAXException {
if (!inEntityReference) {
- createOMComment(target, new String(ch, start, length));
+ createOMComment(new String(ch, start, length));
}
}
public final void skippedEntity(String name) throws SAXException {
- createOMEntityReference(target, name, null);
+ createOMEntityReference(name, null);
}
public final void startEntity(String name) throws SAXException {
@@ -351,7 +339,7 @@ public abstract class OMContentHandler i
} else if (name.equals("[dtd]")) {
inExternalSubset = true;
} else if (!expandEntityReferences) {
- createOMEntityReference(target, name, entities == null ? null : entities.get(name));
+ createOMEntityReference(name, entities == null ? null : entities.get(name));
inEntityReference = true;
entityReferenceDepth = 1;
}
@@ -368,24 +356,24 @@ public abstract class OMContentHandler i
}
}
- protected abstract OMContainer doStartDocument();
+ protected abstract void doStartDocument();
protected abstract void doEndDocument();
- protected abstract void createOMDocType(OMContainer parent, String rootName, String publicId,
+ protected abstract void createOMDocType(String rootName, String publicId,
String systemId, String internalSubset);
- protected abstract OMElement createOMElement(OMContainer parent, String localName,
+ protected abstract OMElement createOMElement(String localName,
String namespaceURI, String prefix, String[] namespaces, int namespaceCount);
- protected abstract void completed(OMElement element);
+ protected abstract void completed();
- protected abstract void createOMText(OMContainer parent, String text, int type);
+ protected abstract void createOMText(String text, int type);
- protected abstract void createOMProcessingInstruction(OMContainer parent, String piTarget,
+ protected abstract void createOMProcessingInstruction(String piTarget,
String piData);
- protected abstract void createOMComment(OMContainer parent, String content);
+ protected abstract void createOMComment(String content);
- protected abstract void createOMEntityReference(OMContainer parent, String name, String replacementText);
+ protected abstract void createOMEntityReference(String name, String replacementText);
}
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java?rev=1728563&r1=1728562&r2=1728563&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java Thu Feb 4 22:44:43 2016
@@ -22,10 +22,12 @@ import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
public class SAXResultContentHandler extends OMContentHandler {
private final OMContainer root;
private final OMFactory factory;
+ private OMContainer target;
public SAXResultContentHandler(OMContainer root) {
super(true);
@@ -33,24 +35,24 @@ public class SAXResultContentHandler ext
factory = root.getOMFactory();
}
- protected OMContainer doStartDocument() {
- return root;
+ protected void doStartDocument() {
+ target = root;
}
protected void doEndDocument() {
}
- protected void createOMDocType(OMContainer parent, String rootName, String publicId,
+ protected void createOMDocType(String rootName, String publicId,
String systemId, String internalSubset) {
- if (parent instanceof OMDocument) {
- factory.createOMDocType(parent, rootName, publicId, systemId, internalSubset);
+ if (target instanceof OMDocument) {
+ factory.createOMDocType(target, rootName, publicId, systemId, internalSubset);
}
}
- protected OMElement createOMElement(OMContainer parent, String localName, String namespaceURI,
+ protected OMElement createOMElement(String localName, String namespaceURI,
String prefix, String[] namespaces, int namespaceCount) {
// TODO: inefficient: we should not create a new OMNamespace instance every time
- OMElement element = factory.createOMElement(localName, factory.createOMNamespace(namespaceURI, prefix), parent);
+ OMElement element = factory.createOMElement(localName, factory.createOMNamespace(namespaceURI, prefix), target);
for (int i=0; i<namespaceCount; i++) {
String nsPrefix = namespaces[2*i];
String nsURI = namespaces[2*i+1];
@@ -60,27 +62,29 @@ public class SAXResultContentHandler ext
element.declareNamespace(nsURI, nsPrefix);
}
}
+ target = element;
return element;
}
- protected void completed(OMElement element) {
+ protected void completed() {
+ target = ((OMNode)target).getParent();
}
- protected void createOMText(OMContainer parent, String text, int type) {
- factory.createOMText(parent, text, type);
+ protected void createOMText(String text, int type) {
+ factory.createOMText(target, text, type);
}
- protected void createOMProcessingInstruction(OMContainer parent, String piTarget, String piData) {
- factory.createOMProcessingInstruction(parent, piTarget, piData);
+ protected void createOMProcessingInstruction(String piTarget, String piData) {
+ factory.createOMProcessingInstruction(target, piTarget, piData);
}
- protected void createOMComment(OMContainer parent, String content) {
- factory.createOMComment(parent, content);
+ protected void createOMComment(String content) {
+ factory.createOMComment(target, content);
}
- protected void createOMEntityReference(OMContainer parent, String name, String replacementText) {
+ protected void createOMEntityReference(String name, String replacementText) {
if (replacementText == null) {
- factory.createOMEntityReference(parent, name);
+ factory.createOMEntityReference(target, name);
} else {
// Since we set expandEntityReferences=true, we should never get here
throw new UnsupportedOperationException();
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java?rev=1728563&r1=1728562&r2=1728563&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java Thu Feb 4 22:44:43 2016
@@ -25,6 +25,7 @@ import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.common.OMContentHandler;
import org.apache.axiom.om.impl.common.builder.BuilderUtil;
@@ -48,6 +49,8 @@ public class SAXOMBuilder extends OMCont
private AxiomDocument document;
private final OMFactoryEx factory;
+
+ private OMContainer target;
public SAXOMBuilder(NodeFactory nodeFactory, OMFactory factory, Model model, SAXSource source, boolean expandEntityReferences) {
super(expandEntityReferences);
@@ -57,13 +60,17 @@ public class SAXOMBuilder extends OMCont
this.source = source;
}
- protected OMContainer doStartDocument() {
+ protected void doStartDocument() {
document = nodeFactory.createNode(model.getDocumentType());
document.coreSetBuilder(this);
- return document;
+ target = document;
}
protected void doEndDocument() {
+ if (target != document) {
+ throw new IllegalStateException();
+ }
+ target = null;
((AxiomContainer)document).setComplete(true);
}
@@ -141,41 +148,41 @@ public class SAXOMBuilder extends OMCont
// This is a no-op
}
- protected void createOMDocType(OMContainer parent, String rootName, String publicId,
+ protected void createOMDocType(String rootName, String publicId,
String systemId, String internalSubset) {
- factory.createOMDocType(parent, rootName, publicId, systemId, internalSubset, true);
+ factory.createOMDocType(target, rootName, publicId, systemId, internalSubset, true);
}
- protected OMElement createOMElement(OMContainer parent, String localName,
+ protected OMElement createOMElement(String localName,
String namespaceURI, String prefix, String[] namespaces, int namespaceCount) {
- AxiomElement element = factory.createAxiomElement(AxiomElement.class, localName, parent, this);
+ AxiomElement element = factory.createAxiomElement(AxiomElement.class, localName, target, this);
for (int i = 0; i < namespaceCount; i++) {
element.addNamespaceDeclaration(namespaces[2*i+1], namespaces[2*i]);
}
BuilderUtil.setNamespace(element, namespaceURI, prefix, false);
+ target = element;
return element;
}
- protected void completed(OMElement element) {
- ((AxiomElement)element).setComplete(true);
+ protected void completed() {
+ ((AxiomElement)target).setComplete(true);
+ target = ((OMNode)target).getParent();
}
- protected void createOMText(OMContainer parent, String text, int type) {
- factory.createOMText(parent, text, type, true);
+ protected void createOMText(String text, int type) {
+ factory.createOMText(target, text, type, true);
}
- protected void createOMProcessingInstruction(OMContainer parent,
- String piTarget, String piData) {
- factory.createOMProcessingInstruction(parent, piTarget, piData, true);
+ protected void createOMProcessingInstruction(String piTarget, String piData) {
+ factory.createOMProcessingInstruction(target, piTarget, piData, true);
}
- protected void createOMComment(OMContainer parent, String content) {
- factory.createOMComment(parent, content, true);
+ protected void createOMComment(String content) {
+ factory.createOMComment(target, content, true);
}
- protected void createOMEntityReference(OMContainer parent, String name,
- String replacementText) {
- factory.createOMEntityReference(parent, name, replacementText, true);
+ protected void createOMEntityReference(String name, String replacementText) {
+ factory.createOMEntityReference(target, name, replacementText, true);
}
public void detach() {