You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/05/14 17:09:38 UTC

svn commit: r774803 - in /cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf: attachment/LazyAttachmentCollection.java databinding/source/XMLStreamDataReader.java

Author: dkulp
Date: Thu May 14 15:09:38 2009
New Revision: 774803

URL: http://svn.apache.org/viewvc?rev=774803&view=rev
Log:
Pull some minor fixes for issues found while doing the Provider refactor

Modified:
    cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
    cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java

Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java?rev=774803&r1=774802&r2=774803&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java (original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java Thu May 14 15:09:38 2009
@@ -122,6 +122,9 @@
     }
 
     public boolean isEmpty() {
+        if (attachments.isEmpty()) {
+            return !iterator().hasNext();
+        }
         return attachments.isEmpty();
     }
 

Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=774803&r1=774802&r2=774803&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java (original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java Thu May 14 15:09:38 2009
@@ -19,9 +19,12 @@
 package org.apache.cxf.databinding.source;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Collection;
 import java.util.logging.Logger;
 
+import javax.activation.DataSource;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -52,19 +55,11 @@
         return read(null, input, part.getTypeClass());
     }
 
-    public Object read(QName name, XMLStreamReader input, Class type) {
+    public Object read(final QName name, XMLStreamReader input, Class type) {
         if (type != null) {
             if (SAXSource.class.isAssignableFrom(type)) {
                 try {
-                    CachedOutputStream out = new CachedOutputStream();
-                    try {
-                        XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
-                        StaxUtils.copy(input, xsw);
-                        xsw.close();
-                        return new SAXSource(new InputSource(out.getInputStream()));
-                    } finally {
-                        out.close();
-                    }
+                    return new SAXSource(new InputSource(getInputStream(input)));
                 } catch (IOException e) {
                     throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
                 } catch (XMLStreamException e) {
@@ -72,25 +67,51 @@
                 }
             } else if (StreamSource.class.isAssignableFrom(type)) {
                 try {
-                    CachedOutputStream out = new CachedOutputStream();
-                    try {
-                        XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
-                        StaxUtils.copy(input, xsw);
-                        xsw.close();
-                        return new StreamSource(out.getInputStream());
-                    } finally {
-                        out.close();
-                    }
+                    return new StreamSource(getInputStream(input));
                 } catch (IOException e) {
                     throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
                 } catch (XMLStreamException e) {
                     throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
                 }
-            } 
+            } else if (DataSource.class.isAssignableFrom(type)) {
+                try {
+                    final InputStream ins = getInputStream(input);
+                    return new DataSource() {
+                        public String getContentType() {
+                            return "text/xml";
+                        }
+                        public InputStream getInputStream() throws IOException {
+                            return ins;
+                        }
+                        public String getName() {
+                            return name.toString();
+                        }
+                        public OutputStream getOutputStream() throws IOException {
+                            return null;
+                        }
+                    };
+                } catch (IOException e) {
+                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
+                } catch (XMLStreamException e) {
+                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
+                }                
+            }
         }
         return read(input);
     }
-
+    private InputStream getInputStream(XMLStreamReader input) 
+        throws XMLStreamException, IOException {
+        
+        CachedOutputStream out = new CachedOutputStream();
+        try {
+            XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
+            StaxUtils.copy(input, xsw);
+            xsw.close();
+            return out.getInputStream();
+        } finally {
+            out.close();
+        }
+    }
     public Object read(XMLStreamReader reader) {
         // Use a DOMSource for now, we should really use a StaxSource/SAXSource though for 
         // performance reasons