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