geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r881902 - /geronimo/specs/trunk/geronimo-ejb_3.1_spec/src/main/java/javax/ejb/embeddable/EJBContainer.java
Date Wed, 18 Nov 2009 19:56:46 GMT
Author: dblevins
Date: Wed Nov 18 19:56:46 2009
New Revision: 881902

URL: http://svn.apache.org/viewvc?rev=881902&view=rev
Log: (empty)

Modified:
    geronimo/specs/trunk/geronimo-ejb_3.1_spec/src/main/java/javax/ejb/embeddable/EJBContainer.java

Modified: geronimo/specs/trunk/geronimo-ejb_3.1_spec/src/main/java/javax/ejb/embeddable/EJBContainer.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-ejb_3.1_spec/src/main/java/javax/ejb/embeddable/EJBContainer.java?rev=881902&r1=881901&r2=881902&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-ejb_3.1_spec/src/main/java/javax/ejb/embeddable/EJBContainer.java
(original)
+++ geronimo/specs/trunk/geronimo-ejb_3.1_spec/src/main/java/javax/ejb/embeddable/EJBContainer.java
Wed Nov 18 19:56:46 2009
@@ -21,7 +21,14 @@
 //
 package javax.ejb.embeddable;
 
+import javax.ejb.EJBException;
+import javax.ejb.spi.EJBContainerProvider;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
 import java.util.Collections;
+import java.util.Enumeration;
 
 public abstract class EJBContainer {
 
@@ -39,9 +46,76 @@
     }
 
     public static EJBContainer createEJBContainer(java.util.Map<?, ?> properties) {
-        return null; // TODO
+
+        if (properties == null) {
+            properties = Collections.EMPTY_MAP;
+        }
+
+        String providerName = null;
+
+        Object o = properties.get(PROVIDER);
+
+        if (o instanceof String) {
+            providerName = (String) o;
+        } else {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            try {
+                String service = "META-INF/services/" + EJBContainerProvider.class.getName();
+                Enumeration<URL> providers = loader.getResources(service);
+
+                while (providers.hasMoreElements()) {
+
+                    String name = getProviderName(providers.nextElement());
+
+                    if (name != null) {
+                        providerName = name;
+                        break;
+                    }
+                }
+            } catch (IOException e) {
+            }
+        }
+
+        if (providerName == null) {
+            throw new EJBException("No provider found");
+        }
+
+        Class providerClass;
+
+        try {
+            providerClass = Class.forName(providerName, true, Thread.currentThread().getContextClassLoader());
+        } catch (Exception e) {
+            throw new EJBException("Invalid or inaccessible provider class: " + providerName,
e);
+        }
+
+        try {
+            EJBContainerProvider provider = (EJBContainerProvider) providerClass.newInstance();
+            return provider.createEJBContainer(properties);
+        } catch (Exception e) {
+            throw new EJBException("Provider error. Provider: " + providerName, e);
+        }
+    }
+
+    static String getProviderName(URL url) throws IOException {
+
+        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
+
+        String providerName;
+
+        try {
+            providerName = in.readLine();
+        } finally {
+            in.close();
+        }
+
+        if (providerName != null) {
+            providerName = providerName.trim();
+        }
+
+        return providerName;
     }
 
     public abstract javax.naming.Context getContext();
 
+
 }



Mime
View raw message