You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/10/17 05:28:53 UTC

svn commit: r1184987 - /camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java

Author: dkulp
Date: Mon Oct 17 03:28:53 2011
New Revision: 1184987

URL: http://svn.apache.org/viewvc?rev=1184987&view=rev
Log:
Use an AbstractList subclass so the returned list is "live" and also
only un-streams if the appropriate "get" is called.

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java?rev=1184987&r1=1184986&r2=1184987&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java Mon Oct 17 03:28:53 2011
@@ -16,11 +16,14 @@
  */
 package org.apache.camel.component.cxf;
 
+import java.util.AbstractList;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
 import javax.xml.XMLConstants;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.dom.DOMSource;
@@ -62,19 +65,49 @@ public class CxfPayload<T> {
      * @return
      */
     public List<Element> getBody() {
-        List<Element> els = new ArrayList<Element>();
-        for (int x = 0; x < body.size(); x++) {
-            Source s = body.get(x);
-            try {
-                Element el = StaxUtils.read(s).getDocumentElement();
-                addNamespace(el, nsMap);
-                els.add(el);
-                body.set(x, new DOMSource(el));
-            } catch (Exception ex) {
-                throw new RuntimeCamelException("Problem converting content to Element", ex);
+        return new AbstractList<Element>() {
+            public boolean add(Element e) {
+                return body.add(new DOMSource(e));
             }
-        }
-        return els;
+
+            public Element set(int index, Element element) {
+                Source s = body.set(index, new DOMSource(element));
+                try {
+                    return StaxUtils.read(s).getDocumentElement();
+                } catch (XMLStreamException e) {
+                    throw new RuntimeCamelException("Problem converting content to Element", e);
+                }
+            }
+
+            public void add(int index, Element element) {
+                body.add(index, new DOMSource(element));
+            }
+
+            public Element remove(int index) {
+                Source s = body.remove(index);
+                try {
+                    return StaxUtils.read(s).getDocumentElement();
+                } catch (XMLStreamException e) {
+                    throw new RuntimeCamelException("Problem converting content to Element", e);
+                }
+            }
+
+            public Element get(int index) {
+                Source s = body.get(index);
+                try {
+                    Element el = StaxUtils.read(s).getDocumentElement();
+                    addNamespace(el, nsMap);
+                    body.set(index, new DOMSource(el));
+                    return el;
+                } catch (Exception ex) {
+                    throw new RuntimeCamelException("Problem converting content to Element", ex);
+                }
+            }
+
+            public int size() {
+                return body.size();
+            }
+        };
     }
     
     protected static void addNamespace(Element element, Map<String, String> nsMap) {