incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r833550 - in /incubator/wink/trunk/wink-common/src: main/java/org/apache/wink/common/internal/providers/entity/xml/ test/java/org/apache/wink/common/internal/providers/jaxb/ test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/
Date Fri, 06 Nov 2009 20:38:43 GMT
Author: rott
Date: Fri Nov  6 20:38:43 2009
New Revision: 833550

URL: http://svn.apache.org/viewvc?rev=833550&view=rev
Log:
WINK-229: tolerate user's JAXBContext resolver

Added:
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/ProvidersJAXBTest.java
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/AddNumbers.java
  (with props)
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/ObjectFactory.java
  (with props)
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/package-info.java
  (with props)
Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java?rev=833550&r1=833549&r2=833550&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java
Fri Nov  6 20:38:43 2009
@@ -35,6 +35,7 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
@@ -71,11 +72,21 @@
         try {
             JAXBContext context = getContext(type, mediaType);
             unmarshaller = getJAXBUnmarshaller(context);
-            if (type.isAnnotationPresent(XmlRootElement.class))
+            if (type.isAnnotationPresent(XmlRootElement.class)) {
                 unmarshaledResource = unmarshaller.unmarshal(entityStream);
-            else
+                if (unmarshaledResource instanceof JAXBElement) {
+                    // this can happen if the JAXBContext object used to create the unmarshaller
+                    // was created using the package name string instead of a class object
and the
+                    // ObjectFactory has a creator method for the desired object that returns
+                    // JAXBElement.  But we know better; the 'type' param passed in here
had the
+                    // XmlRootElement on it, so we know the desired return object type is
NOT
+                    // JAXBElement, thus:
+                    unmarshaledResource = ((JAXBElement)unmarshaledResource).getValue();
+                }
+            } else {
                 unmarshaledResource =
                     unmarshaller.unmarshal(new StreamSource(entityStream), type).getValue();
+            }
 
             releaseJAXBUnmarshaller(context, unmarshaller);
         } catch (JAXBException e) {

Added: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/ProvidersJAXBTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/ProvidersJAXBTest.java?rev=833550&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/ProvidersJAXBTest.java
(added)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/ProvidersJAXBTest.java
Fri Nov  6 20:38:43 2009
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.wink.common.internal.providers.jaxb;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.wink.common.internal.providers.entity.xml.JAXBXmlProvider;
+import org.apache.wink.common.internal.providers.jaxb.jaxb1.AddNumbers;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ProvidersJAXBTest {
+    
+    public class MyJAXBXmlProvider extends JAXBXmlProvider {
+
+        /* 
+         * simulate what would happen if application had supplied a JAXBContext provider
+         */
+        @Override
+        protected JAXBContext getContext(Class<?> type, MediaType mediaType)
+                throws JAXBException {
+            // use JAXBContext.newInstance(String).  The default in AbstractJAXBProvider
is JAXBContext.newInstance(Class)
+            return JAXBContext.newInstance(type.getPackage().getName());
+        }
+        
+    }
+    
+    static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+
+        "<ns2:addNumbers xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">"
+
+        "<arg0>1</arg0>" +
+        "<arg1>2</arg1>" +
+        "</ns2:addNumbers>";
+    
+    private MessageBodyReader jaxbProvider = null;
+    
+    @Before
+    public void setUp() {
+        jaxbProvider = new MyJAXBXmlProvider();
+    }
+    
+    @Test
+    public void testJAXBUnmarshallingWithAlternateContext1() throws Exception {
+        assertTrue(jaxbProvider.isReadable(AddNumbers.class, null, null, MediaType.TEXT_XML_TYPE));
+        ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+        Object obj = jaxbProvider.readFrom(AddNumbers.class, null, null, MediaType.TEXT_XML_TYPE,
null, bais);
+        assertTrue(obj instanceof AddNumbers);
+    }
+    
+}

Added: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/AddNumbers.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/AddNumbers.java?rev=833550&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/AddNumbers.java
(added)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/AddNumbers.java
Fri Nov  6 20:38:43 2009
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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.
+ *  
+ *******************************************************************************/
+
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation,
vhudson-jaxb-ri-2.1-558 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>

+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.08.20 at 04:05:47 PM CDT 
+//
+
+
+package org.apache.wink.common.internal.providers.jaxb.jaxb1;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for anonymous complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within
this class.
+ * 
+ * <pre>
+ * &lt;complexType>
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="arg0" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *         &lt;element name="arg1" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *       &lt;/sequence>
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+    "arg0",
+    "arg1"
+})
+@XmlRootElement(name = "addNumbers")
+public class AddNumbers {
+
+    protected int arg0;
+    protected int arg1;
+
+    /**
+     * Gets the value of the arg0 property.
+     * 
+     */
+    public int getArg0() {
+        return arg0;
+    }
+
+    /**
+     * Sets the value of the arg0 property.
+     * 
+     */
+    public void setArg0(int value) {
+        this.arg0 = value;
+    }
+
+    /**
+     * Gets the value of the arg1 property.
+     * 
+     */
+    public int getArg1() {
+        return arg1;
+    }
+
+    /**
+     * Sets the value of the arg1 property.
+     * 
+     */
+    public void setArg1(int value) {
+        this.arg1 = value;
+    }
+
+}

Propchange: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/AddNumbers.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/ObjectFactory.java?rev=833550&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/ObjectFactory.java
(added)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/ObjectFactory.java
Fri Nov  6 20:38:43 2009
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.
+ *  
+ *******************************************************************************/
+
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation,
vhudson-jaxb-ri-2.1-558 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>

+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.08.20 at 04:05:47 PM CDT 
+//
+
+
+package org.apache.wink.common.internal.providers.jaxb.jaxb1;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlElementDecl;
+import javax.xml.bind.annotation.XmlRegistry;
+import javax.xml.namespace.QName;
+
+
+/**
+ * This object contains factory methods for each 
+ * Java content interface and Java element interface 
+ * generated in the org.apache.wink.common.internal.providers.jaxb.jaxb1 package. 
+ * <p>An ObjectFactory allows you to programatically 
+ * construct new instances of the Java representation 
+ * for XML content. The Java representation of XML 
+ * content can consist of schema derived interfaces 
+ * and classes representing the binding of schema 
+ * type definitions, element declarations and model 
+ * groups.  Factory methods for each of these are 
+ * provided in this class.
+ * 
+ */
+@XmlRegistry
+public class ObjectFactory {
+
+    private final static QName _AddNumbers_QNAME = new QName("http://org/apache/wink/common/internal/providers/jaxb/jaxb1",
"addNumbers");
+
+    /**
+     * Create a new ObjectFactory that can be used to create new instances of schema derived
classes for package: org.apache.wink.common.internal.providers.jaxb.jaxb1
+     * 
+     */
+    public ObjectFactory() {
+    }
+
+    /**
+     * Create an instance of {@link AddNumbers }
+     * 
+     */
+    public AddNumbers createAddNumbers() {
+        return new AddNumbers();
+    }
+    
+    /**
+     * Create an instance of {@link JAXBElement }{@code <}{@link AddNumbers }{@code >}}
+     * 
+     */
+    @XmlElementDecl(namespace = "http://org/apache/wink/common/internal/providers/jaxb/jaxb1",
name = "addNumbers")
+    public JAXBElement<AddNumbers> createAddNumbers(AddNumbers value) {
+        return new JAXBElement<AddNumbers>(_AddNumbers_QNAME, AddNumbers.class, null,
value);
+    }
+
+
+}

Propchange: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/ObjectFactory.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/package-info.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/package-info.java?rev=833550&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/package-info.java
(added)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/package-info.java
Fri Nov  6 20:38:43 2009
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.
+ *  
+ *******************************************************************************/
+
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation,
vhudson-jaxb-ri-2.1-558 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>

+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.08.20 at 04:05:47 PM CDT 
+//
+
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://org/apache/wink/common/internal/providers/jaxb",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.wink.common.internal.providers.jaxb.jaxb1;

Propchange: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/package-info.java
------------------------------------------------------------------------------
    svn:mergeinfo = 



Mime
View raw message