Package org.apache.camel

Examples of org.apache.camel.TypeConverter.convertTo()


                        }
                        s = new DOMSource(d.getDocumentElement());
                        payload.getBodySources().set(0, s);
                    }
                   
                    T t = tc.convertTo(type, s);
                    if (t instanceof Document) {
                        payload.getBodySources().set(0, new DOMSource(((Document)t).getDocumentElement()));
                    } else if (t instanceof Source) {
                        payload.getBodySources().set(0, (Source)t);
                    }
View Full Code Here


                    return t;
                }               
            }
            TypeConverter tc = registry.lookup(type, NodeList.class);
            if (tc != null) {
                Object result = tc.convertTo(type, cxfPayloadToNodeList((CxfPayload<?>) value, exchange));
                if (result == null) {
                    // no we could not do it currently, and we just abort the convert here
                    return (T) Void.TYPE;
                } else {
                    return (T) result;
View Full Code Here

            // node list
            tc = registry.lookup(type, Node.class);
            if (tc != null) {
                NodeList nodeList = cxfPayloadToNodeList((CxfPayload<?>) value, exchange);
                if (nodeList.getLength() > 0) {
                    return tc.convertTo(type, nodeList.item(0));
                } else {
                    // no we could not do it currently
                    return (T) Void.TYPE;
                }
            }
View Full Code Here

        TypeConverter tc = registry.lookup(via, value.getClass());
        if (tc != null) {
            TypeConverter tc1 = registry.lookup(Document.class, via);
            if (tc1 != null) {
                V is = tc.convertTo(via, exchange, value);
                Document document = tc1.convertTo(Document.class, exchange, is);
                return documentToCxfPayload(document, exchange);
            }
        }
        return null;
    }
View Full Code Here

            return new StreamSource((InputStream)body);
        }
        if (body != null) {
            TypeConverter tc = exchange.getContext().getTypeConverterRegistry().lookup(Source.class, body.getClass());
            if (tc != null) {
                source = tc.convertTo(Source.class, body);
            }
        }

        if (source == null && isAllowStAX()) {
            source = exchange.getContext().getTypeConverter().tryConvertTo(StAXSource.class, exchange, body);
View Full Code Here

            log.trace("Using converter: {} to convert {}", converter, key);
            Object rc;
            if (tryConvert) {
                rc = converter.tryConvertTo(type, exchange, value);
            } else {
                rc = converter.convertTo(type, exchange, value);
            }
            if (rc != null) {
                return rc;
            }
        }
View Full Code Here

                    addTypeConverter(type, fromType, tc);
                    Object rc;
                    if (tryConvert) {
                        rc = tc.tryConvertTo(primitiveType, exchange, value);
                    } else {
                        rc = tc.convertTo(primitiveType, exchange, value);
                    }
                    if (rc != null) {
                        return rc;
                    }
                }
View Full Code Here

            TypeConverter tc = fallback.getFallbackTypeConverter();
            Object rc;
            if (tryConvert) {
                rc = tc.tryConvertTo(type, exchange, value);
            } else {
                rc = tc.convertTo(type, exchange, value);
            }

            if (Void.TYPE.equals(rc)) {
                // it cannot be converted so give up
                return Void.TYPE;
View Full Code Here

    public static <T> T convertToType(Exchange exchange, Class<T> type, Object value) throws TypeConversionException {
        CamelContext camelContext = exchange.getContext();
        ObjectHelper.notNull(camelContext, "CamelContext of Exchange");
        TypeConverter converter = camelContext.getTypeConverter();
        if (converter != null) {
            return converter.convertTo(type, exchange, value);
        }
        return null;
    }

    /**
 
View Full Code Here

            TypeConverter converter = e.getContext().getTypeConverter();

            // lets first try converting the body itself first
            // as for some types like InputStream v Reader its more efficient to do the transformation
            // from the body itself as its got efficient implementations of them, before trying the message
            T answer = converter.convertTo(type, e, body);
            if (answer != null) {
                return answer;
            }

            // fallback and try the message itself (e.g. used in camel-http)
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.