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/07/29 13:24:07 UTC
svn commit: r1366814 - in
/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb: ./
src/main/java/org/apache/axiom/om/ds/jaxb/
src/test/java/org/apache/axiom/om/ds/jaxb/
src/test/java/org/apache/axiom/om/ds/jaxb/beans/ src/test/schemas/
Author: veithen
Date: Sun Jul 29 11:24:06 2012
New Revision: 1366814
URL: http://svn.apache.org/viewvc?rev=1366814&view=rev
Log:
Let JAXBOMDataSource implement QNameAwareOMDataSource.
Added:
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/schemas/
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/schemas/identity.xsd
Modified:
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/DocumentBean.java
Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml?rev=1366814&r1=1366813&r2=1366814&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml Sun Jul 29 11:24:06 2012
@@ -65,6 +65,24 @@
</dependencies>
<build>
<plugins>
+ <plugin>
+ <groupId>org.jvnet.jaxb2.maven2</groupId>
+ <artifactId>maven-jaxb2-plugin</artifactId>
+ <version>0.8.0</version>
+ <executions>
+ <execution>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <schemaDirectory>src/test/schemas</schemaDirectory>
+ <addCompileSourceRoot>false</addCompileSourceRoot>
+ <addTestCompileSourceRoot>true</addTestCompileSourceRoot>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java?rev=1366814&r1=1366813&r2=1366814&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/main/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSource.java Sun Jul 29 11:24:06 2012
@@ -19,19 +19,24 @@
package org.apache.axiom.om.ds.jaxb;
import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
+import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.QNameAwareOMDataSource;
import org.apache.axiom.om.ds.AbstractPushOMDataSource;
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.util.stax.xop.XOPDecodingStreamWriter;
-public class JAXBOMDataSource extends AbstractPushOMDataSource {
+public class JAXBOMDataSource extends AbstractPushOMDataSource implements QNameAwareOMDataSource {
private final JAXBContext context;
private final Object object;
+ private QName cachedQName;
public JAXBOMDataSource(JAXBContext context, Object object) {
this.context = context;
@@ -70,4 +75,32 @@ public class JAXBOMDataSource extends Ab
throw new XMLStreamException("Error marshalling JAXB object", ex);
}
}
+
+ private QName getQName() {
+ if (cachedQName == null) {
+ if (object instanceof JAXBElement) {
+ cachedQName = ((JAXBElement<?>)object).getName();
+ } else {
+ cachedQName = context.createJAXBIntrospector().getElementName(object);
+ if (cachedQName == null) {
+ // We get here if the class of the object is not known to
+ // the JAXBContext
+ throw new OMException("Unable to determine the element name of the object");
+ }
+ }
+ }
+ return cachedQName;
+ }
+
+ public String getLocalName() {
+ return getQName().getLocalPart();
+ }
+
+ public String getNamespaceURI() {
+ return getQName().getNamespaceURI();
+ }
+
+ public String getPrefix() {
+ return null;
+ }
}
Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java?rev=1366814&r1=1366813&r2=1366814&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java Sun Jul 29 11:24:06 2012
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
import javax.activation.DataHandler;
import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.apache.axiom.attachments.Attachments;
@@ -41,6 +42,8 @@ import org.apache.axiom.om.OMXMLBuilderF
import org.apache.axiom.om.ds.jaxb.beans.DocumentBean;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
+import org.example.identity.LinkIdentitiesType;
+import org.example.identity.ObjectFactory;
import org.junit.Test;
public class JAXBOMDataSourceTest {
@@ -105,4 +108,40 @@ public class JAXBOMDataSourceTest {
DataHandler dh = (DataHandler)content.getDataHandler();
assertEquals("some content", dh.getContent());
}
+
+ /**
+ * Tests that {@link JAXBOMDataSource} backed by a plain Java bean is able to determine the
+ * namespace URI and local name of the element without expansion.
+ */
+ @Test
+ public void testGetNameFromPlainObject() throws Exception {
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+ JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
+ OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, new DocumentBean()));
+ assertEquals("http://ws.apache.org/axiom/test/jaxb", element.getNamespaceURI());
+ assertEquals("document", element.getLocalName());
+ assertFalse(element.isExpanded());
+ // Force expansion so that OMSourcedElement compares the namespace URI and local name
+ // provided by JAXBOMDataSource with the actual name of the element
+ element.getFirstOMChild();
+ }
+
+ /**
+ * Tests that {@link JAXBOMDataSource} backed by a {@link JAXBElement} is able to determine the
+ * namespace URI and local name of the element without expansion.
+ */
+ @Test
+ public void testGetNameFromJAXBElement() throws Exception {
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+ ObjectFactory objectFactory = new ObjectFactory();
+ JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
+ JAXBElement<LinkIdentitiesType> jaxbElement = objectFactory.createLinkIdentities(new LinkIdentitiesType());
+ OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, jaxbElement));
+ assertEquals("http://www.example.org/identity", element.getNamespaceURI());
+ assertEquals("LinkIdentities", element.getLocalName());
+ assertFalse(element.isExpanded());
+ // Force expansion so that OMSourcedElement compares the namespace URI and local name
+ // provided by JAXBOMDataSource with the actual name of the element
+ element.getFirstOMChild();
+ }
}
Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/DocumentBean.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/DocumentBean.java?rev=1366814&r1=1366813&r2=1366814&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/DocumentBean.java (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/DocumentBean.java Sun Jul 29 11:24:06 2012
@@ -22,7 +22,7 @@ import javax.activation.DataHandler;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
-@XmlRootElement
+@XmlRootElement(name="document")
@XmlType(propOrder={ "id", "content" })
public class DocumentBean {
private String id;
Added: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/schemas/identity.xsd
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/schemas/identity.xsd?rev=1366814&view=auto
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/schemas/identity.xsd (added)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/schemas/identity.xsd Sun Jul 29 11:24:06 2012
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified" attributeFormDefault="unqualified"
+ xmlns="http://www.example.org/identity" targetNamespace="http://www.example.org/identity">
+
+ <xs:complexType name="linkIdentitiesResponseType">
+ <xs:sequence>
+ <xs:element name="owningPlatform" type="xs:string"
+ minOccurs="1" maxOccurs="1" nillable="false" />
+ </xs:sequence>
+ </xs:complexType>
+
+
+ <xs:complexType name="modifyLinkResponseType">
+ <xs:complexContent>
+ <xs:extension base="linkIdentitiesResponseType">
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="removeLinkResponseType">
+ <xs:complexContent>
+ <xs:extension base="linkIdentitiesResponseType">
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+
+ <xs:complexType name="removeIdentityResponseType">
+ <xs:sequence>
+ <xs:element name="owningPlatform" type="xs:string"
+ minOccurs="1" maxOccurs="1" nillable="false" />
+ </xs:sequence>
+ </xs:complexType>
+
+
+ <xs:complexType name="linkIdentitiesType">
+ <xs:sequence>
+ <xs:element name="owningPlatform" type="xs:string"
+ minOccurs="1" maxOccurs="1" nillable="false" />
+ </xs:sequence>
+ </xs:complexType>
+
+
+ <xs:complexType name="linkIdentitiesGuidResponseType">
+ <xs:sequence>
+ <xs:element name="owningPlatform" type="xs:string"
+ minOccurs="1" maxOccurs="1" nillable="false" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="multipleLinkIdentitiesType">
+ <xs:sequence>
+ <xs:element name="multipleIdentityLink" type="linkIdentitiesType"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="multipleLinkIdentitiesGuidResponseType">
+ <xs:sequence>
+ <xs:element name="multipleLinkIdentitiesGuidResponse"
+ type="linkIdentitiesGuidResponseType" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:complexType>
+
+
+ <xs:element name="LinkIdentities" type="linkIdentitiesType" />
+ <xs:element name="LinkIdentitiesResponse" type="linkIdentitiesResponseType" />
+ <xs:element name="ModifyLink" type="linkIdentitiesType" />
+ <xs:element name="ModifyLinkResponse" type="modifyLinkResponseType" />
+
+ <xs:element name="RemoveLink" type="linkIdentitiesType" />
+ <xs:element name="RemoveLinkResponse" type="removeLinkResponseType" />
+
+</xs:schema>