001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 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: ListDatabasesAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.db;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.Collections;
029:
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.J2eeObjectName;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
041: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
042:
043: /**
044: * @author Michel-Ange ANTON
045: * @author Adriana Danes - update to use JSR 77 JDBCResource
046: */
047:
048: public class ListDatabasesAction extends JonasBaseAction {
049:
050: // --------------------------------------------------------- Public Methods
051: /**
052: * Action executed to perform HTTP request
053: *
054: * @param pMapping The ActionMapping used to select this instance
055: * @param pForm The optional ActionForm bean for this request (if any)
056: * @param pRequest The HTTP request we are processing
057: * @param pResponse The HTTP response we are creating
058: *
059: * @return The forward where redirect
060: *
061: * @exception IOException if an input/output error occurs
062: * @exception ServletException if a servlet exception occurs
063: */
064: public ActionForward executeAction(ActionMapping pMapping,
065: ActionForm pForm, HttpServletRequest pRequest,
066: HttpServletResponse pResponse) throws IOException,
067: ServletException {
068:
069: // Force the node selected in tree
070: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
071: + WhereAreYou.NODE_SEPARATOR + "services"
072: + WhereAreYou.NODE_SEPARATOR + "database", true);
073:
074: // no Form used
075: try {
076: // Use JDBCResource MBean
077: String domainName = m_WhereAreYou.getCurrentDomainName();
078: String serverName = m_WhereAreYou
079: .getCurrentJonasServerName();
080: ObjectName on = J2eeObjectName.JDBCResource(domainName,
081: serverName);
082: String[] jdbcDataSources = (String[]) JonasManagementRepr
083: .getAttribute(on, "jdbcDataSources", serverName);
084: ArrayList al = new ArrayList();
085: if (jdbcDataSources.length != 0) {
086: String jdbcDataSourceON = null;
087: ObjectName jdbcDataSourceObjectName = null;
088: String sName = null;
089: String sJndiName = null;
090: int iJdbcConOpen;
091: for (int i = 0; i < jdbcDataSources.length; i++) {
092: jdbcDataSourceON = jdbcDataSources[i];
093: jdbcDataSourceObjectName = ObjectName
094: .getInstance(jdbcDataSourceON);
095: sName = (String) getStringAttribute(
096: jdbcDataSourceObjectName, "name");
097: sJndiName = (String) getStringAttribute(
098: jdbcDataSourceObjectName, "jndiName");
099: iJdbcConOpen = getIntegerAttribute(
100: jdbcDataSourceObjectName, "currentOpened");
101: al.add(new DatasourceItem(sName, sJndiName,
102: iJdbcConOpen, true));
103: }
104:
105: Collections.sort(al,
106: new DatasourceItemByNameComparator());
107: }
108: // Set list in the request
109: pRequest.setAttribute("listDatabases", al);
110: } catch (Throwable t) {
111: addGlobalError(t);
112: saveErrors(pRequest, m_Errors);
113: return (pMapping.findForward("Global Error"));
114: }
115: // Forward to the jsp.
116: return (pMapping.findForward("Databases"));
117: }
118: }
|