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: */package org.apache.geronimo.console.jmsmanager.handlers;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.util.List;
021:
022: import javax.jms.Queue;
023: import javax.jms.Topic;
024: import javax.management.ObjectName;
025: import javax.portlet.ActionRequest;
026: import javax.portlet.ActionResponse;
027: import javax.portlet.PortletException;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.apache.geronimo.console.core.jms.TopicBrowserGBean;
032: import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
033: import org.apache.geronimo.gbean.AbstractName;
034: import org.apache.geronimo.gbean.GBeanData;
035: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
036: import org.apache.geronimo.kernel.config.ConfigurationData;
037: import org.apache.geronimo.kernel.config.ConfigurationManager;
038: import org.apache.geronimo.kernel.config.ConfigurationUtil;
039: import org.apache.geronimo.kernel.repository.Artifact;
040: import org.apache.geronimo.kernel.repository.Dependency;
041: import org.apache.geronimo.kernel.repository.ImportType;
042:
043: public class CreateDestinationHandler extends AbstractJMSManager
044: implements PortletResponseHandler {
045: protected static Log log = LogFactory
046: .getLog(CreateDestinationHandler.class);
047:
048: private static final Artifact parentId = new Artifact("geronimo",
049: "activemq-broker",
050: org.apache.geronimo.system.serverinfo.ServerConstants
051: .getVersion(), "car");
052:
053: // static final GBeanInfo QUEUE_INFO;
054: //
055: // static final GBeanInfo TOPIC_INFO;
056: //
057: // static {
058: // GBeanInfoBuilder queueInfoBuilder = new GBeanInfoBuilder(
059: // AdminObjectWrapper.class, AdminObjectWrapperGBean.GBEAN_INFO);
060: // queueInfoBuilder.addAttribute(new DynamicGAttributeInfo("PhysicalName",
061: // String.class.getName(), true, true, true, true));
062: // QUEUE_INFO = queueInfoBuilder.getBeanInfo();
063: // GBeanInfoBuilder topicInfoBuilder = new GBeanInfoBuilder(
064: // AdminObjectWrapper.class, AdminObjectWrapperGBean.GBEAN_INFO);
065: // topicInfoBuilder.addAttribute(new DynamicGAttributeInfo("PhysicalName",
066: // String.class.getName(), true, true, true, true));
067: // TOPIC_INFO = topicInfoBuilder.getBeanInfo();
068: // }
069:
070: public void processAction(ActionRequest request,
071: ActionResponse response) throws IOException,
072: PortletException {
073: String destinationName = request.getParameter(DESTINATION_NAME);
074: String destinationPhysicalName = request
075: .getParameter(DESTINATION_PHYSICAL_NAME);
076: String destinationType = request.getParameter(DESTINATION_TYPE);
077: String destinationApplicationName = request
078: .getParameter(DESTINATION_APPLICATION_NAME);
079: String destinationModuleName = request
080: .getParameter(DESTINATION_MODULE_NAME);
081: try {
082:
083: Artifact configId = new Artifact(Artifact.DEFAULT_GROUP_ID,
084: BASE_CONFIG_URI + destinationName, "0", "car");
085: ConfigurationData configurationData = new ConfigurationData(
086: configId, kernel.getNaming());
087: configurationData.getEnvironment().addDependency(
088: new Dependency(ACTIVEMQ_ARTIFACT, ImportType.ALL));
089:
090: AbstractName adminObjectName = kernel.getNaming()
091: .createRootName(configId, destinationName,
092: NameFactory.JCA_ADMIN_OBJECT);
093: // ObjectName adminObjectName = NameFactory.getComponentName(null,
094: // null, destinationApplicationName, NameFactory.JCA_RESOURCE,
095: // destinationModuleName, destinationName, null, baseContext);
096:
097: GBeanData adminObjectData;
098: if (Topic.class.getName().equals(destinationType)) {
099: adminObjectData = getTopicGBeanData();
100: // If we are adding a topic we have to add a browser so we can view
101: // its messages later.
102: AbstractName browserName = kernel.getNaming()
103: .createChildName(adminObjectName,
104: destinationName, "TopicBrowser");
105: GBeanData tBrowserBeanData = new GBeanData(browserName,
106: TopicBrowserGBean.GBEAN_INFO);
107: tBrowserBeanData.setAttribute("subscriberName",
108: destinationName);
109: tBrowserBeanData.setReferencePattern(
110: "ConnectionFactoryWrapper",
111: JCA_MANAGED_CONNECTION_FACTORY_NAME);
112: tBrowserBeanData.setReferencePattern("TopicWrapper",
113: adminObjectName);
114:
115: configurationData.addGBean(tBrowserBeanData);
116: } else if (Queue.class.getName().equals(destinationType)) {
117: adminObjectData = getQueueGBeanData();
118: } else {
119: throw new PortletException(
120: "Invalid choice destination, must be FQCL of Topic or Queue, not "
121: + destinationType);
122: }
123: adminObjectData.setAbstractName(adminObjectName);
124: adminObjectData.setAttribute("PhysicalName",
125: destinationPhysicalName);
126: configurationData.addGBean(adminObjectData);
127:
128: ConfigurationManager configurationManager = ConfigurationUtil
129: .getConfigurationManager(kernel);
130: List stores = configurationManager.listStores();
131: if (stores.isEmpty()) {
132: throw new PortletException("No configuration store");
133: }
134: ObjectName storeName = (ObjectName) stores.get(0);
135: File installDir = (File) kernel.invoke(storeName,
136: "createNewConfigurationDir");
137: // Environment environment = new Environment();
138: // environment.setConfigId(configId);
139: // environment.addDependency(parentId, ImportType.ALL);
140: // List gbeans = new ArrayList();
141: // gbeans.add(adminObjectData);
142: //TODO configid FIXME set configurationDir correctly
143: File configurationDir = null;
144: // ConfigurationData configData = new ConfigurationData(ConfigurationModuleType.SERVICE,
145: // new LinkedHashSet(),
146: // gbeans,
147: // Collections.EMPTY_LIST,
148: // environment, configurationDir,
149: // kernel.getNaming());
150:
151: //saves it.
152: //deploymentContext.close();
153: kernel.invoke(storeName, "install", new Object[] {
154: configurationData, installDir }, new String[] {
155: ConfigurationData.class.getName(),
156: File.class.getName() });
157:
158: configurationManager.loadConfiguration(configId);
159: configurationManager.startConfiguration(configId);
160:
161: } catch (Exception e) {
162: log.error("problem", e);
163: }
164: response
165: .setRenderParameter("processAction", "viewDestinations");
166: }
167:
168: }
|