Coverage Report - org.apache.camel.impl.DefaultComponentResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultComponentResolver
54% 
100% 
0
 
 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.impl;
 18  
 
 19  
 import org.apache.camel.CamelContext;
 20  
 import org.apache.camel.Component;
 21  
 import org.apache.camel.Exchange;
 22  
 import org.apache.camel.spi.ComponentResolver;
 23  
 import org.apache.camel.util.FactoryFinder;
 24  
 import org.apache.camel.util.NoFactoryAvailableException;
 25  
 
 26  
 /**
 27  
  * The default implementation of {@link ComponentResolver} which tries to find
 28  
  * components by using the URI scheme prefix and searching for a file of the URI
 29  
  * scheme name in the <b>META-INF/services/org/apache/camel/component/</b>
 30  
  * directory on the classpath.
 31  
  * 
 32  
  * @version $Revision: 563607 $
 33  
  */
 34  243
 public class DefaultComponentResolver<E extends Exchange> implements ComponentResolver<E> {
 35  3
     protected static final FactoryFinder COMPONENT_FACTORY = 
 36  
         new FactoryFinder("META-INF/services/org/apache/camel/component/");
 37  
 
 38  
     public Component<E> resolveComponent(String name, CamelContext context) {
 39  
         Class type;
 40  
         try {
 41  411
             type = COMPONENT_FACTORY.findClass(name);
 42  0
         } catch (NoFactoryAvailableException e) {
 43  0
             return null;
 44  0
         } catch (Throwable e) {
 45  0
             throw new IllegalArgumentException("Invalid URI, no Component registered for scheme : " 
 46  
                                                + name, e);
 47  411
         }
 48  411
         if (type == null) {
 49  0
             return null;
 50  
         }
 51  411
         if (Component.class.isAssignableFrom(type)) {
 52  411
             return (Component<E>)context.getInjector().newInstance(type);
 53  
         } else {
 54  0
             throw new IllegalArgumentException("Type is not a Component implementation. Found: "
 55  
                                                + type.getName());
 56  
         }
 57  
     }
 58  
 }