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/06 12:02:19 UTC
svn commit: r1728809 - in
/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl:
common/ common/factory/ mixin/
Author: veithen
Date: Sat Feb 6 11:02:19 2016
New Revision: 1728809
URL: http://svn.apache.org/viewvc?rev=1728809&view=rev
Log:
Prefer composition over inheritance.
Added:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java (with props)
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
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java?rev=1728809&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java (added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java Sat Feb 6 11:02:19 2016
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.om.impl.common;
+
+import org.apache.axiom.om.OMElement;
+
+// TODO: transitional interface that should eventually converge with BuilderHandler
+public interface Handler {
+ void doStartDocument();
+
+ void doEndDocument();
+
+ void createOMDocType(String rootName, String publicId,
+ String systemId, String internalSubset);
+
+ OMElement createOMElement(String localName,
+ String namespaceURI, String prefix, String[] namespaces, int namespaceCount);
+
+ void completed();
+
+ void createOMText(String text, int type);
+
+ void createOMProcessingInstruction(String piTarget,
+ String piData);
+
+ void createOMComment(String content);
+
+ void createOMEntityReference(String name, String replacementText);
+}
Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1728809&r1=1728808&r2=1728809&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 Sat Feb 6 11:02:19 2016
@@ -33,7 +33,8 @@ import org.xml.sax.ext.LexicalHandler;
import java.util.HashMap;
import java.util.Map;
-public abstract class OMContentHandler implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
+public final class OMContentHandler implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
+ private final Handler handler;
private final boolean expandEntityReferences;
/**
@@ -84,7 +85,8 @@ public abstract class OMContentHandler i
private boolean inEntityReference;
private int entityReferenceDepth;
- public OMContentHandler(boolean expandEntityReferences) {
+ public OMContentHandler(Handler handler, boolean expandEntityReferences) {
+ this.handler = handler;
this.expandEntityReferences = expandEntityReferences;
}
@@ -92,11 +94,11 @@ public abstract class OMContentHandler i
}
public final void startDocument() throws SAXException {
- doStartDocument();
+ handler.doStartDocument();
}
public final void endDocument() throws SAXException {
- doEndDocument();
+ handler.doEndDocument();
}
public final void startDTD(String name, String publicId, String systemId) throws SAXException {
@@ -196,7 +198,7 @@ public abstract class OMContentHandler i
}
public final void endDTD() throws SAXException {
- createOMDocType(dtdName, dtdPublicId, dtdSystemId,
+ handler.createOMDocType(dtdName, dtdPublicId, dtdSystemId,
internalSubset.length() == 0 ? null : internalSubset.toString());
internalSubset = null;
}
@@ -238,7 +240,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(localName, namespaceURI, prefix, namespaces, namespaceCount);
+ OMElement element = handler.createOMElement(localName, namespaceURI, prefix, namespaces, namespaceCount);
namespaceCount = 0;
int j = atts.getLength();
@@ -279,7 +281,7 @@ public abstract class OMContentHandler i
public final void endElement(String uri, String localName, String qName)
throws SAXException {
if (!inEntityReference) {
- completed();
+ handler.completed();
}
}
@@ -298,7 +300,7 @@ public abstract class OMContentHandler i
private void characterData(char[] ch, int start, int length, int nodeType)
throws SAXException {
if (!inEntityReference) {
- createOMText(new String(ch, start, length), nodeType);
+ handler.createOMText(new String(ch, start, length), nodeType);
}
}
@@ -319,18 +321,18 @@ public abstract class OMContentHandler i
public final void processingInstruction(String piTarget, String data)
throws SAXException {
if (!inEntityReference) {
- createOMProcessingInstruction(piTarget, data);
+ handler.createOMProcessingInstruction(piTarget, data);
}
}
public final void comment(char[] ch, int start, int length) throws SAXException {
if (!inEntityReference) {
- createOMComment(new String(ch, start, length));
+ handler.createOMComment(new String(ch, start, length));
}
}
public final void skippedEntity(String name) throws SAXException {
- createOMEntityReference(name, null);
+ handler.createOMEntityReference(name, null);
}
public final void startEntity(String name) throws SAXException {
@@ -339,7 +341,7 @@ public abstract class OMContentHandler i
} else if (name.equals("[dtd]")) {
inExternalSubset = true;
} else if (!expandEntityReferences) {
- createOMEntityReference(name, entities == null ? null : entities.get(name));
+ handler.createOMEntityReference(name, entities == null ? null : entities.get(name));
inEntityReference = true;
entityReferenceDepth = 1;
}
@@ -355,25 +357,4 @@ public abstract class OMContentHandler i
inExternalSubset = false;
}
}
-
- protected abstract void doStartDocument();
-
- protected abstract void doEndDocument();
-
- protected abstract void createOMDocType(String rootName, String publicId,
- String systemId, String internalSubset);
-
- protected abstract OMElement createOMElement(String localName,
- String namespaceURI, String prefix, String[] namespaces, int namespaceCount);
-
- protected abstract void completed();
-
- protected abstract void createOMText(String text, int type);
-
- protected abstract void createOMProcessingInstruction(String piTarget,
- String piData);
-
- protected abstract void createOMComment(String content);
-
- 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=1728809&r1=1728808&r2=1728809&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 Sat Feb 6 11:02:19 2016
@@ -24,32 +24,31 @@ import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNode;
-public class SAXResultContentHandler extends OMContentHandler {
+public final class SAXResultContentHandler implements Handler {
private final OMContainer root;
private final OMFactory factory;
private OMContainer target;
public SAXResultContentHandler(OMContainer root) {
- super(true);
this.root = root;
factory = root.getOMFactory();
}
- protected void doStartDocument() {
+ public void doStartDocument() {
target = root;
}
- protected void doEndDocument() {
+ public void doEndDocument() {
}
- protected void createOMDocType(String rootName, String publicId,
+ public void createOMDocType(String rootName, String publicId,
String systemId, String internalSubset) {
if (target instanceof OMDocument) {
factory.createOMDocType(target, rootName, publicId, systemId, internalSubset);
}
}
- protected OMElement createOMElement(String localName, String namespaceURI,
+ public 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), target);
@@ -66,23 +65,23 @@ public class SAXResultContentHandler ext
return element;
}
- protected void completed() {
+ public void completed() {
target = ((OMNode)target).getParent();
}
- protected void createOMText(String text, int type) {
+ public void createOMText(String text, int type) {
factory.createOMText(target, text, type);
}
- protected void createOMProcessingInstruction(String piTarget, String piData) {
+ public void createOMProcessingInstruction(String piTarget, String piData) {
factory.createOMProcessingInstruction(target, piTarget, piData);
}
- protected void createOMComment(String content) {
+ public void createOMComment(String content) {
factory.createOMComment(target, content);
}
- protected void createOMEntityReference(String name, String replacementText) {
+ public void createOMEntityReference(String name, String replacementText) {
if (replacementText == null) {
factory.createOMEntityReference(target, name);
} else {
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=1728809&r1=1728808&r2=1728809&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 Sat Feb 6 11:02:19 2016
@@ -24,6 +24,7 @@ import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.common.Handler;
import org.apache.axiom.om.impl.common.OMContentHandler;
import org.apache.axiom.om.impl.common.builder.BuilderHandler;
import org.apache.axiom.om.impl.common.builder.BuilderUtil;
@@ -38,21 +39,22 @@ import java.io.IOException;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.transform.sax.SAXSource;
-public class SAXOMBuilder extends OMContentHandler implements OMXMLParserWrapper {
+public final class SAXOMBuilder implements OMXMLParserWrapper, Handler {
+ private final boolean expandEntityReferences;
private final BuilderHandler handler;
private final SAXSource source;
public SAXOMBuilder(NodeFactory nodeFactory, Model model, SAXSource source, boolean expandEntityReferences) {
- super(expandEntityReferences);
+ this.expandEntityReferences = expandEntityReferences;
handler = new BuilderHandler(nodeFactory, model, this);
this.source = source;
}
- protected void doStartDocument() {
+ public void doStartDocument() {
handler.startDocument(null, "1.0", null, true);
}
- protected void doEndDocument() {
+ public void doEndDocument() {
if (handler.target != handler.document) {
throw new IllegalStateException();
}
@@ -63,15 +65,16 @@ public class SAXOMBuilder extends OMCont
public OMDocument getDocument() {
if (handler.document == null && source != null) {
XMLReader reader = source.getXMLReader();
- reader.setContentHandler(this);
- reader.setDTDHandler(this);
+ OMContentHandler contentHandler = new OMContentHandler(this, expandEntityReferences);
+ reader.setContentHandler(contentHandler);
+ reader.setDTDHandler(contentHandler);
try {
- reader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler", contentHandler);
} catch (SAXException ex) {
// Ignore
}
try {
- reader.setProperty("http://xml.org/sax/properties/declaration-handler", this);
+ reader.setProperty("http://xml.org/sax/properties/declaration-handler", contentHandler);
} catch (SAXException ex) {
// Ignore
}
@@ -134,12 +137,12 @@ public class SAXOMBuilder extends OMCont
// This is a no-op
}
- protected void createOMDocType(String rootName, String publicId,
+ public void createOMDocType(String rootName, String publicId,
String systemId, String internalSubset) {
handler.createDocumentTypeDeclaration(rootName, publicId, systemId, internalSubset);
}
- protected OMElement createOMElement(String localName,
+ public OMElement createOMElement(String localName,
String namespaceURI, String prefix, String[] namespaces, int namespaceCount) {
AxiomElement element = handler.startElement(null, localName, null);
for (int i = 0; i < namespaceCount; i++) {
@@ -149,11 +152,11 @@ public class SAXOMBuilder extends OMCont
return element;
}
- protected void completed() {
+ public void completed() {
handler.endElement();
}
- protected void createOMText(String text, int type) {
+ public void createOMText(String text, int type) {
switch (type) {
case XMLStreamConstants.CHARACTERS:
handler.processCharacterData(text, false);
@@ -169,15 +172,15 @@ public class SAXOMBuilder extends OMCont
}
}
- protected void createOMProcessingInstruction(String piTarget, String piData) {
+ public void createOMProcessingInstruction(String piTarget, String piData) {
handler.createProcessingInstruction(piTarget, piData);
}
- protected void createOMComment(String content) {
+ public void createOMComment(String content) {
handler.createComment(content);
}
- protected void createOMEntityReference(String name, String replacementText) {
+ public void createOMEntityReference(String name, String replacementText) {
handler.createEntityReference(name, replacementText);
}
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj?rev=1728809&r1=1728808&r2=1728809&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj Sat Feb 6 11:02:19 2016
@@ -51,6 +51,7 @@ import org.apache.axiom.om.impl.builder.
import org.apache.axiom.om.impl.common.AxiomSemantics;
import org.apache.axiom.om.impl.common.NamespaceURIInterningXMLStreamReaderWrapper;
import org.apache.axiom.om.impl.common.OMChildrenQNameIterator;
+import org.apache.axiom.om.impl.common.OMContentHandler;
import org.apache.axiom.om.impl.common.SAXResultContentHandler;
import org.apache.axiom.om.impl.common.serializer.pull.OMXMLStreamReaderExAdapter;
import org.apache.axiom.om.impl.common.serializer.pull.PullSerializer;
@@ -258,7 +259,7 @@ public aspect AxiomContainerSupport {
}
public final SAXResult AxiomContainer.getSAXResult() {
- SAXResultContentHandler handler = new SAXResultContentHandler(this);
+ OMContentHandler handler = new OMContentHandler(new SAXResultContentHandler(this), true);
SAXResult result = new SAXResult();
result.setHandler(handler);
result.setLexicalHandler(handler);