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 assert stores.size() == 1 :"Piling one hack on another, this code only works with exactly one store";
059 ObjectName storeName = (ObjectName) stores.iterator().next();
060
061 // Unsubscribe topicbrowser before uninstalling the configuration.
062 DependencyManager dm = kernel.getDependencyManager();
063 //GBeanData topicBrowser = (GBeanData) kernel.invoke(storeName,
064 // "getConfiguration", new Object[]{destinationConfigURI}, new
065 // String[]{URI.class.getName()});
066 GBeanData topicBrowser = kernel.getGBeanData(configurationObjectName);
067 java.util.Set children = dm.getChildren(topicBrowser.getAbstractName());
068 for (Iterator i = children.iterator(); i.hasNext();) {
069 ObjectName o = (ObjectName) i.next();
070 if ("TopicBrowser".equals(o.getKeyProperty("j2eeType"))) {
071 kernel.invoke(o, "unsubscribe");
072 break;
073 }
074 }
075
076 // Uninstall configuration
077 //kernel.stopConfiguration(destinationConfigURI);
078 kernel.stopGBean(configurationObjectName);
079 kernel.invoke(storeName, "uninstall",
080 new Object[] {destinationConfigArtifact},
081 new String[] {URI.class.getName()});
082 } catch (Exception e) {
083 log.error("problem removing destination: "
084 + destinationConfigURIName, e);
085 }
086 }
087
088 }