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.Map;
020    
021    import javax.naming.InitialContext;
022    import javax.naming.Context;
023    import javax.naming.NamingException;
024    
025    import org.apache.geronimo.naming.java.RootContext;
026    import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
027    import org.apache.geronimo.gbean.GBeanInfo;
028    import org.apache.geronimo.gbean.GBeanInfoBuilder;
029    import org.apache.geronimo.gbean.AbstractName;
030    import org.apache.geronimo.kernel.Kernel;
031    
032    /**
033     * @version $Rev: 512993 $ $Date: 2007-02-28 16:40:40 -0500 (Wed, 28 Feb 2007) $
034     */
035    public class StaticJndiContextPlugin implements AppClientPlugin {
036        private final Context context;
037    
038        public StaticJndiContextPlugin(Map context, Kernel kernel, ClassLoader classLoader) throws NamingException {
039            this.context = EnterpriseNamingContext.createEnterpriseNamingContext(context, null, kernel, classLoader);
040        }
041    
042        public void startClient(AbstractName appClientModuleName, Kernel kernel, ClassLoader classLoader) throws Exception {
043            RootContext.setComponentContext(context);
044            new InitialContext().lookup("java:comp/env");
045        }
046    
047        public void stopClient(AbstractName appClientModuleName) throws Exception {
048            RootContext.setComponentContext(null);
049        }
050    
051        public Context getJndiContext() {
052            return context;
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("jndiContext", Context.class, false);
062            infoFactory.addAttribute("kernel", Kernel.class, false);
063            infoFactory.addAttribute("classLoader", ClassLoader.class, false);
064            infoFactory.addInterface(AppClientPlugin.class);
065    
066            infoFactory.setConstructor(new String[]{"context", "kernel", "classLoader"});
067    
068            GBEAN_INFO = infoFactory.getBeanInfo();
069        }
070    
071        public static GBeanInfo getGBeanInfo() {
072            return GBEAN_INFO;
073        }
074    }