On Oct 19, 2006, at 11:19 PM, Jacek Laskowski wrote:

On 10/20/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Author: dain
Date: Thu Oct 19 15:44:24 2006
New Revision: 465917
...
+        boolean containsEnv = false;
+ for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            String name = (String) entry.getKey();
+            Object value = entry.getValue();
+
+            if (name.startsWith("env/")) {
+                containsEnv = true;
+            }
             if (value instanceof KernelAwareReference) {
                 ((KernelAwareReference) value).setKernel(kernel);
             }
             if (value instanceof ClassLoaderAwareReference) {
((ClassLoaderAwareReference) value).setClassLoader (classLoader);
             }
+        }
+
+        if (!containsEnv) {
+ Context env = new ImmutableContext("java:comp/env", Collections.EMPTY_MAP, false);
+            map.put("env", env);
         }

I haven't tested it out, but...reading the code seems to set
containsEnv to false every time. It's because name.startsWith("env/")
checks whether env + '/' whereas map contains only env (with no
trailing slash).

BTW, why doesn't it simply use map.get("env") to verify whether
java:comp/env is available?

My understanding of this code is that the map keys are the complete paths to the objects bound into jndi. You can't really bind anything to env, it would have to be env/foo, and although I don't think there's any way to bind anything to envthisisalongername it's easier to just check startsWith("env/") to avoid any confusion. So, you'd never get map.get("env") != null, and startsWith("env/") while probably redundant is certainly accurate.

thanks
david jencks


--
Jacek Laskowski
http://www.jaceklaskowski.pl

Reply via email to