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/09/28 10:07:20 UTC
svn commit: r580248 - in
/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel:
impl/ReflectionInjector.java util/ObjectHelper.java
Author: jstrachan
Date: Fri Sep 28 01:07:20 2007
New Revision: 580248
URL: http://svn.apache.org/viewvc?rev=580248&view=rev
Log:
minor patch to add a handy newInstance() method to create an object from a class
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReflectionInjector.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReflectionInjector.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReflectionInjector.java?rev=580248&r1=580247&r2=580248&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReflectionInjector.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReflectionInjector.java Fri Sep 28 01:07:20 2007
@@ -18,6 +18,7 @@
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Injector;
+import org.apache.camel.util.ObjectHelper;
/**
* A simple implementation of {@link Injector} which just uses reflection to
@@ -29,12 +30,6 @@
public class ReflectionInjector implements Injector {
public <T> T newInstance(Class<T> type) {
- try {
- return type.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeCamelException(e.getCause());
- } catch (IllegalAccessException e) {
- throw new RuntimeCamelException(e);
- }
+ return ObjectHelper.newInstance(type);
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=580248&r1=580247&r2=580248&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Fri Sep 28 01:07:20 2007
@@ -446,4 +446,17 @@
throw new IllegalArgumentException("Failed to convert: " + value + " to type: " + toType.getName() + " due to: " + e, e);
}
}
+
+ /**
+ * A helper method to create a new instance of a type using the default constructor arguments.
+ */
+ public static <T> T newInstance(Class<T> type) {
+ try {
+ return type.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeCamelException(e.getCause());
+ } catch (IllegalAccessException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
}