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.wizard;
017:
018: import java.io.IOException;
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collections;
022: import java.util.List;
023: import javax.management.MalformedObjectNameException;
024: import javax.management.ObjectName;
025: import javax.portlet.ActionRequest;
026: import javax.portlet.ActionResponse;
027: import javax.portlet.PortletException;
028: import javax.portlet.PortletRequest;
029: import javax.portlet.RenderRequest;
030: import javax.portlet.RenderResponse;
031:
032: import org.apache.geronimo.console.MultiPageModel;
033: import org.apache.geronimo.console.util.PortletManager;
034: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
035: import org.apache.geronimo.kernel.management.State;
036: import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
037: import org.apache.geronimo.management.geronimo.JCAAdminObject;
038: import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
039: import org.apache.geronimo.management.geronimo.JCAResource;
040: import org.apache.geronimo.management.geronimo.ResourceAdapter;
041: import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: /**
046: * A handles for the front page that lists available resources.
047: *
048: * @version $Rev: 476061 $ $Date: 2006-11-16 22:36:50 -0800 (Thu, 16 Nov 2006) $
049: */
050: public class ListScreenHandler extends AbstractHandler {
051: private static final Log log = LogFactory
052: .getLog(ListScreenHandler.class);
053:
054: public ListScreenHandler() {
055: super (LIST_MODE, "/WEB-INF/view/jmswizard/list.jsp");
056: }
057:
058: public String actionBeforeView(ActionRequest request,
059: ActionResponse response, MultiPageModel model)
060: throws PortletException, IOException {
061: return getMode();
062: }
063:
064: public void renderView(RenderRequest request,
065: RenderResponse response, MultiPageModel model)
066: throws PortletException, IOException {
067: populateExistingList(request);
068: }
069:
070: public String actionAfterView(ActionRequest request,
071: ActionResponse response, MultiPageModel model)
072: throws PortletException, IOException {
073: JMSResourceData data = (JMSResourceData) model;
074: String provider = request.getParameter(PROVIDER_PARAMETER);
075: if (isEmpty(provider)) {
076: return SELECT_PROVIDER_MODE + BEFORE_ACTION;
077: }
078: JMSProviderData providerData = JMSProviderData
079: .getProviderByName(provider);
080: data.setRarURI(providerData.getRaURI());
081: data.setDependency(providerData.getDependency());
082: return CONFIGURE_RA_MODE + BEFORE_ACTION;
083: }
084:
085: private void populateExistingList(PortletRequest renderRequest) {
086: // Prepare a list of JMS configurations
087: List resources = new ArrayList();
088:
089: // Get the list of connection factories
090: ResourceAdapterModule[] modules = PortletManager
091: .getOutboundRAModules(renderRequest, new String[] {
092: "javax.jms.ConnectionFactory",
093: "javax.jms.QueueConnectionFactory",
094: "javax.jms.TopicConnectionFactory", });
095: try {
096: for (int i = 0; i < modules.length; i++) {
097: ResourceAdapterModule module = modules[i];
098:
099: JMSResourceSummary target = null;
100: for (int j = 0; j < resources.size(); j++) {
101: JMSResourceSummary data = (JMSResourceSummary) resources
102: .get(j);
103: if (data.adapterObjectName.equals(module
104: .getObjectName())) {
105: target = data;
106: break;
107: }
108: }
109: if (target == null) {
110: ResourceAdapter[] adapters = PortletManager
111: .getResourceAdapters(renderRequest, module);
112: String name = null;
113: if (adapters.length == 1
114: && adapters[0].getJCAResources().length == 1) {
115: JCAResource[] resource = PortletManager
116: .getJCAResources(renderRequest,
117: adapters[0]);
118: if (resource.length == 1
119: && resource[0]
120: .getResourceAdapterInstances().length == 1) {
121: name = ObjectName
122: .getInstance(
123: resource[0]
124: .getResourceAdapterInstanceNames()[0])
125: .getKeyProperty(
126: NameFactory.J2EE_NAME);
127: }
128: }
129: if (name == null) {
130: name = ObjectName.getInstance(
131: module.getObjectName()).getKeyProperty(
132: NameFactory.J2EE_NAME);
133: }
134: target = new JMSResourceSummary(PortletManager
135: .getConfigurationFor(
136: renderRequest,
137: PortletManager.getNameFor(
138: renderRequest, module))
139: .toString(), module.getObjectName(), name,
140: ((GeronimoManagedBean) module).getState());
141: resources.add(target);
142: }
143:
144: JCAManagedConnectionFactory[] factories = PortletManager
145: .getOutboundFactoriesForRA(
146: renderRequest,
147: module,
148: new String[] {
149: "javax.jms.ConnectionFactory",
150: "javax.jms.QueueConnectionFactory",
151: "javax.jms.TopicConnectionFactory", });
152: for (int j = 0; j < factories.length; j++) {
153: JCAManagedConnectionFactory factory = factories[j];
154: ObjectName name = ObjectName.getInstance(factory
155: .getObjectName());
156: target
157: .getConnectionFactories()
158: .add(
159: new ConnectionFactorySummary(
160: factory.getObjectName(),
161: name
162: .getKeyProperty(NameFactory.J2EE_NAME),
163: ((GeronimoManagedBean) factory)
164: .getState()));
165: }
166: }
167:
168: // Get the list of admin objects
169: modules = PortletManager.getAdminObjectModules(
170: renderRequest, new String[] { "javax.jms.Queue",
171: "javax.jms.Topic" });
172: for (int i = 0; i < modules.length; i++) {
173: ResourceAdapterModule module = modules[i];
174:
175: JMSResourceSummary target = null;
176: for (int j = 0; j < resources.size(); j++) {
177: JMSResourceSummary data = (JMSResourceSummary) resources
178: .get(j);
179: if (data.adapterObjectName.equals(module
180: .getObjectName())) {
181: target = data;
182: break;
183: }
184: }
185: if (target == null) {
186: ResourceAdapter[] adapters = PortletManager
187: .getResourceAdapters(renderRequest, module);
188: String name = null;
189: if (adapters.length == 1
190: && adapters[0].getJCAResources().length == 1) {
191: JCAResource[] resource = PortletManager
192: .getJCAResources(renderRequest,
193: adapters[0]);
194: if (resource.length == 1
195: && resource[0]
196: .getResourceAdapterInstances().length == 1) {
197: name = ObjectName
198: .getInstance(
199: resource[0]
200: .getResourceAdapterInstanceNames()[0])
201: .getKeyProperty(
202: NameFactory.J2EE_NAME);
203: }
204: }
205: if (name == null) {
206: name = ObjectName.getInstance(
207: module.getObjectName()).getKeyProperty(
208: NameFactory.J2EE_NAME);
209: }
210: target = new JMSResourceSummary(PortletManager
211: .getConfigurationFor(
212: renderRequest,
213: PortletManager.getNameFor(
214: renderRequest, module))
215: .toString(), module.getObjectName(), name,
216: ((GeronimoManagedBean) module).getState());
217: resources.add(target);
218: }
219:
220: JCAAdminObject[] admins = PortletManager
221: .getAdminObjectsForRA(renderRequest, module,
222: new String[] { "javax.jms.Queue",
223: "javax.jms.Topic" });
224: for (int j = 0; j < admins.length; j++) {
225: GeronimoManagedBean bean = (GeronimoManagedBean) admins[j];
226: ObjectName name = ObjectName.getInstance(bean
227: .getObjectName());
228: target
229: .getAdminObjects()
230: .add(
231: new AdminObjectSummary(
232: bean.getObjectName(),
233: name
234: .getKeyProperty(NameFactory.J2EE_NAME),
235: admins[j]
236: .getAdminObjectInterface()
237: .indexOf("Queue") > -1 ? "Queue"
238: : "Topic", bean
239: .getState()));
240: }
241: }
242: } catch (MalformedObjectNameException e) {
243: log.error(e.getMessage(), e);
244: }
245:
246: Collections.sort(resources);
247: renderRequest.setAttribute("resources", resources);
248: // Get the list of JMS providers
249: renderRequest.setAttribute("providers", JMSProviderData
250: .getAllProviders());
251: }
252:
253: public static class JMSResourceSummary implements Serializable,
254: Comparable {
255: private static final long serialVersionUID = -2788803234448047035L;
256: private final String configurationName;
257: private final String adapterObjectName;
258: private final String name;
259: private final String parentName;
260: private final int state;
261: private final List connectionFactories = new ArrayList();
262: private final List adminObjects = new ArrayList();
263:
264: public JMSResourceSummary(String configurationName,
265: String adapterObjectName, String name, int state) {
266: this .configurationName = configurationName;
267: this .adapterObjectName = adapterObjectName;
268: this .state = state;
269: try {
270: ObjectName objectName = ObjectName
271: .getInstance(adapterObjectName);
272: String parent = objectName
273: .getKeyProperty(NameFactory.J2EE_APPLICATION);
274: if (parent != null && parent.equals("null")) {
275: parent = null;
276: }
277: parentName = parent;
278: this .name = name;
279: } catch (MalformedObjectNameException e) {
280: throw new RuntimeException("Can't parse ObjectName", e);
281: }
282: }
283:
284: public String getConfigurationName() {
285: return configurationName;
286: }
287:
288: public String getAdapterObjectName() {
289: return adapterObjectName;
290: }
291:
292: public String getName() {
293: return name;
294: }
295:
296: public String getParentName() {
297: return parentName;
298: }
299:
300: public int getState() {
301: return state;
302: }
303:
304: public List getConnectionFactories() {
305: return connectionFactories;
306: }
307:
308: public List getAdminObjects() {
309: return adminObjects;
310: }
311:
312: public String getStateName() {
313: return State.toString(state);
314: }
315:
316: public int compareTo(Object o) {
317: final JMSResourceSummary pool = (JMSResourceSummary) o;
318: int names = name.toLowerCase().compareTo(
319: pool.name.toLowerCase());
320: if (parentName == null) {
321: if (pool.parentName == null) {
322: return names;
323: } else {
324: return -1;
325: }
326: } else {
327: if (pool.parentName == null) {
328: return 1;
329: } else {
330: int test = parentName.compareTo(pool.parentName);
331: if (test != 0) {
332: return test;
333: } else {
334: return names;
335: }
336: }
337: }
338: }
339: }
340:
341: public static class ConnectionFactorySummary implements
342: Serializable, Comparable {
343: private static final long serialVersionUID = 5777507920880039759L;
344: private final String factoryObjectName;
345: private final String name;
346: private final int state;
347:
348: public ConnectionFactorySummary(String factoryObjectName,
349: String name, int state) {
350: this .factoryObjectName = factoryObjectName;
351: this .name = name;
352: this .state = state;
353: }
354:
355: public String getFactoryObjectName() {
356: return factoryObjectName;
357: }
358:
359: public String getName() {
360: return name;
361: }
362:
363: public int getState() {
364: return state;
365: }
366:
367: public String getStateName() {
368: return State.toString(state);
369: }
370:
371: public int compareTo(Object o) {
372: final ConnectionFactorySummary pool = (ConnectionFactorySummary) o;
373: return name.compareTo(pool.name);
374: }
375: }
376:
377: public static class AdminObjectSummary implements Serializable,
378: Comparable {
379: private static final long serialVersionUID = 3941332145785485903L;
380: private final String adminObjectName;
381: private final String name;
382: private final String type;
383: private final int state;
384:
385: public AdminObjectSummary(String adminObjectName, String name,
386: String type, int state) {
387: this .adminObjectName = adminObjectName;
388: this .name = name;
389: this .type = type;
390: this .state = state;
391: }
392:
393: public String getAdminObjectName() {
394: return adminObjectName;
395: }
396:
397: public String getName() {
398: return name;
399: }
400:
401: public String getType() {
402: return type;
403: }
404:
405: public int getState() {
406: return state;
407: }
408:
409: public String getStateName() {
410: return State.toString(state);
411: }
412:
413: public int compareTo(Object o) {
414: final AdminObjectSummary pool = (AdminObjectSummary) o;
415: int result = name.compareTo(pool.name);
416: return result == 0 ? type.compareTo(pool.type) : result;
417: }
418: }
419: }
|