Title: [2442] trunk/openejb3/container/openejb-core/src/main/java/org/openejb: This file never should have been removed.
- Revision
- 2442
- Author
- dblevins
- Date
- 2006-02-13 23:37:38 -0500 (Mon, 13 Feb 2006)
Log Message
This file never should have been removed. Unfortunate that we put it into the client package as it has nothing to do with the remote client. Course the other perspective is that it's unfortunate we put the EJBd client code into the org.openejb.client package as it's not generic client code and tied to that protocol specifically. One thought is to move all protocol-specific client code into modules relating to the protocol (server) and make an actual client package consisting of a few classes only and providing an easy way to use the protocol of your choosing.
Ideas, ideas, ideas... to many so little time........
Added Paths
Diff
Added: trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/LocalInitialContextFactory.java (2441 => 2442)
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/LocalInitialContextFactory.java 2006-02-12 05:52:02 UTC (rev 2441)
+++ trunk/openejb3/container/openejb-core/src/main/java/org/openejb/client/LocalInitialContextFactory.java 2006-02-14 04:37:38 UTC (rev 2442)
@@ -0,0 +1,71 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openejb.client;
+
+import org.openejb.loader.OpenEJBInstance;
+import org.openejb.loader.SystemInstance;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import java.util.Hashtable;
+import java.util.Properties;
+
+public class LocalInitialContextFactory implements javax.naming.spi.InitialContextFactory {
+
+ static Context intraVmContext;
+ private static OpenEJBInstance openejb;
+
+ public Context getInitialContext(Hashtable env) throws javax.naming.NamingException {
+ if (intraVmContext == null) {
+ try {
+ Properties properties = new Properties();
+ properties.putAll(env);
+ init(properties);
+ } catch (Exception e) {
+ throw (NamingException) new NamingException("Attempted to load OpenEJB. " + e.getMessage()).initCause(e);
+ }
+ intraVmContext = getIntraVmContext(env);
+ }
+ return intraVmContext;
+ }
+
+ public void init(Properties properties) throws Exception {
+ if (openejb != null) return;
+ SystemInstance.init(properties);
+ openejb = new OpenEJBInstance();
+ if (openejb.isInitialized()) return;
+ openejb.init(properties);
+ }
+
+ private Context getIntraVmContext(Hashtable env) throws javax.naming.NamingException {
+ Context context = null;
+ try {
+ InitialContextFactory factory = null;
+ ClassLoader cl = SystemInstance.get().getClassLoader();
+ Class ivmFactoryClass = Class.forName("org.openejb.core.ivm.naming.InitContextFactory", true, cl);
+
+ factory = (InitialContextFactory) ivmFactoryClass.newInstance();
+ context = factory.getInitialContext(env);
+ } catch (Exception e) {
+ throw new javax.naming.NamingException("Cannot instantiate an IntraVM InitialContext. Exception: "
+ + e.getClass().getName() + " " + e.getMessage());
+ }
+
+ return context;
+ }
+}
\ No newline at end of file