1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.geronimo.client;
19
20 import java.util.Iterator;
21 import java.util.Map;
22 import java.util.Collections;
23 import javax.naming.InitialContext;
24 import javax.naming.Context;
25 import javax.naming.NamingException;
26
27 import org.apache.geronimo.naming.java.RootContext;
28 import org.apache.geronimo.naming.reference.KernelAwareReference;
29 import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
30 import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
31 import org.apache.geronimo.gbean.GBeanInfo;
32 import org.apache.geronimo.gbean.GBeanInfoBuilder;
33 import org.apache.geronimo.gbean.AbstractName;
34 import org.apache.geronimo.kernel.Kernel;
35 import org.apache.xbean.naming.context.ImmutableContext;
36
37 /**
38 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
39 */
40 public class StaticJndiContextPlugin implements AppClientPlugin {
41 private final Context context;
42
43 public StaticJndiContextPlugin(Map context, Kernel kernel, ClassLoader classLoader) throws NamingException {
44 this.context = EnterpriseNamingContext.createEnterpriseNamingContext(context, null, kernel, classLoader);
45 }
46
47 public void startClient(AbstractName appClientModuleName, Kernel kernel, ClassLoader classLoader) throws Exception {
48 RootContext.setComponentContext(context);
49 new InitialContext().lookup("java:comp/env");
50 }
51
52 public void stopClient(AbstractName appClientModuleName) throws Exception {
53 RootContext.setComponentContext(null);
54 }
55
56 public static final GBeanInfo GBEAN_INFO;
57
58 static {
59 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(StaticJndiContextPlugin.class);
60
61 infoFactory.addAttribute("context", Map.class, true);
62 infoFactory.addAttribute("kernel", Kernel.class, false);
63 infoFactory.addAttribute("classLoader", ClassLoader.class, false);
64 infoFactory.addInterface(AppClientPlugin.class);
65
66 infoFactory.setConstructor(new String[]{"context", "kernel", "classLoader"});
67
68 GBEAN_INFO = infoFactory.getBeanInfo();
69 }
70
71 public static GBeanInfo getGBeanInfo() {
72 return GBEAN_INFO;
73 }
74 }