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.ejb;
018
019 import java.util.Map;
020 import java.util.Properties;
021 import javax.naming.Context;
022 import javax.naming.InitialContext;
023 import javax.naming.NamingException;
024
025 import org.apache.camel.Endpoint;
026 import org.apache.camel.Processor;
027 import org.apache.camel.component.bean.BeanComponent;
028 import org.apache.camel.component.bean.BeanEndpoint;
029 import org.apache.camel.impl.JndiRegistry;
030 import org.apache.camel.spi.Registry;
031
032 /**
033 * EJB component to invoke EJBs like the {@link org.apache.camel.component.bean.BeanComponent}.
034 *
035 * @version $Revision: 19532 $
036 */
037 public class EjbComponent extends BeanComponent {
038
039 private Context context;
040 private Properties properties;
041
042 @Override
043 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
044 BeanEndpoint answer = new BeanEndpoint(uri, this);
045 answer.setBeanName(remaining);
046
047 // plugin registry to lookup in jndi for the EJBs
048 Registry registry = new JndiRegistry(getContext());
049 answer.setBeanHolder(new EjbRegistryBean(registry, getCamelContext(), answer.getBeanName()));
050
051 Processor processor = answer.getProcessor();
052 setProperties(processor, parameters);
053 return answer;
054 }
055
056 public synchronized Context getContext() throws NamingException {
057 if (context == null && properties != null) {
058 context = new InitialContext(getProperties());
059 }
060 return context;
061 }
062
063 public void setContext(Context context) {
064 this.context = context;
065 }
066
067 public Properties getProperties() {
068 return properties;
069 }
070
071 public void setProperties(Properties properties) {
072 this.properties = properties;
073 }
074 }