You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/10/08 18:21:24 UTC
svn commit: r582864 -
/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
Author: jstrachan
Date: Mon Oct 8 09:21:23 2007
New Revision: 582864
URL: http://svn.apache.org/viewvc?rev=582864&view=rev
Log:
added a few helper methods
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=582864&r1=582863&r2=582864&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java Mon Oct 8 09:21:23 2007
@@ -19,6 +19,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.NoSuchEndpointException;
+import static org.apache.camel.util.ObjectHelper.notNull;
/**
* A number of helper methods
@@ -49,6 +50,25 @@
} else {
return endpoint;
}
+ }
+
+ /**
+ * Converts the given value to the requested type
+ */
+ public static <T> T convertTo(CamelContext context, Class<T> type, Object value) {
+ notNull(context, "camelContext");
+ return context.getTypeConverter().convertTo(type, value);
+ }
+ /**
+ * Converts the given value to the specified type throwing an {@link IllegalArgumentException}
+ * if the value could not be converted to a non null value
+ */
+ public static <T> T mandatoryConvertTo(CamelContext context, Class<T> type, Object value) {
+ T answer = convertTo(context, type, value);
+ if (answer == null) {
+ throw new IllegalArgumentException("Value " + value + " converted to " + type.getName() + " cannot be null");
+ }
+ return answer;
}
}