1 17 18 package org.apache.geronimo.naming.java; 19 20 import java.util.Collections ; 21 22 import javax.naming.Context ; 23 import javax.naming.NameNotFoundException ; 24 import javax.naming.NamingException ; 25 26 import org.apache.xbean.naming.context.ImmutableContext; 27 28 35 public class RootContext extends ImmutableContext { 36 private static InheritableThreadLocal compContext = new InheritableThreadLocal (); 37 38 public RootContext() throws NamingException { 39 super(Collections.EMPTY_MAP); 40 } 41 42 public Object lookup(String name) throws NamingException { 43 if (name.startsWith("java:")) { 44 name = name.substring(5); 45 if (name.length() == 0) { 46 return this; 47 } 48 49 Context compCtx = (Context ) compContext.get(); 50 if (compCtx == null) { 51 throw new NameNotFoundException (name); 53 } 54 55 if ("comp".equals(name)) { 56 return compCtx; 57 } else if (name.startsWith("comp/")) { 58 return compCtx.lookup(name.substring(5)); 59 } else if ("/comp".equals(name)) { 60 return compCtx; 61 } else if (name.startsWith("/comp/")) { 62 return compCtx.lookup(name.substring(6)); 63 } else { 64 throw new NameNotFoundException ("Unrecognized name, does not start with expected 'comp': " + name); 65 } 66 } 67 return super.lookup(name); 68 } 69 70 75 public static void setComponentContext(Context ctx) { 76 compContext.set(ctx); 77 } 78 79 83 public static Context getComponentContext() { 84 return (Context ) compContext.get(); 85 } 86 } 87 | Popular Tags |