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 2012/05/07 22:54:29 UTC
svn commit: r1335254 - in /webservices/axiom/branches/AXIOM-420/modules:
axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/p...
Author: veithen
Date: Mon May 7 20:54:28 2012
New Revision: 1335254
URL: http://svn.apache.org/viewvc?rev=1335254&view=rev
Log:
More code: the push-only OMDataSource feature now works with ADB.
Added:
webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java (with props)
webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java (with props)
webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java (with props)
Modified:
webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java?rev=1335254&r1=1335253&r2=1335254&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java Mon May 7 20:54:28 2012
@@ -18,16 +18,22 @@
*/
package org.apache.axiom.om.impl.llom;
+import java.io.IOException;
+
+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.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
import org.apache.axiom.om.impl.builder.BuilderUtil;
import org.apache.axiom.util.stax.AbstractXMLStreamWriter;
// TODO: need to seed the namespace context with the namespace context from the parent!
-public class PushOMBuilder extends AbstractXMLStreamWriter {
+public class PushOMBuilder extends AbstractXMLStreamWriter implements DataHandlerWriter {
private final OMSourcedElementImpl root;
private final OMFactory factory;
private OMElement parent;
@@ -38,8 +44,11 @@ public class PushOMBuilder extends Abstr
}
public Object getProperty(String name) throws IllegalArgumentException {
- // TODO
- throw new UnsupportedOperationException();
+ if (DataHandlerWriter.PROPERTY.equals(name)) {
+ return this;
+ } else {
+ throw new IllegalArgumentException("Unsupported property " + name);
+ }
}
protected void doWriteStartDocument() {
@@ -104,9 +113,16 @@ public class PushOMBuilder extends Abstr
}
protected void doWriteNamespace(String prefix, String namespaceURI) {
+ if (namespaceURI == null) {
+ namespaceURI = "";
+ }
// Note that the namespace declaration may already have been added automatically by writeStartElement
// or writeAttribute; we count on declareNamespace to do the necessary checks
- parent.declareNamespace(namespaceURI == null ? "" : namespaceURI, prefix == null ? "" : prefix);
+ if (prefix == null || prefix.length() == 0) {
+ parent.declareDefaultNamespace(namespaceURI);
+ } else {
+ parent.declareNamespace(namespaceURI, prefix);
+ }
}
protected void doWriteDefaultNamespace(String namespaceURI) {
@@ -149,4 +165,18 @@ public class PushOMBuilder extends Abstr
public void close() throws XMLStreamException {
// Do nothing
}
+
+ public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize)
+ throws IOException, XMLStreamException {
+ OMText child = factory.createOMText(dataHandler, optimize);
+ if (contentID != null) {
+ child.setContentID(contentID);
+ }
+ parent.addChild(child);
+ }
+
+ public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID,
+ boolean optimize) throws IOException, XMLStreamException {
+ parent.addChild(factory.createOMText(contentID, dataHandlerProvider, optimize));
+ }
}
Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1335254&r1=1335253&r2=1335254&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Mon May 7 20:54:28 2012
@@ -381,7 +381,12 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.sourcedelement.TestWrappedTextNodeOMDataSourceFromReader(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteAttributeNoNamespace(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteDataHandler(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteDataHandlerProvider(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteEmptyElementAutoPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteNamespace(metaFactory, "", ""));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteNamespace(metaFactory, "", "urn:test"));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteNamespace(metaFactory, "p", "urn:test"));
addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteStartElementAutoPrefix(metaFactory));
}
addTest(new org.apache.axiom.ts.om.pi.TestDigest(metaFactory));
Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java?rev=1335254&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java (added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java Mon May 7 20:54:28 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.ts.om.sourcedelement.push;
+
+import java.io.IOException;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.util.stax.XMLStreamWriterUtils;
+
+/**
+ * Tests that {@link DataHandlerWriter#writeDataHandler(DataHandler, String, boolean)} creates an
+ * {@link OMText} backed by a {@link DataHandler}.
+ */
+public class TestWriteDataHandler extends AxiomTestCase {
+ public TestWriteDataHandler(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ final DataHandler dh = new DataHandler("test", "text/plain");
+ OMElement element = factory.createOMElement(new AbstractPushOMDataSource() {
+ public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeStartElement(null, "root", null);
+ try {
+ XMLStreamWriterUtils.writeDataHandler(writer, dh, null, true);
+ } catch (IOException ex) {
+ throw new XMLStreamException(ex);
+ }
+ writer.writeEndElement();
+ }
+
+ public boolean isDestructiveWrite() {
+ return false;
+ }
+ });
+ OMText child = (OMText)element.getFirstOMChild();
+ assertTrue(child.isBinary());
+ assertSame(dh, child.getDataHandler());
+ }
+}
Propchange: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java?rev=1335254&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java (added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java Mon May 7 20:54:28 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.ts.om.sourcedelement.push;
+
+import java.io.IOException;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
+import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.util.stax.XMLStreamWriterUtils;
+
+/**
+ * Tests that {@link DataHandlerWriter#writeDataHandler(DataHandlerProvider, String, boolean)}
+ * creates an {@link OMText} backed by a {@link DataHandlerProvider}.
+ */
+public class TestWriteDataHandlerProvider extends AxiomTestCase {
+ public TestWriteDataHandlerProvider(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ final DataHandler dh = new DataHandler("test", "text/plain");
+ final DataHandlerProvider dhp = new DataHandlerProvider() {
+ public boolean isLoaded() {
+ return true;
+ }
+
+ public DataHandler getDataHandler() throws IOException {
+ return dh;
+ }
+ };
+ OMElement element = factory.createOMElement(new AbstractPushOMDataSource() {
+ public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeStartElement(null, "root", null);
+ try {
+ XMLStreamWriterUtils.writeDataHandler(writer, dhp, null, true);
+ } catch (IOException ex) {
+ throw new XMLStreamException(ex);
+ }
+ writer.writeEndElement();
+ }
+
+ public boolean isDestructiveWrite() {
+ return false;
+ }
+ });
+ OMText child = (OMText)element.getFirstOMChild();
+ assertTrue(child.isBinary());
+ assertSame(dh, child.getDataHandler());
+ }
+}
Propchange: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java?rev=1335254&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java (added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java Mon May 7 20:54:28 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.ts.om.sourcedelement.push;
+
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link XMLStreamWriter#writeNamespace(String, String)} creates the expected namespace
+ * declaration.
+ */
+public class TestWriteNamespace extends AxiomTestCase {
+ private final String prefix;
+ private final String namespaceURI;
+
+ public TestWriteNamespace(OMMetaFactory metaFactory, String prefix, String namespaceURI) {
+ super(metaFactory);
+ this.prefix = prefix;
+ this.namespaceURI = namespaceURI;
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new AbstractPushOMDataSource() {
+ public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeStartElement("_p_", "root", "urn:__test__");
+ writer.writeNamespace("_p_", "urn:test");
+ writer.writeNamespace(prefix, namespaceURI);
+ writer.writeEndElement();
+ }
+
+ public boolean isDestructiveWrite() {
+ return false;
+ }
+ });
+ OMNamespace decl = null;
+ Iterator it = element.getAllDeclaredNamespaces();
+ while (it.hasNext()) {
+ OMNamespace ns = (OMNamespace)it.next();
+ if (!ns.getPrefix().equals("_p_")) {
+ if (decl != null) {
+ fail("Found unexpected namespace declaration");
+ } else {
+ decl = ns;
+ }
+ }
+ }
+ assertNotNull(decl);
+ assertEquals(prefix, decl.getPrefix());
+ assertEquals(namespaceURI, decl.getNamespaceURI());
+ }
+}
Propchange: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java
------------------------------------------------------------------------------
svn:eol-style = native