001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.cxf;
018
019 import java.util.List;
020
021 import javax.xml.transform.TransformerException;
022
023 import org.w3c.dom.Element;
024
025 import org.apache.camel.converter.jaxp.XmlConverter;
026
027
028 /**
029 * CxfMessage body type when {@link DataFormat#PAYLOAD} is used.
030 *
031 * @version $Revision: 19329 $
032 */
033 public class CxfPayload<T> {
034
035 private List<Element> body;
036 private List<T> headers;
037
038 public CxfPayload(List<T> headers, List<Element> body) {
039 this.headers = headers;
040 this.body = body;
041 }
042
043 public List<Element> getBody() {
044 return body;
045 }
046
047 public List<T> getHeaders() {
048 return headers;
049 }
050
051 public String toString() {
052 XmlConverter converter = new XmlConverter();
053 StringBuilder buf = new StringBuilder();
054 buf.append(getClass().getName());
055 buf.append(" headers: " + headers);
056 // go through the list of element and turn it into String
057 if (body == null) {
058 buf.append("body: " + body);
059 } else {
060 buf.append("body: [ ");
061 for (Element element : body) {
062 String elementString = "";
063 try {
064 elementString = converter.toString(element, null);
065 } catch (TransformerException e) {
066 elementString = element.toString();
067 }
068 buf.append("[" + elementString + "]");
069 }
070 buf.append("]");
071 }
072 return buf.toString();
073 }
074
075 }