001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.guice;
018    
019    import org.apache.camel.CamelContext;
020    import org.apache.camel.Consume;
021    import org.apache.camel.EndpointInject;
022    import org.apache.camel.Produce;
023    import org.apache.camel.guice.impl.ConsumerInjection;
024    import org.apache.camel.guice.impl.EndpointInjector;
025    import org.apache.camel.guice.impl.ProduceInjector;
026    import org.guiceyfruit.jsr250.Jsr250Module;
027    
028    /**
029     * A base Guice module for creating a {@link CamelContext} leaving it up to the users module
030     * to bind a Set<Routes> for the routing rules.
031     * <p>
032     * To bind the routes you should create a provider method annotated with @Provides and returning Set<Routes> such as
033     * <code><pre>
034     * public class MyModule extends CamelModule {
035     *   &#64;Provides
036     *   Set&lt;Routes&gt; routes(Injector injector) { ... }
037     * }
038     * </pre></code>
039     * If you wish to bind all of the bound {@link org.apache.camel.RoutesBuilder} implementations available - maybe with some filter applied - then
040     * please use the {@link org.apache.camel.guice.CamelModuleWithMatchingRoutes}.
041     * <p>
042     * Otherwise if you wish to list all of the classes of the {@link org.apache.camel.RoutesBuilder} implementations then use the
043     * {@link org.apache.camel.guice.CamelModuleWithRouteTypes} module instead.
044     *
045     * @version $Revision: 16645 $
046     */
047    public class CamelModule extends Jsr250Module {
048        
049        protected void configureCamelContext() {
050            bind(CamelContext.class).to(GuiceCamelContext.class).asEagerSingleton();
051        }
052    
053        protected void configure() {
054            super.configure();
055            
056            configureCamelContext();
057            
058            bindAnnotationInjector(EndpointInject.class, EndpointInjector.class);
059            bindAnnotationInjector(Produce.class, ProduceInjector.class);
060    
061            bindMethodHandler(Consume.class, ConsumerInjection.class);
062        }
063    
064    }