KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > ivm > naming > InitContextFactory


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: InitContextFactory.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.core.ivm.naming;
46
47 import java.util.Hashtable JavaDoc;
48 import java.util.Properties JavaDoc;
49
50 import javax.naming.Context JavaDoc;
51
52 import org.openejb.EnvProps;
53
54 /**
55  * Invoked by server on the OpenEJB JNDI global name space.
56  *
57  * Allows application clients in the same vm to lookup beans
58  * in the OpenEJB global name space.
59  *
60  * If OpenEJB is not initialized when getInitialContext(env) is
61  * called, the IntraVM Server will initialize OpenEJB as an in VM
62  * EJB Server. In this case, OpenEJB is not capable of receiving
63  * remote calls.
64  *
65  * @author David Blevins
66  * @author Richard Monson-Haefel
67  */

68 public class InitContextFactory implements javax.naming.spi.InitialContextFactory JavaDoc {
69     
70     public Context JavaDoc getInitialContext(Hashtable JavaDoc env) throws javax.naming.NamingException JavaDoc {
71         if (!org.openejb.OpenEJB.isInitialized()) {
72             initializeOpenEJB(env);
73         }
74
75         Context JavaDoc context = org.openejb.OpenEJB.getJNDIContext();
76         context = (Context JavaDoc)context.lookup("java:openejb/ejb");
77         return context;
78
79     }
80
81     private void initializeOpenEJB(Hashtable JavaDoc env) throws javax.naming.NamingException JavaDoc{
82         try{
83         Properties JavaDoc props = new Properties JavaDoc();
84
85         // Prepare defaults
86
/* DMB: We should get the defaults from the functionality
87          * Alan is working on. This is temporary.
88          * When that logic is finished, this block should
89          * probably just be deleted.
90          */

91         props.put(EnvProps.ASSEMBLER, "org.openejb.alt.assembler.classic.Assembler");
92         props.put(EnvProps.CONFIGURATION_FACTORY, "org.openejb.alt.config.ConfigurationFactory");
93         props.put(EnvProps.CONFIGURATION, "conf/default.openejb.conf");
94
95         // Override defaults with System properties
96
props.putAll(System.getProperties());
97
98         // Override defauls again with JNDI Env properties
99
props.putAll( env );
100
101         org.openejb.OpenEJB.init( props );
102
103         }
104     catch( org.openejb.OpenEJBException e){
105             throw new NamingException("Cannot initailize OpenEJB", e);
106         }
107     catch( Exception JavaDoc e){
108             throw new NamingException("Cannot initailize OpenEJB", e);
109         }
110     }
111
112 }
113
114
115
Popular Tags