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/06/07 22:35:37 UTC
svn commit: r545303 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/ main/java/org/apache/camel/impl/
test/java/org/apache/camel/
Author: jstrachan
Date: Thu Jun 7 13:35:32 2007
New Revision: 545303
URL: http://svn.apache.org/viewvc?view=rev&rev=545303
Log:
added a helper method to make it a bit easier to grab a typesafe endpoint or component with less ugly casting
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?view=diff&rev=545303&r1=545302&r2=545303
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Jun 7 13:35:32 2007
@@ -37,16 +37,21 @@
//-----------------------------------------------------------------------
/**
- * Adds a component to the container.
+ * Adds a component to the context.
*/
void addComponent(String componentName, Component component);
/**
- * Gets a component from the container by name.
+ * Gets a component from the context by name.
*/
Component getComponent(String componentName);
/**
+ * Gets a component from the context by name and specifying the expected type of component.
+ */
+ <T extends Component> T getComponent(String name, Class<T> componentType);
+
+ /**
* Removes a previously added component.
*
* @param componentName
@@ -58,7 +63,7 @@
* Gets the a previously added component by name or lazily creates the component
* using the factory Callback.
*
- * @param componentName
+ * @param componentName the name of the component
* @param factory used to create a new component instance if the component was not previously added.
* @return
*/
@@ -73,6 +78,14 @@
* and if the endpoint is a singleton it is registered as a singleton endpoint.
*/
Endpoint getEndpoint(String uri);
+
+ /**
+ * Resolves the given URI to an {@see Endpoint} of the specified type.
+ * If the URI has a singleton endpoint registered, then the singleton is returned.
+ * Otherwise, a new {@see Endpoint} is created and if the endpoint is a
+ * singleton it is registered as a singleton endpoint.
+ */
+ <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType);
/**
* Returns the collection of all registered singleton endpoints.
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=545303&r1=545302&r2=545303
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu Jun 7 13:35:32 2007
@@ -100,6 +100,16 @@
}
}
+ public <T extends Component> T getComponent(String name, Class<T> componentType) {
+ Component component = getComponent(name);
+ if (componentType.isInstance(component)) {
+ return componentType.cast(component);
+ }
+ else {
+ throw new IllegalArgumentException("The component is not of type: " + componentType + " but is: " + component);
+ }
+ }
+
/**
* Removes a previously added component.
*
@@ -212,6 +222,18 @@
return answer;
}
+
+ public <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType) {
+ Endpoint endpoint = getEndpoint(name);
+ if (endpointType.isInstance(endpoint)) {
+ return endpointType.cast(endpoint);
+ }
+ else {
+ throw new IllegalArgumentException("The endpoint is not of type: " + endpointType + " but is: " + endpoint);
+ }
+ }
+
+
// Route Management Methods
//-----------------------------------------------------------------------
public List<Route> getRoutes() {
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?view=diff&rev=545303&r1=545302&r2=545303
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java Thu Jun 7 13:35:32 2007
@@ -64,6 +64,11 @@
return resolveMandatoryEndpoint(context, uri);
}
+ protected <T extends Endpoint> T resolveMandatoryEndpoint(String uri, Class<T> endpointType) {
+ return resolveMandatoryEndpoint(context, uri, endpointType);
+ }
+
+
/**
* Sends a message to the given endpoint URI with the body value
*
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?view=diff&rev=545303&r1=545302&r2=545303
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Thu Jun 7 13:35:32 2007
@@ -122,6 +122,17 @@
}
/**
+ * Resolves an endpoint and asserts that it is found
+ */
+ protected <T extends Endpoint> T resolveMandatoryEndpoint(CamelContext context, String uri, Class<T> endpointType) {
+ T endpoint = context.getEndpoint(uri, endpointType);
+
+ assertNotNull("No endpoint found for URI: " + uri, endpoint);
+
+ return endpoint;
+ }
+
+ /**
* Creates an exchange with the given body
*/
protected Exchange createExchangeWithBody(CamelContext camelContext, Object body) {