01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.gjndi;
17:
18: import org.apache.geronimo.gbean.GBeanInfo;
19: import org.apache.geronimo.gbean.GBeanInfoBuilder;
20: import org.apache.geronimo.gbean.GBeanLifecycle;
21: import org.apache.geronimo.gbean.AbstractNameQuery;
22: import org.apache.geronimo.gbean.AbstractName;
23: import org.apache.geronimo.kernel.Kernel;
24: import org.apache.xbean.naming.global.GlobalContextManager;
25:
26: import javax.naming.Context;
27: import javax.naming.NamingException;
28: import javax.naming.Name;
29: import java.util.Collections;
30:
31: /**
32: * @version $Rev$ $Date$
33: */
34: public class GlobalContextGBean extends KernelContextGBean implements
35: GBeanLifecycle {
36: public GlobalContextGBean(Kernel kernel) throws NamingException {
37: super ("", new AbstractNameQuery(null, Collections.EMPTY_MAP,
38: Context.class.getName()), kernel);
39: }
40:
41: public void doStart() {
42: super .doStart();
43: GlobalContextManager.setGlobalContext(this );
44: }
45:
46: public void doStop() {
47: GlobalContextManager.setGlobalContext(null);
48: super .doStop();
49: }
50:
51: public void doFail() {
52: GlobalContextManager.setGlobalContext(null);
53: super .doFail();
54: }
55:
56: protected Name createBindingName(AbstractName abstractName,
57: Object value) throws NamingException {
58: if (value instanceof Context) {
59: // don't bind yourself
60: if (value == this )
61: return null;
62:
63: Context context = (Context) value;
64: String nameInNamespace = context.getNameInNamespace();
65: return getNameParser().parse(nameInNamespace);
66: }
67: throw new NamingException(
68: "value is not a context: abstractName=" + abstractName
69: + " valueType=" + value.getClass().getName());
70: }
71:
72: public static final GBeanInfo GBEAN_INFO;
73:
74: public static GBeanInfo getGBeanInfo() {
75: return GBEAN_INFO;
76: }
77:
78: static {
79: GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(
80: GlobalContextGBean.class, "GlobalContext");
81: builder.setConstructor(new String[] { "kernel" });
82: GBEAN_INFO = builder.getBeanInfo();
83: }
84: }
|