001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: PresentTopicAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.jms;
027:
028: import java.io.IOException;
029: import java.util.ArrayList;
030: import java.util.Collections;
031:
032: import javax.management.ObjectName;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import org.apache.struts.action.ActionForm;
038: import org.apache.struts.action.ActionForward;
039: import org.apache.struts.action.ActionMapping;
040: import org.objectweb.jonas.jmx.JonasManagementRepr;
041: import org.objectweb.jonas.jmx.JonasObjectName;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
043: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
044: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
045: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
046:
047: /**
048: * Action presenting a given JMS Topic destination's attributes.
049: * @author Adriana Danes
050: */
051: public class PresentTopicAction extends JonasBaseAction {
052: /**
053: */
054: public ActionForward executeAction(ActionMapping p_Mapping,
055: ActionForm p_Form, HttpServletRequest p_Request,
056: HttpServletResponse p_Response) throws IOException,
057: ServletException {
058:
059: // Selected Topic
060: String topicName = p_Request.getParameter("name");
061:
062: // Form used
063: TopicForm oForm = null;
064: if (topicName != null) {
065: // Build a new form
066: oForm = new TopicForm();
067: oForm.reset(p_Mapping, p_Request);
068: m_Session.setAttribute("topicForm", oForm);
069: oForm.setName(topicName);
070: } else {
071: // Used last form in session
072: oForm = (TopicForm) m_Session.getAttribute("topicForm");
073: }
074:
075: // Force the node selected in tree
076: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
077: + WhereAreYou.NODE_SEPARATOR + "services"
078: + WhereAreYou.NODE_SEPARATOR + "jms"
079: + WhereAreYou.NODE_SEPARATOR + "topic"
080: + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true);
081:
082: // Current server
083: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
084: .getAttribute(WhereAreYou.SESSION_NAME);
085: String jonasServerName = oWhere.getCurrentJonasServerName();
086:
087: // Populuate
088: try {
089: if (topicName != null) {
090: ArrayList al = new ArrayList();
091: String[] asParam = new String[1];
092: String[] asSignature = new String[1];
093: asSignature[0] = "java.lang.String";
094: asParam[0] = topicName;
095: ObjectName ejbServiceMB = JonasObjectName.ejbService();
096: if (JonasManagementRepr.isRegistered(ejbServiceMB,
097: jonasServerName)) {
098: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
099: .invoke(ejbServiceMB,
100: "getJmsDestinationDependence",
101: asParam, asSignature,
102: jonasServerName)).iterator();
103: while (it.hasNext()) {
104: al.add(new EjbItem((ObjectName) it.next(),
105: jonasServerName));
106: }
107: // Sort by name
108: Collections.sort(al, new EjbItemByNameComparator());
109: }
110: // Set list in form
111: oForm.setListUsedByEjb(al);
112:
113: // Set monitoting info
114: ObjectName jmsServiceMB = JonasObjectName.jmsService();
115: int subscriptions = ((Integer) JonasManagementRepr
116: .invoke(jmsServiceMB, "getSubscriptions",
117: asParam, asSignature, jonasServerName))
118: .intValue();
119: oForm.setSubscriptions(subscriptions);
120: }
121: } catch (Throwable t) {
122: addGlobalError(t);
123: saveErrors(p_Request, m_Errors);
124: return (p_Mapping.findForward("Global Error"));
125: }
126:
127: // Forward to the jsp.
128: return (p_Mapping.findForward("Topic"));
129: }
130: }
|