KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > client > StaticJndiContextPlugin


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.client;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Collections JavaDoc;
22 import javax.naming.InitialContext JavaDoc;
23 import javax.naming.Context JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25
26 import org.apache.geronimo.naming.java.RootContext;
27 import org.apache.geronimo.naming.reference.KernelAwareReference;
28 import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
29 import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
30 import org.apache.geronimo.gbean.GBeanInfo;
31 import org.apache.geronimo.gbean.GBeanInfoBuilder;
32 import org.apache.geronimo.gbean.AbstractName;
33 import org.apache.geronimo.kernel.Kernel;
34 import org.apache.xbean.naming.context.ImmutableContext;
35
36 /**
37  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
38  */

39 public class StaticJndiContextPlugin implements AppClientPlugin {
40     private final Context JavaDoc context;
41
42     public StaticJndiContextPlugin(Map JavaDoc context, Kernel kernel, ClassLoader JavaDoc classLoader) throws NamingException JavaDoc {
43         this.context = EnterpriseNamingContext.createEnterpriseNamingContext(context, null, kernel, classLoader);
44     }
45
46     public void startClient(AbstractName appClientModuleName, Kernel kernel, ClassLoader JavaDoc classLoader) throws Exception JavaDoc {
47         RootContext.setComponentContext(context);
48         new InitialContext JavaDoc().lookup("java:comp/env");
49     }
50
51     public void stopClient(AbstractName appClientModuleName) throws Exception JavaDoc {
52         RootContext.setComponentContext(null);
53     }
54
55     public static final GBeanInfo GBEAN_INFO;
56
57     static {
58         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(StaticJndiContextPlugin.class);
59
60         infoFactory.addAttribute("context", Map JavaDoc.class, true);
61         infoFactory.addAttribute("kernel", Kernel.class, false);
62         infoFactory.addAttribute("classLoader", ClassLoader JavaDoc.class, false);
63         infoFactory.addInterface(AppClientPlugin.class);
64
65         infoFactory.setConstructor(new String JavaDoc[]{"context", "kernel", "classLoader"});
66
67         GBEAN_INFO = infoFactory.getBeanInfo();
68     }
69
70     public static GBeanInfo getGBeanInfo() {
71         return GBEAN_INFO;
72     }
73 }
74
Popular Tags