001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    
021    package org.apache.geronimo.console.jmsmanager;
022    
023    import javax.enterprise.deploy.spi.DeploymentManager;
024    import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
025    import javax.enterprise.deploy.spi.factories.DeploymentFactory;
026    import javax.portlet.PortletRequest;
027    import javax.portlet.PortletSession;
028    
029    import org.apache.geronimo.console.util.PortletManager;
030    import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryWithKernel;
031    import org.apache.geronimo.kernel.Kernel;
032    
033    /**
034     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
035     */
036    public class ManagementHelper {
037        private final static String PLUGIN_HELPER_KEY = "org.apache.geronimo.console.activemq.ManagementHelper";
038        private final Kernel kernel;
039    
040        public static ManagementHelper getManagementHelper(PortletRequest request) {
041            ManagementHelper helper = (ManagementHelper) request.getPortletSession(true).getAttribute(PLUGIN_HELPER_KEY, PortletSession.APPLICATION_SCOPE);
042            if (helper == null) {
043                Kernel kernel = PortletManager.getKernel();
044                helper = new ManagementHelper(kernel);
045                request.getPortletSession().setAttribute(PLUGIN_HELPER_KEY, helper, PortletSession.APPLICATION_SCOPE);
046            }
047            return helper;
048        }
049    
050        public ManagementHelper(Kernel kernel) {
051            this.kernel = kernel;
052        }
053    
054        public DeploymentManager getDeploymentManager() {
055            DeploymentFactory factory = new DeploymentFactoryWithKernel(kernel);
056            try {
057                return factory.getDeploymentManager("deployer:geronimo:inVM", null, null);
058            } catch (DeploymentManagerCreationException e) {
059                //            log.error(e.getMessage(), e);
060                return null;
061            }
062        }
063    }
064