Author: davsclaus Date: Mon Apr 23 04:47:46 2012 New Revision: 1329062 URL: http://svn.apache.org/viewvc?rev=1329062&view=rev Log: CAMEL-5171: Favor static methods for type converters
Modified: camel/branches/camel-2.9.x/ (props changed) camel/branches/camel-2.9.x/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java camel/branches/camel-2.9.x/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java camel/branches/camel-2.9.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java camel/branches/camel-2.9.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/converter/RestletConverter.java camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1328885 Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.9.x/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java Mon Apr 23 04:47:46 2012 @@ -89,7 +89,7 @@ public final class ExecResultConverter { * the file can not be found */ @SuppressWarnings("unchecked") - public static <T> T convertTo(Class<T> type, Exchange exchange, ExecResult result) throws FileNotFoundException { + private static <T> T convertTo(Class<T> type, Exchange exchange, ExecResult result) throws FileNotFoundException { InputStream is = toInputStream(result); if (is != null) { return exchange.getContext().getTypeConverter().convertTo(type, exchange, is); @@ -118,7 +118,7 @@ public final class ExecResultConverter { * not be opened. In this case the out file must have had a not * <code>null</code> value */ - public static InputStream toInputStream(ExecResult execResult) throws FileNotFoundException { + private static InputStream toInputStream(ExecResult execResult) throws FileNotFoundException { if (execResult == null) { LOG.warn("Received a null ExecResult instance to convert!"); return null; Modified: camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java Mon Apr 23 04:47:46 2012 @@ -56,8 +56,6 @@ public final class HttpConverter { } return message.getHeader(Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class); } - - @Converter public static ServletInputStream toServletInputStream(HttpMessage message) throws IOException { Modified: camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java Mon Apr 23 04:47:46 2012 @@ -31,20 +31,23 @@ import org.apache.commons.httpclient.met * Some converter methods to make it easier to convert the body to RequestEntity types. */ @Converter -public class RequestEntityConverter { +public final class RequestEntityConverter { + + private RequestEntityConverter() { + } @Converter - public RequestEntity toRequestEntity(byte[] data, Exchange exchange) throws Exception { + public static RequestEntity toRequestEntity(byte[] data, Exchange exchange) throws Exception { return asRequestEntity(data, exchange); } @Converter - public RequestEntity toRequestEntity(InputStream inStream, Exchange exchange) throws Exception { + public static RequestEntity toRequestEntity(InputStream inStream, Exchange exchange) throws Exception { return asRequestEntity(inStream, exchange); } @Converter - public RequestEntity toRequestEntity(String str, Exchange exchange) throws Exception { + public static RequestEntity toRequestEntity(String str, Exchange exchange) throws Exception { if (GZIPHelper.isGzip(exchange.getIn())) { byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, str); return asRequestEntity(data, exchange); @@ -54,7 +57,7 @@ public class RequestEntityConverter { } } - private RequestEntity asRequestEntity(InputStream in, Exchange exchange) throws IOException { + private static RequestEntity asRequestEntity(InputStream in, Exchange exchange) throws IOException { if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { return new InputStreamRequestEntity(GZIPHelper.compressGzip(exchange.getIn() @@ -70,7 +73,7 @@ public class RequestEntityConverter { } } - private RequestEntity asRequestEntity(byte[] data, Exchange exchange) throws Exception { + private static RequestEntity asRequestEntity(byte[] data, Exchange exchange) throws Exception { if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { return new InputStreamRequestEntity(GZIPHelper.compressGzip(exchange.getIn() Modified: camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java Mon Apr 23 04:47:46 2012 @@ -56,8 +56,6 @@ public final class HttpConverter { } return message.getHeader(Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class); } - - @Converter public static ServletInputStream toServletInputStream(HttpMessage message) throws IOException { Modified: camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java Mon Apr 23 04:47:46 2012 @@ -31,20 +31,23 @@ import org.apache.http.entity.InputStrea * Some converter methods to make it easier to convert the body to RequestEntity types. */ @Converter -public class HttpEntityConverter { +public final class HttpEntityConverter { + + private HttpEntityConverter() { + } @Converter - public HttpEntity toHttpEntity(byte[] data, Exchange exchange) throws Exception { + public static HttpEntity toHttpEntity(byte[] data, Exchange exchange) throws Exception { return asHttpEntity(data, exchange); } @Converter - public HttpEntity toHttpEntity(InputStream inStream, Exchange exchange) throws Exception { + public static HttpEntity toHttpEntity(InputStream inStream, Exchange exchange) throws Exception { return asHttpEntity(inStream, exchange); } @Converter - public HttpEntity toHttpEntity(String str, Exchange exchange) throws Exception { + public static HttpEntity toHttpEntity(String str, Exchange exchange) throws Exception { if (GZIPHelper.isGzip(exchange.getIn())) { byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, str); return asHttpEntity(data, exchange); @@ -54,13 +57,12 @@ public class HttpEntityConverter { } } - private HttpEntity asHttpEntity(InputStream in, Exchange exchange) throws IOException { + private static HttpEntity asHttpEntity(InputStream in, Exchange exchange) throws IOException { String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class); String contentType = ExchangeHelper.getContentType(exchange); - InputStreamEntity entity = null; - if (exchange != null - && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { + InputStreamEntity entity; + if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { entity = new InputStreamEntity(GZIPHelper.compressGzip(contentEncoding, in), -1); } else { entity = new InputStreamEntity(in, -1); @@ -70,13 +72,12 @@ public class HttpEntityConverter { return entity; } - private HttpEntity asHttpEntity(byte[] data, Exchange exchange) throws Exception { + private static HttpEntity asHttpEntity(byte[] data, Exchange exchange) throws Exception { String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class); String contentType = ExchangeHelper.getContentType(exchange); - InputStreamEntity entity = null; - if (exchange != null - && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { + InputStreamEntity entity; + if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { entity = new InputStreamEntity(GZIPHelper.compressGzip(contentEncoding, data), -1); } else { entity = new InputStreamEntity(new ByteArrayInputStream(data), -1); Modified: camel/branches/camel-2.9.x/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java Mon Apr 23 04:47:46 2012 @@ -31,25 +31,28 @@ import org.apache.jackrabbit.value.Strin * A helper class to transform Object into JCR {@link Value} implementations */ @Converter -public class JcrConverter { +public final class JcrConverter { + + private JcrConverter() { + } @Converter - public Value toValue(Boolean bool) { + public static Value toValue(Boolean bool) { return new BooleanValue(bool); } @Converter - public Value toValue(InputStream stream) { + public static Value toValue(InputStream stream) { return new BinaryValue(stream); } @Converter - public Value toValue(Calendar calendar) { + public static Value toValue(Calendar calendar) { return new DateValue(calendar); } @Converter - public Value toValue(String value) { + public static Value toValue(String value) { return new StringValue(value); } Modified: camel/branches/camel-2.9.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java Mon Apr 23 04:47:46 2012 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.component.netty; import java.io.IOException; @@ -66,7 +65,6 @@ public final class NettyConverter { @Converter public static ChannelBuffer toByteBuffer(byte[] bytes) { ChannelBuffer buf = new DynamicChannelBuffer(bytes.length); - buf.writeBytes(bytes); return buf; } Modified: camel/branches/camel-2.9.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/converter/RestletConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/converter/RestletConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/converter/RestletConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/converter/RestletConverter.java Mon Apr 23 04:47:46 2012 @@ -28,16 +28,18 @@ import org.restlet.data.Method; * @version */ @Converter -public class RestletConverter { +public final class RestletConverter { + + private RestletConverter() { + } @Converter - public Method toMethod(String name) { + public static Method toMethod(String name) { return Method.valueOf(name.toUpperCase()); } @Converter - public Method[] toMethods(String name) { - + public static Method[] toMethods(String name) { String[] strings = name.split(","); List<Method> methods = new ArrayList<Method>(); for (String string : strings) { @@ -48,7 +50,7 @@ public class RestletConverter { } @Converter - public MediaType toMediaType(String name) { + public static MediaType toMediaType(String name) { return MediaType.valueOf(name); } Modified: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java?rev=1329062&r1=1329061&r2=1329062&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java (original) +++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java Mon Apr 23 04:47:46 2012 @@ -21,20 +21,15 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.nio.ByteBuffer; - -import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.xml.sax.SAXException; import org.apache.camel.Converter; import org.apache.camel.Exchange; +import org.apache.camel.NoTypeConversionAvailableException; import org.apache.camel.converter.IOConverter; import org.apache.camel.converter.NIOConverter; -import org.apache.camel.converter.jaxp.XmlConverter; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.impl.piccolo.xml.XMLStreamReader; @@ -46,8 +41,10 @@ import org.apache.xmlbeans.impl.piccolo. * @version */ @Converter -public class XmlBeansConverter { - private XmlConverter xmlConverter = new XmlConverter(); +public final class XmlBeansConverter { + + private XmlBeansConverter() { + } @Converter public static XmlObject toXmlObject(File value) throws IOException, XmlException { @@ -90,18 +87,9 @@ public class XmlBeansConverter { } @Converter - public XmlObject toXmlObject(Source value) throws IOException, XmlException, TransformerException, ParserConfigurationException, SAXException { - Document document = getXmlConverter().toDOMDocument(value); - return toXmlObject(document); + public XmlObject toXmlObject(Source value, Exchange exchange) throws IOException, XmlException, NoTypeConversionAvailableException { + Reader reader = exchange.getContext().getTypeConverter().mandatoryConvertTo(Reader.class, value); + return XmlObject.Factory.parse(reader); } - // Properties - //------------------------------------------------------------------------- - public XmlConverter getXmlConverter() { - return xmlConverter; - } - - public void setXmlConverter(XmlConverter xmlConverter) { - this.xmlConverter = xmlConverter; - } }