Author: ningjiang
Date: Wed Nov 25 05:13:25 2009
New Revision: 883979
URL: http://svn.apache.org/viewvc?rev=883979&view=rev
Log:
CAMEL-2225 Added configureCamelContext method in Module for extesion
Modified:
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
Modified:
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java?rev=883979&r1=883978&r2=883979&view=diff
==============================================================================
---
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
(original)
+++
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
Wed Nov 25 05:13:25 2009
@@ -45,12 +45,16 @@
* @version $Revision$
*/
public class CamelModule extends Jsr250Module {
+
+ protected void configureCamelContext() {
+
bind(CamelContext.class).to(GuiceCamelContext.class).asEagerSingleton();
+ }
protected void configure() {
super.configure();
-
bind(CamelContext.class).to(GuiceCamelContext.class).asEagerSingleton();
-
+ configureCamelContext();
+
bindAnnotationInjector(EndpointInject.class, EndpointInjector.class);
bindAnnotationInjector(Produce.class, ProduceInjector.class);
Modified:
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java?rev=883979&r1=883978&r2=883979&view=diff
==============================================================================
---
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
(original)
+++
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
Wed Nov 25 05:13:25 2009
@@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;
+import javax.naming.Context;
import javax.naming.InitialContext;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -43,7 +44,6 @@
*/
public class Main extends MainSupport {
private static Main instance;
- private InitialContext context;
private Injector injector;
@@ -77,18 +77,25 @@
// Properties
//
-------------------------------------------------------------------------
-
-
+ protected void setInjector(Injector injector) {
+ this.injector = injector;
+ }
+
+ protected Injector getInjector() {
+ return injector;
+ }
+
// Implementation methods
//
-------------------------------------------------------------------------
-
+ protected Injector getInjectorFromContext() throws Exception {
+ Context context = new InitialContext();
+ return (Injector) context.lookup(Injector.class.getName());
+ }
+
@Override
protected void doStart() throws Exception {
super.doStart();
-
- context = new InitialContext();
-
- injector = (Injector) context.lookup(Injector.class.getName());
+ setInjector(getInjectorFromContext());
postProcessContext();
}
@@ -105,7 +112,7 @@
if (injector != null) {
Set<ProducerTemplate> set = Injectors.getInstancesOf(injector,
ProducerTemplate.class);
if (!set.isEmpty()) {
- // TODO shouldbe Iterables.get(set, 0);
+ // TODO should be Iterables.get(set, 0);
return Iterables.getOnlyElement(set);
}
}