Coverage Report - org.apache.camel.component.bean.BeanComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanComponent
83% 
100% 
1.5
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.bean;
 18  
 
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.impl.DefaultComponent;
 23  
 import org.apache.camel.impl.ProcessorEndpoint;
 24  
 import org.apache.camel.spi.Registry;
 25  
 import org.apache.camel.util.IntrospectionSupport;
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 /**
 30  
  * An alternative to the <a href="http://activemq.apache.org/pojo.html">POJO Component</a>
 31  
  * which implements the <a href="http://activemq.apache.org/bean.html">Bean Component</a>
 32  
  * which will look up the URI in the Spring ApplicationContext and use that to handle message dispatching.
 33  
  *
 34  
  * @version $Revision: 1.1 $
 35  
  */
 36  
 public class BeanComponent extends DefaultComponent {
 37  3
     private static final Log LOG = LogFactory.getLog(BeanComponent.class);
 38  
     private ParameterMappingStrategy parameterMappingStrategy;
 39  
 
 40  9
     public BeanComponent() {
 41  9
     }
 42  
 
 43  
     public ParameterMappingStrategy getParameterMappingStrategy() {
 44  6
         if (parameterMappingStrategy == null) {
 45  6
             parameterMappingStrategy = createParameterMappingStrategy();
 46  
         }
 47  6
         return parameterMappingStrategy;
 48  
     }
 49  
 
 50  
     public void setParameterMappingStrategy(ParameterMappingStrategy parameterMappingStrategy) {
 51  0
         this.parameterMappingStrategy = parameterMappingStrategy;
 52  0
     }
 53  
 
 54  
     // Implementation methods
 55  
     //-----------------------------------------------------------------------
 56  
 
 57  
     protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
 58  6
         Object bean = getBean(remaining);
 59  6
         BeanProcessor processor = new BeanProcessor(bean, getParameterMappingStrategy());
 60  6
         IntrospectionSupport.setProperties(processor, parameters);
 61  6
         return new ProcessorEndpoint(uri, this, processor);
 62  
     }
 63  
 
 64  
     public Object getBean(String remaining) throws NoBeanAvailableException {
 65  6
         Registry registry = getCamelContext().getRegistry();
 66  6
         Object bean = registry.lookup(remaining);
 67  6
         if (bean == null) {
 68  0
             throw new NoBeanAvailableException(remaining);
 69  
         }
 70  6
         return bean;
 71  
     }
 72  
 
 73  
     protected ParameterMappingStrategy createParameterMappingStrategy() {
 74  6
         return BeanProcessor.createParameterMappingStrategy(getCamelContext());
 75  
     }
 76  
 }