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 018 package org.apache.geronimo.console.jmsmanager.handlers; 019 020 import java.io.IOException; 021 import java.net.URI; 022 import java.util.Iterator; 023 import java.util.List; 024 025 import javax.management.ObjectName; 026 import javax.portlet.ActionRequest; 027 import javax.portlet.ActionResponse; 028 import javax.portlet.PortletException; 029 030 import org.apache.commons.logging.Log; 031 import org.apache.commons.logging.LogFactory; 032 import org.apache.geronimo.console.jmsmanager.AbstractJMSManager; 033 import org.apache.geronimo.gbean.GBeanData; 034 import org.apache.geronimo.gbean.AbstractName; 035 import org.apache.geronimo.kernel.DependencyManager; 036 import org.apache.geronimo.kernel.repository.Artifact; 037 import org.apache.geronimo.kernel.config.Configuration; 038 import org.apache.geronimo.kernel.config.ConfigurationManager; 039 import org.apache.geronimo.kernel.config.ConfigurationUtil; 040 041 public class RemoveDestinationHandler extends AbstractJMSManager implements 042 PortletResponseHandler { 043 044 protected static Log log = LogFactory 045 .getLog(RemoveDestinationHandler.class); 046 047 public void processAction(ActionRequest request, ActionResponse response) 048 throws IOException, PortletException { 049 String destinationConfigURIName = request 050 .getParameter(DESTINATION_CONFIG_URI); 051 try { 052 ConfigurationManager configurationManager = ConfigurationUtil 053 .getConfigurationManager(kernel); 054 Artifact destinationConfigArtifact = Artifact.create(destinationConfigURIName); 055 AbstractName configurationObjectName = Configuration.getConfigurationAbstractName(destinationConfigArtifact); 056 057 List stores = configurationManager.listStores(); 058 if (stores.isEmpty()) { 059 throw new PortletException("No configuration store"); 060 } 061 ObjectName storeName = (ObjectName) stores.get(0); 062 063 // Unsubscribe topicbrowser before uninstalling the configuration. 064 DependencyManager dm = kernel.getDependencyManager(); 065 //GBeanData topicBrowser = (GBeanData) kernel.invoke(storeName, 066 // "getConfiguration", new Object[]{destinationConfigURI}, new 067 // String[]{URI.class.getName()}); 068 GBeanData topicBrowser = kernel.getGBeanData(configurationObjectName); 069 java.util.Set children = dm.getChildren(topicBrowser.getAbstractName()); 070 for (Iterator i = children.iterator(); i.hasNext();) { 071 ObjectName o = (ObjectName) i.next(); 072 if ("TopicBrowser".equals(o.getKeyProperty("j2eeType"))) { 073 kernel.invoke(o, "unsubscribe"); 074 break; 075 } 076 } 077 078 // Uninstall configuration 079 //kernel.stopConfiguration(destinationConfigURI); 080 kernel.stopGBean(configurationObjectName); 081 kernel.invoke(storeName, "uninstall", 082 new Object[] {destinationConfigArtifact}, 083 new String[] {URI.class.getName()}); 084 } catch (Exception e) { 085 log.error("problem removing destination: " 086 + destinationConfigURIName, e); 087 } 088 } 089 090 }