KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > jms > PresentConnectionFactoryAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: PresentConnectionFactoryAction.java,v 1.5 2004/03/19 14:31:48 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.jms;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.JonasManagementRepr;
41 import org.objectweb.jonas.jmx.JonasObjectName;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
44 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
45 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
46
47 /**
48  * Action presenting a given JMS Connection Factory's attributes.
49  * @author Adriana Danes
50  */

51 public class PresentConnectionFactoryAction extends JonasBaseAction {
52     /**
53      */

54     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
55         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
56         throws IOException JavaDoc, ServletException JavaDoc {
57
58         // Selected Connection Factory
59
String JavaDoc cfName = p_Request.getParameter("name");
60
61         // Form used
62
CfForm oForm = null;
63         if (cfName != null) {
64             // Build a new form
65
oForm = new CfForm();
66             oForm.reset(p_Mapping, p_Request);
67             m_Session.setAttribute("cfForm", oForm);
68             oForm.setName(cfName);
69         }
70         else {
71             // Used last form in session
72
oForm = (CfForm) m_Session.getAttribute("cfForm");
73         }
74
75         // Force the node selected in tree
76
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
77             + "services" + WhereAreYou.NODE_SEPARATOR + "jms" + WhereAreYou.NODE_SEPARATOR + "cf"
78             + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true);
79
80         // Populuate
81
try {
82             if (cfName != null) {
83                 ArrayList JavaDoc al = new ArrayList JavaDoc();
84                 String JavaDoc[] asParam = new String JavaDoc[1];
85                 String JavaDoc[] asSignature = new String JavaDoc[1];
86                 asSignature[0] = "java.lang.String";
87                 asParam[0] = cfName;
88                 ObjectName JavaDoc ejbServiceMB = JonasObjectName.ejbService();
89                 if (JonasManagementRepr.isRegistered(ejbServiceMB)) {
90                     java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(
91                         ejbServiceMB, "getJmsConnectionFactoryDependence", asParam
92                         , asSignature)).iterator();
93                     while (it.hasNext()) {
94                         al.add(new EjbItem((ObjectName JavaDoc) it.next()));
95                     }
96                     // Sort by name
97
Collections.sort(al, new EjbItemByNameComparator());
98                 }
99                 // Set list in form
100
oForm.setListUsedByEjb(al);
101
102                 // Set monitoting info
103
ObjectName JavaDoc jmsServiceMB = JonasObjectName.jmsService();
104                 String JavaDoc mode = (String JavaDoc) JonasManagementRepr.invoke(jmsServiceMB
105                     , "getConnectionFactoryMode", asParam, asSignature);
106                 oForm.setMode(mode);
107             }
108         }
109         catch (Throwable JavaDoc t) {
110             addGlobalError(t);
111             saveErrors(p_Request, m_Errors);
112             return (p_Mapping.findForward("Global Error"));
113         }
114
115         // Forward to the jsp.
116
return (p_Mapping.findForward("Connection Factory"));
117     }
118 }
119
Popular Tags