01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.console.jmsmanager.handlers;
17:
18: import java.io.IOException;
19: import java.net.URI;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import javax.management.ObjectName;
24: import javax.portlet.ActionRequest;
25: import javax.portlet.ActionResponse;
26: import javax.portlet.PortletException;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
31: import org.apache.geronimo.gbean.GBeanData;
32: import org.apache.geronimo.gbean.AbstractName;
33: import org.apache.geronimo.kernel.DependencyManager;
34: import org.apache.geronimo.kernel.repository.Artifact;
35: import org.apache.geronimo.kernel.config.Configuration;
36: import org.apache.geronimo.kernel.config.ConfigurationManager;
37: import org.apache.geronimo.kernel.config.ConfigurationUtil;
38:
39: public class RemoveDestinationHandler extends AbstractJMSManager
40: implements PortletResponseHandler {
41:
42: protected static Log log = LogFactory
43: .getLog(RemoveDestinationHandler.class);
44:
45: public void processAction(ActionRequest request,
46: ActionResponse response) throws IOException,
47: PortletException {
48: String destinationConfigURIName = request
49: .getParameter(DESTINATION_CONFIG_URI);
50: try {
51: ConfigurationManager configurationManager = ConfigurationUtil
52: .getConfigurationManager(kernel);
53: Artifact destinationConfigArtifact = Artifact
54: .create(destinationConfigURIName);
55: AbstractName configurationObjectName = Configuration
56: .getConfigurationAbstractName(destinationConfigArtifact);
57:
58: List stores = configurationManager.listStores();
59: if (stores.isEmpty()) {
60: throw new PortletException("No configuration store");
61: }
62: ObjectName storeName = (ObjectName) stores.get(0);
63:
64: // Unsubscribe topicbrowser before uninstalling the configuration.
65: DependencyManager dm = kernel.getDependencyManager();
66: //GBeanData topicBrowser = (GBeanData) kernel.invoke(storeName,
67: // "getConfiguration", new Object[]{destinationConfigURI}, new
68: // String[]{URI.class.getName()});
69: GBeanData topicBrowser = kernel
70: .getGBeanData(configurationObjectName);
71: java.util.Set children = dm.getChildren(topicBrowser
72: .getAbstractName());
73: for (Iterator i = children.iterator(); i.hasNext();) {
74: ObjectName o = (ObjectName) i.next();
75: if ("TopicBrowser".equals(o.getKeyProperty("j2eeType"))) {
76: kernel.invoke(o, "unsubscribe");
77: break;
78: }
79: }
80:
81: // Uninstall configuration
82: //kernel.stopConfiguration(destinationConfigURI);
83: kernel.stopGBean(configurationObjectName);
84: kernel.invoke(storeName, "uninstall",
85: new Object[] { destinationConfigArtifact },
86: new String[] { URI.class.getName() });
87: } catch (Exception e) {
88: log.error("problem removing destination: "
89: + destinationConfigURIName, e);
90: }
91: }
92:
93: }
|