01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999-2004 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: ListDatasourcesAction.java 9680 2006-10-06 12:08:33Z danesa $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.jonas.webapp.jonasadmin.resource;
25:
26: import java.io.IOException;
27: import java.util.ArrayList;
28: import java.util.Collections;
29: import java.util.Iterator;
30:
31: import javax.servlet.ServletException;
32: import javax.servlet.http.HttpServletRequest;
33: import javax.servlet.http.HttpServletResponse;
34:
35: import org.apache.struts.action.ActionForm;
36: import org.apache.struts.action.ActionForward;
37: import org.apache.struts.action.ActionMapping;
38: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
39: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
40: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
41: import org.objectweb.jonas.webapp.jonasadmin.service.db.DatasourceItem;
42: import org.objectweb.jonas.webapp.jonasadmin.service.db.DatasourceItemByNameComparator;
43:
44: /**
45: * @author Michel-Ange ANTON
46: */
47:
48: public class ListDatasourcesAction extends JonasBaseAction {
49:
50: // --------------------------------------------------------- Public Methods
51:
52: public ActionForward executeAction(ActionMapping p_Mapping,
53: ActionForm p_Form, HttpServletRequest p_Request,
54: HttpServletResponse p_Response) throws IOException,
55: ServletException {
56:
57: // no Form used
58: try {
59: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
60: .getAttribute(WhereAreYou.SESSION_NAME);
61: String serverName = oWhere.getCurrentJonasServerName();
62: ArrayList alDeployable = JonasAdminJmx
63: .getDatasourceFilesDeployable(serverName);
64: ArrayList alDeployed = JonasAdminJmx
65: .getDatasourceFilesDeployed(oWhere
66: .getCurrentDomainName(), oWhere
67: .getCurrentJonasServerName());
68:
69: ArrayList al = new ArrayList();
70: String sName;
71: boolean bDeployed;
72: Iterator it = alDeployable.iterator();
73: while (it.hasNext()) {
74: sName = it.next().toString();
75: bDeployed = alDeployed.contains(sName);
76: al.add(new DatasourceItem(sName, bDeployed));
77: }
78: Collections.sort(al, new DatasourceItemByNameComparator());
79: // Set list in the request
80: p_Request.setAttribute("listDatasources", al);
81: } catch (Throwable t) {
82: addGlobalError(t);
83: saveErrors(p_Request, m_Errors);
84: return (p_Mapping.findForward("Global Error"));
85: }
86: // Forward to the jsp.
87: return (p_Mapping.findForward("Datasources"));
88: }
89: }
|