KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > gjndi > GlobalContextGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.naming.Name JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 /**
33  * @version $Rev$ $Date$
34  */

35 public class GlobalContextGBean extends KernelContextGBean implements GBeanLifecycle {
36     public GlobalContextGBean(Kernel kernel) throws NamingException JavaDoc {
37         super("", new AbstractNameQuery(null, Collections.EMPTY_MAP, Context JavaDoc.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 JavaDoc value) throws NamingException JavaDoc {
56         if (value instanceof Context JavaDoc) {
57             // don't bind yourself
58
if (value == this) return null;
59
60             Context JavaDoc context = (Context JavaDoc) value;
61             String JavaDoc nameInNamespace = context.getNameInNamespace();
62             return getNameParser().parse(nameInNamespace);
63         }
64         throw new NamingException JavaDoc("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 JavaDoc[]{"kernel"});
76         GBEAN_INFO = builder.getBeanInfo();
77     }
78 }
79
Popular Tags