001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.client;
018
019 import java.util.Iterator;
020 import java.util.Map;
021 import java.util.Collections;
022 import javax.naming.InitialContext;
023 import javax.naming.Context;
024 import javax.naming.NamingException;
025
026 import org.apache.geronimo.naming.java.RootContext;
027 import org.apache.geronimo.naming.reference.KernelAwareReference;
028 import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
029 import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
030 import org.apache.geronimo.gbean.GBeanInfo;
031 import org.apache.geronimo.gbean.GBeanInfoBuilder;
032 import org.apache.geronimo.gbean.AbstractName;
033 import org.apache.geronimo.kernel.Kernel;
034 import org.apache.xbean.naming.context.ImmutableContext;
035
036 /**
037 * @version $Rev: 487175 $ $Date: 2006-12-14 03:10:31 -0800 (Thu, 14 Dec 2006) $
038 */
039 public class StaticJndiContextPlugin implements AppClientPlugin {
040 private final Context context;
041
042 public StaticJndiContextPlugin(Map context, Kernel kernel, ClassLoader classLoader) throws NamingException {
043 this.context = EnterpriseNamingContext.createEnterpriseNamingContext(context, null, kernel, classLoader);
044 }
045
046 public void startClient(AbstractName appClientModuleName, Kernel kernel, ClassLoader classLoader) throws Exception {
047 RootContext.setComponentContext(context);
048 new InitialContext().lookup("java:comp/env");
049 }
050
051 public void stopClient(AbstractName appClientModuleName) throws Exception {
052 RootContext.setComponentContext(null);
053 }
054
055 public static final GBeanInfo GBEAN_INFO;
056
057 static {
058 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(StaticJndiContextPlugin.class);
059
060 infoFactory.addAttribute("context", Map.class, true);
061 infoFactory.addAttribute("kernel", Kernel.class, false);
062 infoFactory.addAttribute("classLoader", ClassLoader.class, false);
063 infoFactory.addInterface(AppClientPlugin.class);
064
065 infoFactory.setConstructor(new String[]{"context", "kernel", "classLoader"});
066
067 GBEAN_INFO = infoFactory.getBeanInfo();
068 }
069
070 public static GBeanInfo getGBeanInfo() {
071 return GBEAN_INFO;
072 }
073 }