1 17 package org.apache.geronimo.gjndi; 18 19 import org.apache.geronimo.gbean.GBeanInfo; 20 import org.apache.geronimo.gbean.GBeanInfoBuilder; 21 import org.apache.geronimo.gbean.GBeanLifecycle; 22 import org.apache.geronimo.gbean.AbstractNameQuery; 23 import org.apache.geronimo.gbean.AbstractName; 24 import org.apache.geronimo.kernel.Kernel; 25 import org.apache.xbean.naming.global.GlobalContextManager; 26 27 import javax.naming.Context ; 28 import javax.naming.NamingException ; 29 import javax.naming.Name ; 30 import java.util.Collections ; 31 32 35 public class GlobalContextGBean extends KernelContextGBean implements GBeanLifecycle { 36 public GlobalContextGBean(Kernel kernel) throws NamingException { 37 super("", new AbstractNameQuery(null, Collections.EMPTY_MAP, Context .class.getName()), kernel); 38 } 39 40 public void doStart() { 41 super.doStart(); 42 GlobalContextManager.setGlobalContext(this); 43 } 44 45 public void doStop() { 46 GlobalContextManager.setGlobalContext(null); 47 super.doStop(); 48 } 49 50 public void doFail() { 51 GlobalContextManager.setGlobalContext(null); 52 super.doFail(); 53 } 54 55 protected Name createBindingName(AbstractName abstractName, Object value) throws NamingException { 56 if (value instanceof Context ) { 57 if (value == this) return null; 59 60 Context context = (Context ) value; 61 String nameInNamespace = context.getNameInNamespace(); 62 return getNameParser().parse(nameInNamespace); 63 } 64 throw new NamingException ("value is not a context: abstractName=" + abstractName + " valueType=" + value.getClass().getName()); 65 } 66 67 public static final GBeanInfo GBEAN_INFO; 68 69 public static GBeanInfo getGBeanInfo() { 70 return GBEAN_INFO; 71 } 72 73 static { 74 GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(GlobalContextGBean.class, "GlobalContext"); 75 builder.setConstructor(new String []{"kernel"}); 76 GBEAN_INFO = builder.getBeanInfo(); 77 } 78 } 79 | Popular Tags |