cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r546903 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/databinding/ rt/core/src/main/java/org/apache/cxf/databinding/source/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/databinding/aegis/src/main/java/org/apache/cxf/ae...
Date Wed, 13 Jun 2007 15:04:19 GMT
Author: dandiep
Date: Wed Jun 13 08:03:45 2007
New Revision: 546903

URL: http://svn.apache.org/viewvc?view=rev&rev=546903
Log:
Add an option to set the encoding on the datawriter. I'm wondering if 
maybe we should extend this to a more generic interface, i.e.:

DataWriter.setProperty(DataWriter.ENCODING, encoding);

That requires yet another map and yet another property transfer though.
Thoughts?


Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataWriter.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java Wed Jun
13 08:03:45 2007
@@ -31,4 +31,5 @@
     void write(Object obj, MessagePartInfo part, T output);
     void setSchema(Schema s);
     void setAttachments(Collection<Attachment> attachments);
+    void setEncoding(String encoding);
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataWriter.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataWriter.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataWriter.java
Wed Jun 13 08:03:45 2007
@@ -43,6 +43,8 @@
 public class NodeDataWriter implements DataWriter<Node> {
     private static final Logger LOG = LogUtils.getL7dLogger(NodeDataWriter.class);
 
+    private String encoding;
+    
     public void write(Object obj, MessagePartInfo part, Node output) {
         write(obj, output);
     }
@@ -68,7 +70,14 @@
     }
 
     public void setAttachments(Collection<Attachment> attachments) {
-        // TODO Auto-generated method stub
-        
+ 
     }
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+    
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
Wed Jun 13 08:03:45 2007
@@ -39,6 +39,8 @@
 public class XMLStreamDataWriter implements DataWriter<XMLStreamWriter> {
     private static final Logger LOG = LogUtils.getL7dLogger(XMLStreamDataWriter.class);
 
+    private String encoding;
+    
     public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
         write(obj, output);
     }
@@ -63,7 +65,15 @@
     }
 
     public void setAttachments(Collection<Attachment> attachments) {
-        // TODO Auto-generated method stub
-        
+
+    }
+    
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
     }
+    
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
Wed Jun 13 08:03:45 2007
@@ -81,6 +81,7 @@
             }
             
             DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
+            osWriter.setEncoding((String)message.get(Message.ENCODING));
             
             for (MessagePartInfo part : parts) {
                 int idx = part.getMessageInfo().getMessagePartIndex(part);

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
Wed Jun 13 08:03:45 2007
@@ -60,16 +60,7 @@
         // assert os != null;
 
         // TODO: where does encoding constant go?
-        String encoding = (String)message.get(Message.ENCODING);
-        if (encoding == null && message.getExchange().getInMessage() != null) {
-            encoding = (String) message.getExchange().getInMessage().get(Message.ENCODING);
-            message.put(Message.ENCODING, encoding);
-        }
-        
-        if (encoding == null) {
-            encoding = "UTF-8";
-            message.put(Message.ENCODING, encoding);
-        }
+        String encoding = getEncoding(message);
         
         try {
             writer = getXMLOutputFactory(message).createXMLStreamWriter(os, encoding);
@@ -80,6 +71,20 @@
 
         // Add a final interceptor to write end elements
         message.getInterceptorChain().add(ending);
+    }
+
+    private String getEncoding(Message message) {
+        String encoding = (String)message.get(Message.ENCODING);
+        if (encoding == null && message.getExchange().getInMessage() != null) {
+            encoding = (String) message.getExchange().getInMessage().get(Message.ENCODING);
+            message.put(Message.ENCODING, encoding);
+        }
+        
+        if (encoding == null) {
+            encoding = "UTF-8";
+            message.put(Message.ENCODING, encoding);
+        }
+        return encoding;
     }
 
     public static XMLOutputFactory getXMLOutputFactory(Message m) throws Fault {

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
Wed Jun 13 08:03:45 2007
@@ -44,7 +44,9 @@
     private AegisDatabinding databinding;
 
     private Collection<Attachment> attachments;
-
+    
+    private String encoding;
+    
     public XMLStreamDataWriter(AegisDatabinding databinding) {
         this.databinding = databinding;
     }
@@ -96,4 +98,12 @@
         write(obj, null, output);
     }
 
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+    
 }

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
Wed Jun 13 08:03:45 2007
@@ -81,7 +81,7 @@
                                 Object elValue, 
                                 MessagePartInfo part,
                                 Object source, 
-                                AttachmentMarshaller am) {
+                                AttachmentMarshaller am, String encoding) {
         Class<?> cls = null;
         if (part != null) {
             cls = part.getTypeClass();
@@ -103,6 +103,10 @@
                 // generate the xml declaration.
                 u.setProperty(Marshaller.JAXB_FRAGMENT, true);
                 u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
+                
+                if (encoding != null) {
+                    u.setProperty(Marshaller.JAXB_ENCODING, encoding);
+                }
             } catch (javax.xml.bind.PropertyException e) {
                 // intentionally empty.
             }
@@ -158,14 +162,14 @@
     }
 
     public static void marshall(JAXBContext context, Schema schema, Object elValue, Object
source) {
-        marshall(context, schema, elValue, null, source, null);
+        marshall(context, schema, elValue, null, source, null, null);
     }
 
     public static void marshall(JAXBContext context, Schema schema, 
                                 Object elValue, 
                                 MessagePartInfo part,
                                 Object source) {
-        marshall(context, schema, elValue, part, source, null);
+        marshall(context, schema, elValue, part, source, null, null);
     }
 
     private static Unmarshaller createUnmarshaller(JAXBContext context, Class<?> cls)
throws JAXBException {

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?view=diff&rev=546903&r1=546902&r2=546903
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Wed Jun 13 08:03:45 2007
@@ -27,7 +27,8 @@
 import org.apache.cxf.service.model.MessagePartInfo;
 
 public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T>
{
-
+    private String encoding;
+    
     public DataWriterImpl(JAXBContext ctx) {
         setJAXBContext(ctx);
     }
@@ -39,7 +40,16 @@
     public void write(Object obj, MessagePartInfo part, T output) {
         if (obj != null) {
             JAXBEncoderDecoder.marshall(getJAXBContext(), getSchema(), obj, part, output,

-                                        getAttachmentMarrshaller());
+                                        getAttachmentMarrshaller(), encoding);
         }
     }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+    
 }



Mime
View raw message