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.component.bean;
018    
019    import java.util.Map;
020    
021    import org.apache.camel.Endpoint;
022    import org.apache.camel.Processor;
023    
024    /**
025     * The <a href="http://camel.apache.org/class.html">Class Component</a>
026     * will create an instance of the class from the {@link org.apache.camel.spi.Registry} and use that to handle message dispatching.
027     *
028     * @version 
029     */
030    public class ClassComponent extends BeanComponent {
031    
032        protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
033            BeanEndpoint endpoint = new BeanEndpoint(uri, this);
034            endpoint.setBeanName(remaining);
035    
036            // bean name is the FQN
037            String name = endpoint.getBeanName();
038            Class<?> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(name);
039            // create bean
040            Object bean = getCamelContext().getInjector().newInstance(clazz);
041    
042            // now set additional properties on it
043            setProperties(bean, parameters);
044    
045            // and register the bean as a holder on the endpoint
046            BeanHolder holder = new ConstantBeanHolder(bean, getCamelContext());
047            endpoint.setBeanHolder(holder);
048    
049            // create processor
050            Processor processor = endpoint.getProcessor();
051            setProperties(processor, parameters);
052            return endpoint;
053        }
054    
055    }