KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.jms.Queue JavaDoc;
25 import javax.jms.Topic JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import javax.portlet.ActionRequest;
28 import javax.portlet.ActionResponse;
29 import javax.portlet.PortletException;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.apache.geronimo.console.core.jms.TopicBrowserGBean;
34 import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
35 import org.apache.geronimo.gbean.AbstractName;
36 import org.apache.geronimo.gbean.GBeanData;
37 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
38 import org.apache.geronimo.kernel.config.ConfigurationData;
39 import org.apache.geronimo.kernel.config.ConfigurationManager;
40 import org.apache.geronimo.kernel.config.ConfigurationUtil;
41 import org.apache.geronimo.kernel.repository.Artifact;
42 import org.apache.geronimo.kernel.repository.Dependency;
43 import org.apache.geronimo.kernel.repository.ImportType;
44
45 public class CreateDestinationHandler extends AbstractJMSManager implements PortletResponseHandler {
46     protected static Log log = LogFactory
47             .getLog(CreateDestinationHandler.class);
48
49     private static final Artifact parentId = new Artifact("geronimo", "activemq-broker", org.apache.geronimo.system.serverinfo.ServerConstants.getVersion(), "car");
50
51 // static final GBeanInfo QUEUE_INFO;
52
//
53
// static final GBeanInfo TOPIC_INFO;
54
//
55
// static {
56
// GBeanInfoBuilder queueInfoBuilder = new GBeanInfoBuilder(
57
// AdminObjectWrapper.class, AdminObjectWrapperGBean.GBEAN_INFO);
58
// queueInfoBuilder.addAttribute(new DynamicGAttributeInfo("PhysicalName",
59
// String.class.getName(), true, true, true, true));
60
// QUEUE_INFO = queueInfoBuilder.getBeanInfo();
61
// GBeanInfoBuilder topicInfoBuilder = new GBeanInfoBuilder(
62
// AdminObjectWrapper.class, AdminObjectWrapperGBean.GBEAN_INFO);
63
// topicInfoBuilder.addAttribute(new DynamicGAttributeInfo("PhysicalName",
64
// String.class.getName(), true, true, true, true));
65
// TOPIC_INFO = topicInfoBuilder.getBeanInfo();
66
// }
67

68     public void processAction(ActionRequest request, ActionResponse response)
69             throws IOException JavaDoc, PortletException {
70         String JavaDoc destinationName = request.getParameter(DESTINATION_NAME);
71         String JavaDoc destinationPhysicalName = request
72                 .getParameter(DESTINATION_PHYSICAL_NAME);
73         String JavaDoc destinationType = request.getParameter(DESTINATION_TYPE);
74         String JavaDoc destinationApplicationName = request
75                 .getParameter(DESTINATION_APPLICATION_NAME);
76         String JavaDoc destinationModuleName = request
77                 .getParameter(DESTINATION_MODULE_NAME);
78         try {
79
80             Artifact configId = new Artifact(Artifact.DEFAULT_GROUP_ID, BASE_CONFIG_URI + destinationName, "0", "car");
81             ConfigurationData configurationData = new ConfigurationData(configId, kernel.getNaming());
82             configurationData.getEnvironment().addDependency(new Dependency(ACTIVEMQ_ARTIFACT, ImportType.ALL));
83
84             AbstractName adminObjectName = kernel.getNaming().createRootName(configId, destinationName, NameFactory.JCA_ADMIN_OBJECT);
85 // ObjectName adminObjectName = NameFactory.getComponentName(null,
86
// null, destinationApplicationName, NameFactory.JCA_RESOURCE,
87
// destinationModuleName, destinationName, null, baseContext);
88

89             GBeanData adminObjectData;
90             if (Topic JavaDoc.class.getName().equals(destinationType)) {
91                 adminObjectData = getTopicGBeanData();
92                 // If we are adding a topic we have to add a browser so we can view
93
// its messages later.
94
AbstractName browserName = kernel.getNaming().createChildName(adminObjectName, destinationName, "TopicBrowser");
95                 GBeanData tBrowserBeanData = new GBeanData(browserName, TopicBrowserGBean.GBEAN_INFO);
96                 tBrowserBeanData.setAttribute("subscriberName", destinationName);
97                 tBrowserBeanData.setReferencePattern("ConnectionFactoryWrapper", JCA_MANAGED_CONNECTION_FACTORY_NAME);
98                 tBrowserBeanData.setReferencePattern("TopicWrapper",
99                         adminObjectName);
100
101                 configurationData.addGBean(tBrowserBeanData);
102             } else if (Queue JavaDoc.class.getName().equals(destinationType)) {
103                 adminObjectData = getQueueGBeanData();
104             } else {
105                 throw new PortletException(
106                         "Invalid choice destination, must be FQCL of Topic or Queue, not "
107                                 + destinationType);
108             }
109             adminObjectData.setAbstractName(adminObjectName);
110             adminObjectData.setAttribute("PhysicalName",
111                     destinationPhysicalName);
112             configurationData.addGBean(adminObjectData);
113
114
115             ConfigurationManager configurationManager = ConfigurationUtil
116                     .getConfigurationManager(kernel);
117             List JavaDoc stores = configurationManager.listStores();
118             assert stores.size() == 1 : "Piling one hack on another, this code only works with exactly one store";
119
120             ObjectName JavaDoc storeName = (ObjectName JavaDoc) stores.iterator().next();
121             File JavaDoc installDir = (File JavaDoc) kernel.invoke(storeName,
122                     "createNewConfigurationDir");
123 // Environment environment = new Environment();
124
// environment.setConfigId(configId);
125
// environment.addDependency(parentId, ImportType.ALL);
126
// List gbeans = new ArrayList();
127
// gbeans.add(adminObjectData);
128
//TODO configid FIXME set configurationDir correctly
129
File JavaDoc configurationDir = null;
130 // ConfigurationData configData = new ConfigurationData(ConfigurationModuleType.SERVICE,
131
// new LinkedHashSet(),
132
// gbeans,
133
// Collections.EMPTY_LIST,
134
// environment, configurationDir,
135
// kernel.getNaming());
136

137             //saves it.
138
//deploymentContext.close();
139
kernel.invoke(storeName, "install", new Object JavaDoc[] {configurationData, installDir},
140                     new String JavaDoc[] {ConfigurationData.class.getName(), File JavaDoc.class.getName() });
141
142             configurationManager.loadConfiguration(configId);
143             configurationManager.startConfiguration(configId);
144
145         } catch (Exception JavaDoc e) {
146             log.error("problem", e);
147         }
148         response.setRenderParameter("processAction", "viewDestinations");
149     }
150
151 }
152
Popular Tags