View Javadoc

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