1   /*
2    * $Id: SimpleEjbContextFactory.java 10489 2008-01-23 17:53:38Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.Iterator;
18  import java.util.Map;
19  
20  import javax.naming.Context;
21  import javax.naming.InitialContext;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  
26  public class SimpleEjbContextFactory implements PropertyFactory
27  {
28      protected final Log logger = LogFactory.getLog(getClass());
29  
30      public Object create(Map properties) throws Exception
31      {
32          Hashtable env = new Hashtable();
33          env.put(Context.INITIAL_CONTEXT_FACTORY, MuleInitialContextFactory.class.getName());
34          InitialContext context = new InitialContext(env);
35          Iterator keys = properties.keySet().iterator();
36          while (keys.hasNext())
37          {
38              Object key = keys.next();
39              if (key instanceof String)
40              {
41                  Object value = properties.get(key);
42                  logger.debug("Binding " + key + " to " + value);
43                  context.bind((String) key, value);
44              }
45          }
46          return context;
47      }
48  
49  }