geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From delaf...@apache.org
Subject svn commit: r159302 - in geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming: InitialContext.java NamingContext.java
Date Mon, 28 Mar 2005 20:36:35 GMT
Author: delafran
Date: Mon Mar 28 12:36:34 2005
New Revision: 159302

URL: http://svn.apache.org/viewcvs?view=rev&rev=159302
Log:
Removed openejb dependencies

Modified:
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/InitialContext.java
    geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/NamingContext.java

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/InitialContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/InitialContext.java?view=diff&r1=159301&r2=159302
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/InitialContext.java
(original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/InitialContext.java
Mon Mar 28 12:36:34 2005
@@ -26,7 +26,6 @@
 import javax.naming.NamingException;
 import javax.naming.OperationNotSupportedException;
 
-
 public class InitialContext implements Context, java.io.Serializable {
     private static HashMap EMPTY_MAP = new HashMap();
     private String prefix;

Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/NamingContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/NamingContext.java?view=diff&r1=159301&r2=159302
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/NamingContext.java
(original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/naming/NamingContext.java
Mon Mar 28 12:36:34 2005
@@ -20,6 +20,7 @@
 import java.util.HashMap;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
+import javax.naming.Context;
 
 import org.apache.geronimo.interop.adapter.Adapter;
 import org.apache.commons.logging.Log;
@@ -48,6 +49,7 @@
     private static boolean          verbose = true; // TODO: Configure
     private String                  logContext;
     private HashMap                 map = new HashMap();
+    private HashMap                 failedBindings = new HashMap();
 
     public static final NamingContext getCurrent() {
         return (NamingContext) current.get();
@@ -90,6 +92,14 @@
             }
         }
 
+        // If it is corbaname type bind, give it one more chance to bind 
+        // if not already bound.
+
+        if (value == null)
+        {
+            value = tryBindCorbaName(name);
+        }
+
         if (value == null) {
             NameNotFoundException notFound = new NameNotFoundException(name.length() == 0
? formatEmptyName() : name);
             if (!quiet) {
@@ -135,12 +145,108 @@
         return false;
     }
 
+    /*
+     * The allows the server to bind an object whose name beings with "lookup=".
+     * The lookup= instructs the name service to perform a lookup on another name
+     * service.
+     */
+    protected Object bindCorbaName(String name, String value)
+    {
+        String url = value.substring("lookup=".length());
+
+        /*
+         * value will only have the following two patterns:
+         *
+         * lookup=corbaname...
+         * lookup=corbaloc...
+         *
+         * These are placed into the URL that is sent to the context factory.
+         * The context factory then determine how to perform a lookup on a
+         * given corbaname or corbaloc url.
+         */
+
+        java.util.Properties p = new java.util.Properties();
+
+        /*
+         * corbaname and corbaloc urls are not supported by the OpenEJB name service
+         */
+        p.put(Context.INITIAL_CONTEXT_FACTORY, "" ); // org.openejb.client.RemoteInitialContextFactory
??
+        p.put(Context.PROVIDER_URL, url);
+
+        Context initialContext = null;
+        Object object = null;
+        try
+        {
+            initialContext = new javax.naming.InitialContext(p);
+            object = initialContext.lookup("");
+        }
+        catch (javax.naming.NamingException ne)
+        {
+            failedBindings(name, value);
+            NameServiceLog.getInstance().warnBindFailed(logContext, name, url, ne);
+            return null;
+        }
+        catch (java.lang.IllegalArgumentException ie)
+        {
+            NameServiceLog.getInstance().warnBindFailed(logContext, name, url, ie);
+            return null;
+        }
+        catch (Exception ex)
+        {
+            failedBindings(name, value);
+            NameServiceLog.getInstance().warnBindFailed(logContext, name, url, ex);
+            return null;
+        }
+
+        if (object == null)
+        {
+            NameServiceLog.getInstance().warnIllegalBindValue(logContext, Object.class, name,
url);
+            return null;
+        }
+
+        map.put(name, object);
+
+        return object;
+    }
+
     protected Object dynamicLookup(String name) {
         return null;
     }
 
     protected String formatEmptyName() {
         return "formatEmptyName:";
+    }
+
+    // bind for corbaname failed at server startup. We will try to bind once
+    // again.
+    private Object tryBindCorbaName(String name)
+    {
+        Object obj = null;
+        Object val = failedBindings.get(name);
+        if( val != null)
+        {
+            obj = bindCorbaName(name, (String)val);
+        }
+        return obj;
+    }
+
+    /**
+     * If corbaname bindings fail, give it one more chance at the time of
+     * lookup
+     */
+    private void failedBindings(String name, String value)
+    {
+        Object val = failedBindings.get(name);
+        if( val == null)
+        {
+            failedBindings.put(name, value);
+        }
+        else
+        {
+            //If the binding already exists in the map, then we have already given
+            //it one more chance to bind. Time to remove it.
+            failedBindings.remove(name);
+        }
     }
 
 }



Mime
View raw message