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:40:54 UTC
svn commit: r1728818 - in
/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl:
common/builder/BuilderHandlerXMLStreamWriter.java
common/builder/PushOMBuilder.java mixin/AxiomSourcedElementSupport.aj
Author: veithen
Date: Sat Feb 6 11:40:53 2016
New Revision: 1728818
URL: http://svn.apache.org/viewvc?rev=1728818&view=rev
Log:
Trivial change that will allow us to turn PushOMBuilder into a real builder, i.e. to implement OMXMLParserWrapper.
Added:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandlerXMLStreamWriter.java
- copied, changed from r1728806, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java
Modified:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj
Copied: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandlerXMLStreamWriter.java (from r1728806, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandlerXMLStreamWriter.java?p2=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandlerXMLStreamWriter.java&p1=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java&r1=1728806&r2=1728818&rev=1728818&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandlerXMLStreamWriter.java Sat Feb 6 11:40:53 2016
@@ -36,14 +36,14 @@ import org.apache.axiom.om.impl.intf.OMF
import org.apache.axiom.om.impl.intf.TextContent;
import org.apache.axiom.util.stax.AbstractXMLStreamWriter;
-public class PushOMBuilder extends AbstractXMLStreamWriter implements DataHandlerWriter {
+public class BuilderHandlerXMLStreamWriter extends AbstractXMLStreamWriter implements DataHandlerWriter {
private final AxiomSourcedElement root;
private final OMFactoryEx factory;
private final BuilderHandler handler;
- public PushOMBuilder(AxiomSourcedElement root) throws XMLStreamException {
+ public BuilderHandlerXMLStreamWriter(BuilderHandler handler, AxiomSourcedElement root) throws XMLStreamException {
+ this.handler = handler;
this.root = root;
- handler = new BuilderHandler(root.coreGetNodeFactory(), PlainXMLModel.INSTANCE, null);
factory = (OMFactoryEx)root.getOMFactory();
// Seed the namespace context with the namespace context from the parent
OMContainer parent = root.getParent();
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java?rev=1728818&r1=1728817&r2=1728818&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PushOMBuilder.java Sat Feb 6 11:40:53 2016
@@ -18,187 +18,23 @@
*/
package org.apache.axiom.om.impl.common.builder;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.activation.DataHandler;
import javax.xml.stream.XMLStreamException;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
-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.impl.intf.AxiomElement;
+import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
-import org.apache.axiom.om.impl.intf.OMFactoryEx;
-import org.apache.axiom.om.impl.intf.TextContent;
-import org.apache.axiom.util.stax.AbstractXMLStreamWriter;
-public class PushOMBuilder extends AbstractXMLStreamWriter implements DataHandlerWriter {
+public class PushOMBuilder {
private final AxiomSourcedElement root;
- private final OMFactoryEx factory;
+ private final OMDataSource dataSource;
private final BuilderHandler handler;
- public PushOMBuilder(AxiomSourcedElement root) throws XMLStreamException {
+ public PushOMBuilder(AxiomSourcedElement root, OMDataSource dataSource) throws XMLStreamException {
this.root = root;
handler = new BuilderHandler(root.coreGetNodeFactory(), PlainXMLModel.INSTANCE, null);
- factory = (OMFactoryEx)root.getOMFactory();
- // Seed the namespace context with the namespace context from the parent
- OMContainer parent = root.getParent();
- if (parent instanceof OMElement) {
- for (Iterator<OMNamespace> it = ((OMElement)parent).getNamespacesInScope(); it.hasNext(); ) {
- OMNamespace ns = it.next();
- setPrefix(ns.getPrefix(), ns.getNamespaceURI());
- }
- }
+ this.dataSource = dataSource;
}
- public Object getProperty(String name) throws IllegalArgumentException {
- if (DataHandlerWriter.PROPERTY.equals(name)) {
- return this;
- } else {
- throw new IllegalArgumentException("Unsupported property " + name);
- }
- }
-
- protected void doWriteStartDocument() {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeStartDocument()");
- }
-
- protected void doWriteStartDocument(String encoding, String version) {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeStartDocument(String, String)");
- }
-
- protected void doWriteStartDocument(String version) {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeStartDocument(String)");
- }
-
- protected void doWriteEndDocument() {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeEndDocument()");
- }
-
- protected void doWriteDTD(String dtd) throws XMLStreamException {
- throw new XMLStreamException("A DTD must not appear in element content");
- }
-
- private OMNamespace getOMNamespace(String prefix, String namespaceURI, boolean isDecl) {
- if (prefix == null) {
- prefix = "";
- }
- if (namespaceURI == null) {
- namespaceURI = "";
- }
- if (!isDecl && namespaceURI.length() == 0) {
- return null;
- } else {
- if (handler.target != null) {
- // If possible, locate an existing OMNamespace object
- OMNamespace ns = ((OMElement)handler.target).findNamespaceURI(prefix);
- if (ns != null && ns.getNamespaceURI().equals(namespaceURI)) {
- return ns;
- }
- }
- return factory.createOMNamespace(namespaceURI, prefix);
- }
- }
-
- protected void doWriteStartElement(String prefix, String localName, String namespaceURI) {
- // Get the OMNamespace object before we change the parent
- OMNamespace ns = getOMNamespace(prefix, namespaceURI, false);
- if (handler.target == null) {
- root.validateName(prefix, localName, namespaceURI);
- handler.target = root;
- handler.elementLevel = 1;
- } else {
- handler.startElement(namespaceURI, localName, prefix);
- }
- if (ns != null) {
- ((OMElement)handler.target).setNamespace(ns, false);
- }
- }
-
- protected void doWriteStartElement(String localName) throws XMLStreamException {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeStartElement(String)");
- }
-
- protected void doWriteEndElement() {
- handler.endElement();
- }
-
- protected void doWriteEmptyElement(String prefix, String localName, String namespaceURI) {
- doWriteStartElement(prefix, localName, namespaceURI);
- doWriteEndElement();
- }
-
- protected void doWriteEmptyElement(String localName) throws XMLStreamException {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT use XMLStreamWriter#writeEmptyElement(String)");
- }
-
- protected void doWriteAttribute(String prefix, String namespaceURI, String localName, String value) {
- OMAttribute attr = factory.createOMAttribute(localName, getOMNamespace(prefix, namespaceURI, false), value);
- // Use the internal appendAttribute method instead of addAttribute in order to avoid
- // automatic of a namespace declaration (the OMDataSource is required to produce well formed
- // XML with respect to namespaces, so it will take care of the namespace declarations).
- ((AxiomElement)handler.target).internalAppendAttribute(attr);
- }
-
- protected void doWriteAttribute(String localName, String value) throws XMLStreamException {
- doWriteAttribute(null, null, localName, value);
- }
-
- protected void doWriteNamespace(String prefix, String namespaceURI) {
- ((AxiomElement)handler.target).addNamespaceDeclaration(getOMNamespace(prefix, namespaceURI, true));
- }
-
- protected void doWriteDefaultNamespace(String namespaceURI) {
- doWriteNamespace(null, namespaceURI);
- }
-
- protected void doWriteCharacters(char[] text, int start, int len) {
- doWriteCharacters(new String(text, start, len));
- }
-
- protected void doWriteCharacters(String text) {
- handler.processCharacterData(text, false);
- }
-
- protected void doWriteCData(String data) {
- handler.createCDATASection(data);
- }
-
- protected void doWriteComment(String data) {
- handler.createComment(data);
- }
-
- protected void doWriteEntityRef(String name) throws XMLStreamException {
- handler.createEntityReference(name, null);
- }
-
- protected void doWriteProcessingInstruction(String piTarget, String data) {
- handler.createProcessingInstruction(piTarget, data);
- }
-
- protected void doWriteProcessingInstruction(String target) {
- doWriteProcessingInstruction(target, "");
- }
-
- public void flush() throws XMLStreamException {
- // Do nothing
- }
-
- public void close() throws XMLStreamException {
- throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter) MUST NOT call XMLStreamWriter#close()");
- }
-
- public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize)
- throws IOException, XMLStreamException {
- handler.processCharacterData(new TextContent(contentID, dataHandler, optimize), false);
- }
-
- public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID,
- boolean optimize) throws IOException, XMLStreamException {
- handler.processCharacterData(new TextContent(contentID, dataHandlerProvider, optimize), false);
+ public void expand() throws XMLStreamException {
+ dataSource.serialize(new BuilderHandlerXMLStreamWriter(handler, root));
}
}
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj?rev=1728818&r1=1728817&r2=1728818&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj Sat Feb 6 11:40:53 2016
@@ -218,7 +218,7 @@ public aspect AxiomSourcedElementSupport
// Set this before we start expanding; otherwise this would result in an infinite recursion
isExpanded = true;
try {
- dataSource.serialize(new PushOMBuilder(this));
+ new PushOMBuilder(this, dataSource).expand();
} catch (XMLStreamException ex) {
throw new OMException("Failed to expand data source", ex);
}