View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.ejb;
8   
9   import org.mule.api.config.PropertyFactory;
10  import org.mule.jndi.MuleInitialContextFactory;
11  
12  import java.util.Hashtable;
13  import java.util.Map;
14  
15  import javax.naming.Context;
16  import javax.naming.InitialContext;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  public class SimpleEjbContextFactory implements PropertyFactory
22  {
23      protected final Log logger = LogFactory.getLog(getClass());
24  
25      public Object create(Map<?, ?> properties) throws Exception
26      {
27          Hashtable<String, Object> env = new Hashtable<String, Object>();
28          env.put(Context.INITIAL_CONTEXT_FACTORY, MuleInitialContextFactory.class.getName());
29          
30          InitialContext context = new InitialContext(env);
31          for (Map.Entry<?, ?> entry : properties.entrySet())
32          {
33              Object key = entry.getKey();
34              if (key instanceof String)
35              {
36                  Object value = entry.getValue();
37                  logger.debug("Binding " + key + " to " + value);
38                  context.bind((String) key, value);
39              }
40          }
41          
42          return context;
43      }
44  
45  }