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.client;
17:
18: import java.util.Map;
19:
20: import javax.naming.InitialContext;
21: import javax.naming.Context;
22: import javax.naming.NamingException;
23:
24: import org.apache.geronimo.naming.java.RootContext;
25: import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
26: import org.apache.geronimo.gbean.GBeanInfo;
27: import org.apache.geronimo.gbean.GBeanInfoBuilder;
28: import org.apache.geronimo.gbean.AbstractName;
29: import org.apache.geronimo.kernel.Kernel;
30:
31: /**
32: * @version $Rev: 512993 $ $Date: 2007-02-28 13:40:40 -0800 (Wed, 28 Feb 2007) $
33: */
34: public class StaticJndiContextPlugin implements AppClientPlugin {
35: private final Context context;
36:
37: public StaticJndiContextPlugin(Map context, Kernel kernel,
38: ClassLoader classLoader) throws NamingException {
39: this .context = EnterpriseNamingContext
40: .createEnterpriseNamingContext(context, null, kernel,
41: classLoader);
42: }
43:
44: public void startClient(AbstractName appClientModuleName,
45: Kernel kernel, ClassLoader classLoader) throws Exception {
46: RootContext.setComponentContext(context);
47: new InitialContext().lookup("java:comp/env");
48: }
49:
50: public void stopClient(AbstractName appClientModuleName)
51: throws Exception {
52: RootContext.setComponentContext(null);
53: }
54:
55: public Context getJndiContext() {
56: return context;
57: }
58:
59: public static final GBeanInfo GBEAN_INFO;
60:
61: static {
62: GBeanInfoBuilder infoFactory = GBeanInfoBuilder
63: .createStatic(StaticJndiContextPlugin.class);
64:
65: infoFactory.addAttribute("context", Map.class, true);
66: infoFactory.addAttribute("jndiContext", Context.class, false);
67: infoFactory.addAttribute("kernel", Kernel.class, false);
68: infoFactory.addAttribute("classLoader", ClassLoader.class,
69: false);
70: infoFactory.addInterface(AppClientPlugin.class);
71:
72: infoFactory.setConstructor(new String[] { "context", "kernel",
73: "classLoader" });
74:
75: GBEAN_INFO = infoFactory.getBeanInfo();
76: }
77:
78: public static GBeanInfo getGBeanInfo() {
79: return GBEAN_INFO;
80: }
81: }
|