KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > jmsmanager > handlers > RemoveDestinationHandler


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17
18 package org.apache.geronimo.console.jmsmanager.handlers;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URI JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.management.ObjectName JavaDoc;
26 import javax.portlet.ActionRequest;
27 import javax.portlet.ActionResponse;
28 import javax.portlet.PortletException;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
33 import org.apache.geronimo.gbean.GBeanData;
34 import org.apache.geronimo.gbean.AbstractName;
35 import org.apache.geronimo.kernel.DependencyManager;
36 import org.apache.geronimo.kernel.repository.Artifact;
37 import org.apache.geronimo.kernel.config.Configuration;
38 import org.apache.geronimo.kernel.config.ConfigurationManager;
39 import org.apache.geronimo.kernel.config.ConfigurationUtil;
40
41 public class RemoveDestinationHandler extends AbstractJMSManager implements
42         PortletResponseHandler {
43
44     protected static Log log = LogFactory
45             .getLog(RemoveDestinationHandler.class);
46
47     public void processAction(ActionRequest request, ActionResponse response)
48             throws IOException JavaDoc, PortletException {
49         String JavaDoc destinationConfigURIName = request
50                 .getParameter(DESTINATION_CONFIG_URI);
51         try {
52             ConfigurationManager configurationManager = ConfigurationUtil
53                     .getConfigurationManager(kernel);
54             Artifact destinationConfigArtifact = Artifact.create(destinationConfigURIName);
55             AbstractName configurationObjectName = Configuration.getConfigurationAbstractName(destinationConfigArtifact);
56
57             List JavaDoc stores = configurationManager.listStores();
58             assert stores.size() == 1 :"Piling one hack on another, this code only works with exactly one store";
59             ObjectName JavaDoc storeName = (ObjectName JavaDoc) stores.iterator().next();
60
61             // Unsubscribe topicbrowser before uninstalling the configuration.
62
DependencyManager dm = kernel.getDependencyManager();
63             //GBeanData topicBrowser = (GBeanData) kernel.invoke(storeName,
64
// "getConfiguration", new Object[]{destinationConfigURI}, new
65
// String[]{URI.class.getName()});
66
GBeanData topicBrowser = kernel.getGBeanData(configurationObjectName);
67             java.util.Set JavaDoc children = dm.getChildren(topicBrowser.getAbstractName());
68             for (Iterator JavaDoc i = children.iterator(); i.hasNext();) {
69                 ObjectName JavaDoc o = (ObjectName JavaDoc) i.next();
70                 if ("TopicBrowser".equals(o.getKeyProperty("j2eeType"))) {
71                     kernel.invoke(o, "unsubscribe");
72                     break;
73                 }
74             }
75
76             // Uninstall configuration
77
//kernel.stopConfiguration(destinationConfigURI);
78
kernel.stopGBean(configurationObjectName);
79             kernel.invoke(storeName, "uninstall",
80                     new Object JavaDoc[] {destinationConfigArtifact},
81                     new String JavaDoc[] {URI JavaDoc.class.getName()});
82         } catch (Exception JavaDoc e) {
83             log.error("problem removing destination: "
84                     + destinationConfigURIName, e);
85         }
86     }
87
88 }
89
Popular Tags