Coverage Report - org.apache.camel.spring.xml.RouteBuilderFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteBuilderFactoryBean
89% 
N/A 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.spring.xml;
 19  
 
 20  
 import static org.apache.camel.util.ObjectHelper.notNull;
 21  
 
 22  
 import java.util.ArrayList;
 23  
 
 24  
 import org.apache.camel.CamelContext;
 25  
 import org.springframework.beans.BeansException;
 26  
 import org.springframework.beans.factory.BeanFactory;
 27  
 import org.springframework.beans.factory.BeanFactoryAware;
 28  
 import org.springframework.beans.factory.FactoryBean;
 29  
 import org.springframework.beans.factory.InitializingBean;
 30  
 
 31  
 /**
 32  
  * A {@link FactoryBean} which creates a RouteBuilder by parsing an XML file. This factory bean
 33  
  * must be injected with a context and will then install the rules in the context when the routing rules
 34  
  * are created. 
 35  
  *
 36  
  * @version $Revision: 521369 $
 37  
  */
 38  27
 public class RouteBuilderFactoryBean implements FactoryBean, BeanFactoryAware, InitializingBean {
 39  
         private ArrayList<BuilderStatement> routes;
 40  
         private BeanFactory beanFactory;
 41  
     private CamelContext context;
 42  27
     private StatementRouteBuilder builder = new StatementRouteBuilder();
 43  
 
 44  
     public Object getObject() throws Exception {
 45  1
         return builder;
 46  
         }
 47  
 
 48  
         public Class getObjectType() {
 49  32
                 return StatementRouteBuilder.class;
 50  
         }
 51  
 
 52  
         public boolean isSingleton() {
 53  12
                 return true;
 54  
         }
 55  
 
 56  
         public ArrayList<BuilderStatement> getRoutes() {
 57  0
                 return routes;
 58  
         }
 59  
         public void setRoutes(ArrayList<BuilderStatement> routes) {
 60  27
                 this.routes = routes;
 61  27
         }
 62  
 
 63  
         public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
 64  27
                 this.beanFactory = beanFactory;
 65  27
         }
 66  
 
 67  
     public CamelContext getContext() {
 68  0
         return context;
 69  
     }
 70  
 
 71  
     public void setContext(CamelContext context) {
 72  27
         this.context = context;
 73  27
     }
 74  
 
 75  
     public void afterPropertiesSet() throws Exception {
 76  27
         notNull(context, "context");
 77  27
         notNull(routes, "routes");
 78  27
                 builder.setBeanFactory(beanFactory);
 79  27
                 builder.setRoutes(routes);
 80  
 
 81  
         // now lets install the routes in the context
 82  27
         context.addRoutes(builder);
 83  27
     }
 84  
 }