cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5625] Introducing XSLTTransform annotation
Date Wed, 26 Mar 2014 13:58:58 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 9e87ede2d -> 51053aa2f


[CXF-5625] Introducing XSLTTransform annotation


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/51053aa2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/51053aa2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/51053aa2

Branch: refs/heads/master
Commit: 51053aa2fecbc9620b88f7d25e6f2319c7a4dc04
Parents: 9e87ede
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Mar 26 13:57:51 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Mar 26 13:57:51 2014 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/ext/xml/XSLTTransform.java |  43 +++++++
 .../cxf/jaxrs/provider/JAXBElementProvider.java |  47 ++++---
 .../cxf/jaxrs/provider/XSLTJaxbProvider.java    | 122 +++++++++++++++----
 .../jaxrs/provider/XSLTJaxbProviderTest.java    |  30 +++++
 4 files changed, 201 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/51053aa2/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XSLTTransform.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XSLTTransform.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XSLTTransform.java
new file mode 100644
index 0000000..a208ce8
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XSLTTransform.java
@@ -0,0 +1,43 @@
+/**
+ * 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.cxf.jaxrs.ext.xml;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Can be used to assign qualified XML names to arbitrary classes
+ * for the purpose of matching them with external schema definitions 
+ * 
+ */
+@Target({ElementType.METHOD, ElementType.PARAMETER })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface XSLTTransform {
+    /**
+     * Template location
+     */
+    String value();
+    /**
+     * Media types 
+     **/
+    String[] mediaTypes() default {"*/*" };
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/51053aa2/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
index 99e0be7..8ff1106 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
@@ -187,7 +187,7 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
                     response = unmarshaller.unmarshal(reader, theType);
                 }
             } else {
-                response = doUnmarshal(unmarshaller, type, is, mt);
+                response = doUnmarshal(unmarshaller, type, is, anns, mt);
             }
             if (response instanceof JAXBElement && !JAXBElement.class.isAssignableFrom(type))
{
                 response = ((JAXBElement<?>)response).getValue();    
@@ -221,12 +221,13 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
         return null;
     }
 
-    protected Object doUnmarshal(Unmarshaller unmarshaller, Class<?> type, InputStream
is, MediaType mt) 
+    protected Object doUnmarshal(Unmarshaller unmarshaller, Class<?> type, InputStream
is, 
+                                 Annotation[] anns, MediaType mt) 
         throws JAXBException {
         XMLStreamReader reader = getStreamReader(is, type, mt);
         if (reader != null) {
             try {
-                return unmarshalFromReader(unmarshaller, reader, mt);
+                return unmarshalFromReader(unmarshaller, reader, anns, mt);
             } catch (JAXBException e) {
                 throw e;
             } finally {
@@ -237,7 +238,7 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
                 }
             }
         }
-        return unmarshalFromInputStream(unmarshaller, is, mt);
+        return unmarshalFromInputStream(unmarshaller, is, anns, mt);
     }
     
     protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType
mt) {
@@ -269,7 +270,8 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
         
     }
     
-    protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,
MediaType mt) 
+    protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,

+                                              Annotation[] anns, MediaType mt) 
         throws JAXBException {
         // Try to create the read before unmarshalling the stream
         XMLStreamReader xmlReader = null;
@@ -295,7 +297,8 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
         }
     }
     
-    protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,
MediaType mt) 
+    protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,

+                                         Annotation[] anns, MediaType mt) 
         throws JAXBException {
         return unmarshaller.unmarshal(reader);
     }
@@ -376,25 +379,26 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
             XmlJavaTypeAdapter adapter = 
                 org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns);
             marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true), 
-                                    actualClass, genericType, enc, os, m, 
+                                    actualClass, genericType, enc, os, anns, m, 
                                     qname.getNamespaceURI());
             while (it.hasNext()) {
                 marshalCollectionMember(JAXBUtils.useAdapter(it.next(), adapter, true), actualClass,

-                                        genericType, enc, os, m, 
+                                        genericType, enc, os, anns, m, 
                                         qname.getNamespaceURI());
             }
         }
         os.write(endTag.getBytes());
     }
-    
+    //CHECKSTYLE:OFF
     protected void marshalCollectionMember(Object obj, 
                                            Class<?> cls, 
                                            Type genericType, 
                                            String enc, 
-                                           OutputStream os, 
+                                           OutputStream os,
+                                           Annotation[] anns,
                                            MediaType mt, 
                                            String ns) throws Exception {
-        
+    //CHECKSTYLE:ON    
         if (obj instanceof JAXBElement) {
             obj = ((JAXBElement<?>)obj).getValue();    
         } else {
@@ -416,7 +420,7 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
             map.putAll(nsPrefixes);
             setNamespaceMapper(ms, map);
         }
-        marshal(obj, cls, genericType, enc, os, mt, ms);
+        marshal(obj, cls, genericType, enc, os, anns, mt, ms);
     }
     
     protected void marshal(Object obj, Class<?> cls, Type genericType, 
@@ -439,7 +443,7 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
         addAttachmentMarshaller(ms);
         addProcessingInstructions(ms, anns);
         addSchemaLocation(ms, anns);
-        marshal(obj, cls, genericType, enc, os, mt, ms);
+        marshal(obj, cls, genericType, enc, os, anns, mt, ms);
     }
     
     private void addProcessingInstructions(Marshaller ms, Annotation[] anns) throws Exception
{
@@ -516,11 +520,12 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
             return null;
         }
     }
-    
+    //CHECKSTYLE:OFF
     protected void marshal(Object obj, Class<?> cls, Type genericType, 
-                           String enc, OutputStream os, MediaType mt, Marshaller ms)
+                           String enc, OutputStream os, 
+                           Annotation[] anns, MediaType mt, Marshaller ms)
         throws Exception {
-        
+    //CHECKSTYLE:ON    
         for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
             ms.setProperty(entry.getKey(), entry.getValue());
         }
@@ -546,12 +551,12 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
                 }
                 mc.put(XMLStreamWriter.class.getName(), writer);    
             }
-            marshalToWriter(ms, obj, writer, mt);
+            marshalToWriter(ms, obj, writer, anns, mt);
             if (mc != null) { 
                 writer.writeEndDocument();
             }
         } else {
-            marshalToOutputStream(ms, obj, os, mt);
+            marshalToOutputStream(ms, obj, os, anns, mt);
         }
     }
     
@@ -582,7 +587,8 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
         return createTransformWriterIfNeeded(writer, os, true);
     }
     
-    protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, MediaType
mt) 
+    protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, 
+                                         Annotation[] anns, MediaType mt) 
         throws Exception {
         if (os == null) {
             Writer writer = getStreamHandlerFromCurrentMessage(Writer.class);
@@ -597,7 +603,8 @@ public class JAXBElementProvider<T> extends AbstractJAXBProvider<T>
 {
         }
     }
     
-    protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer, MediaType
mt) 
+    protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer, 
+                                   Annotation[] anns, MediaType mt) 
         throws Exception {
         ms.marshal(obj, writer);
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/51053aa2/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
index 0a8fe45..993c251 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -60,11 +61,15 @@ import javax.xml.transform.stream.StreamSource;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLFilter;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.xml.XSLTTransform;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.staxutils.StaxSource;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -85,6 +90,8 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
     private Templates outTemplates;
     private Map<String, Templates> inMediaTemplates;
     private Map<String, Templates> outMediaTemplates;
+    private ConcurrentHashMap<String, Templates> annotationTemplates =
+        new ConcurrentHashMap<String, Templates>();
 
     private List<String> inClassesToHandle;
     private List<String> outClassesToHandle;
@@ -114,7 +121,7 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
         // if the user has set the list of in classes and a given class 
         // is in that list then it can only be handled by the template
         if (inClassCanBeHandled(type.getName()) || inClassesToHandle == null && !supportJaxbOnly)
{
-            return inTemplatesAvailable(mt); 
+            return inTemplatesAvailable(type, anns, mt); 
         } else {
             return supportJaxbOnly;
         }
@@ -133,42 +140,103 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
         // if the user has set the list of out classes and a given class 
         // is in that list then it can only be handled by the template
         if (outClassCanBeHandled(type.getName()) || outClassesToHandle == null &&
!supportJaxbOnly) {
-            return outTemplatesAvailable(mt); 
+            return outTemplatesAvailable(type, anns, mt); 
         } else {
             return supportJaxbOnly;
         }
     }
     
-    protected boolean inTemplatesAvailable(MediaType mt) {
+    protected boolean inTemplatesAvailable(Class<?> cls, Annotation[] anns, MediaType
mt) {
         return inTemplates != null 
             || inMediaTemplates != null && inMediaTemplates.containsKey(mt.getType()
+ "/" 
-                                                                        + mt.getSubtype());
+                                                                        + mt.getSubtype())
+            || getTemplatesFromAnnotation(cls, anns, mt) != null;
     }
     
-    protected boolean outTemplatesAvailable(MediaType mt) {
+    protected boolean outTemplatesAvailable(Class<?> cls, Annotation[] anns, MediaType
mt) {
         return outTemplates != null 
             || outMediaTemplates != null && outMediaTemplates.containsKey(mt.getType()

-                                                                          + "/" + mt.getSubtype());
+                                                                          + "/" + mt.getSubtype())
+            || getTemplatesFromAnnotation(cls, anns, mt) != null;
     }
     
-    protected Templates getInTemplates(MediaType mt) {
-        return inTemplates != null ? inTemplates 
+    protected Templates getTemplatesFromAnnotation(Class<?> cls,
+                                                   Annotation[] anns, 
+                                                   MediaType mt) {
+        Templates t = null;
+        XSLTTransform ann = getXsltTransformAnn(anns, mt);
+        if (ann != null) {
+            t = annotationTemplates.get(ann.value());
+            if (t == null) {
+                String path = ann.value();
+                final String cp = "classpath:";
+                if (!path.startsWith(cp)) {
+                    path = cp + path;
+                }
+                t = createTemplates(path);
+                if (t == null) {
+                    createTemplates(ClassLoaderUtils.getResourceAsStream(ann.value(), cls));
+                }
+                if (t != null) {
+                    annotationTemplates.putIfAbsent(ann.value(), t);
+                }
+            }
+        }
+        return t;
+        
+    }
+    
+    protected Templates getAnnotationTemplates(Annotation[] anns) {
+        Templates t = null;
+        XSLTTransform ann = AnnotationUtils.getAnnotation(anns, XSLTTransform.class);
+        if (ann != null) {
+            t = annotationTemplates.get(ann.value());
+        }
+        return t;
+        
+    }
+    
+    protected XSLTTransform getXsltTransformAnn(Annotation[] anns, MediaType mt) {
+        XSLTTransform ann = AnnotationUtils.getAnnotation(anns, XSLTTransform.class);
+        if (ann != null) {
+            for (String s : ann.mediaTypes()) {
+                if (mt.isCompatible(JAXRSUtils.toMediaType(s))) {
+                    return ann;
+                }
+            }
+        }
+        return null;
+    }
+    
+    
+    
+    protected Templates getInTemplates(Annotation[] anns, MediaType mt) {
+        Templates t = inTemplates != null ? inTemplates 
             : inMediaTemplates != null ? inMediaTemplates.get(mt.getType() + "/" + mt.getSubtype())
: null;
+        if (t == null) {    
+            t = getAnnotationTemplates(anns);
+        }
+        return t;
     }
     
-    protected Templates getOutTemplates(MediaType mt) {
-        return outTemplates != null ? outTemplates 
+    protected Templates getOutTemplates(Annotation[] anns, MediaType mt) {
+        Templates t = outTemplates != null ? outTemplates 
             : outMediaTemplates != null ? outMediaTemplates.get(mt.getType() + "/" + mt.getSubtype())
: null;
+        if (t == null) {    
+            t = getAnnotationTemplates(anns);
+        }
+        return t;    
     }
     
     @Override
-    protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,
MediaType mt) 
+    protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,

+                                              Annotation[] anns, MediaType mt) 
         throws JAXBException {
         try {
 
-            Templates t = createTemplates(getInTemplates(mt), inParamsMap, inProperties);
+            Templates t = createTemplates(getInTemplates(anns, mt), inParamsMap, inProperties);
             if (t == null && supportJaxbOnly) {
-                return super.unmarshalFromInputStream(unmarshaller, is, mt);
+                return super.unmarshalFromInputStream(unmarshaller, is, anns, mt);
             }
             XMLFilter filter = null;
             try {
@@ -208,7 +276,9 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
         }
     }
 
-    protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,
MediaType mt) 
+    @Override
+    protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,

+                                         Annotation[] anns, MediaType mt) 
         throws JAXBException {
         CachedOutputStream out = new CachedOutputStream();
         try {
@@ -217,17 +287,18 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
             writer.writeEndDocument();
             writer.flush();
             writer.close();
-            return unmarshalFromInputStream(unmarshaller, out.getInputStream(), mt);
+            return unmarshalFromInputStream(unmarshaller, out.getInputStream(), anns, mt);
         } catch (Exception ex) {
             throw ExceptionUtils.toBadRequestException(ex, null);
         }
     }
     
     @Override
-    protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer, MediaType
mt) 
+    protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer, 
+                                   Annotation[] anns, MediaType mt) 
         throws Exception {
         CachedOutputStream out = new CachedOutputStream();
-        marshalToOutputStream(ms, obj, out, mt);
+        marshalToOutputStream(ms, obj, out, anns, mt);
         
         StaxUtils.copy(new StreamSource(out.getInputStream()), writer);
     }
@@ -238,12 +309,13 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
     }
     
     @Override
-    protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, MediaType
mt)
+    protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, 
+                                         Annotation[] anns, MediaType mt)
         throws Exception {
         
-        Templates t = createTemplates(getOutTemplates(mt), outParamsMap, outProperties);
+        Templates t = createTemplates(getOutTemplates(anns, mt), outParamsMap, outProperties);
         if (t == null && supportJaxbOnly) {
-            super.marshalToOutputStream(ms, obj, os, mt);
+            super.marshalToOutputStream(ms, obj, os, anns, mt);
             return;
         }
         TransformerHandler th = null;
@@ -389,7 +461,15 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
     
     protected Templates createTemplates(String loc) {
         try {
-            InputStream is = ResourceUtils.getResourceStream(loc, this.getBus());
+            return createTemplates(ResourceUtils.getResourceStream(loc, this.getBus()));
+        } catch (Exception ex) {
+            LOG.warning("No template can be created : " + ex.getMessage());
+        }
+        return null;
+    }
+    
+    protected Templates createTemplates(InputStream is) {
+        try {
             if (is == null) {
                 return null;
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/51053aa2/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
index 5bdacbf..39b5c1e 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
@@ -23,9 +23,11 @@ import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.StringReader;
+import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.ws.rs.GET;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.Unmarshaller;
@@ -34,6 +36,7 @@ import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.ext.MessageContextImpl;
+import org.apache.cxf.jaxrs.ext.xml.XSLTTransform;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.SuperBook;
@@ -109,6 +112,25 @@ public class XSLTJaxbProviderTest extends Assert {
     }
     
     @Test
+    public void testWriteWithAnnotation() throws Exception {
+        XSLTJaxbProvider<Book> provider = new XSLTJaxbProvider<Book>();
+        provider.setMessageContext(new MessageContextImpl(createMessage()));
+        Book b = new Book();
+        b.setId(123L);
+        b.setName("TheBook");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        
+        Annotation[] anns = Root.class.getMethod("getBook").getAnnotations();
+        assertTrue(provider.isWriteable(Book.class, Book.class, anns, MediaType.TEXT_XML_TYPE));
+        provider.writeTo(b, Book.class, Book.class, anns,
+                         MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(),
bos);
+        Unmarshaller um = provider.getClassContext(Book.class).createUnmarshaller();
+        Book b2 = (Book)um.unmarshal(new StringReader(bos.toString()));
+        b.setName("TheBook2");
+        assertEquals("Transformation is bad", b, b2);
+    }
+    
+    @Test
     public void testWriteToStreamWriter() throws Exception {
         XSLTJaxbProvider<Book> provider = new XSLTJaxbProvider<Book>() {
             @Override
@@ -256,4 +278,12 @@ public class XSLTJaxbProviderTest extends Assert {
         e.put(Endpoint.class, endpoint);
         return m;
     }
+    
+    public static class Root {
+        @GET
+        @XSLTTransform(TEMPLATE_LOCATION)
+        public Book getBook() {
+            return new Book();
+        }
+    }
 }


Mime
View raw message