1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.db; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 import java.util.Collections ; 31 import java.util.Iterator ; 32 33 import javax.management.ObjectName ; 34 import javax.servlet.ServletException ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 38 import org.apache.struts.action.ActionForm; 39 import org.apache.struts.action.ActionForward; 40 import org.apache.struts.action.ActionMapping; 41 import org.objectweb.jonas.jmx.J2eeObjectName; 42 import org.objectweb.jonas.jmx.JonasManagementRepr; 43 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction; 44 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 45 46 50 51 public class ListDatabasesAction extends JonasBaseAction { 52 53 67 public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm 68 , HttpServletRequest pRequest, HttpServletResponse pResponse) 69 throws IOException , ServletException { 70 71 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR 73 + "services" + WhereAreYou.NODE_SEPARATOR + "database", true); 74 75 try { 77 String domainName = m_WhereAreYou.getCurrentDomainName(); 79 String serverName = m_WhereAreYou.getCurrentJonasServerName(); 80 ObjectName on = J2eeObjectName.JDBCResource(domainName, serverName); 81 String [] jdbcDataSources = (String []) JonasManagementRepr.getAttribute(on, "jdbcDataSources"); 82 ArrayList al = new ArrayList (); 83 if (jdbcDataSources.length != 0) { 84 String jdbcDataSourceON = null; 85 ObjectName jdbcDataSourceObjectName = null; 86 String sName = null; 87 String sJndiName = null; 88 int iJdbcConOpen; 89 for (int i = 0; i < jdbcDataSources.length; i++) { 90 jdbcDataSourceON = jdbcDataSources[i]; 91 jdbcDataSourceObjectName = ObjectName.getInstance(jdbcDataSourceON); 92 sName = (String ) getStringAttribute(jdbcDataSourceObjectName, "name"); 93 sJndiName = (String ) getStringAttribute(jdbcDataSourceObjectName, "jndiName"); 94 iJdbcConOpen = getIntegerAttribute(jdbcDataSourceObjectName, "currentOpened "); 95 al.add(new DatasourceItem(sName, sJndiName, iJdbcConOpen, true)); 96 } 97 98 Collections.sort(al, new DatasourceItemByNameComparator()); 99 } 100 pRequest.setAttribute("listDatabases", al); 102 } catch (Throwable t) { 103 addGlobalError(t); 104 saveErrors(pRequest, m_Errors); 105 return (pMapping.findForward("Global Error")); 106 } 107 return (pMapping.findForward("Databases")); 109 } 110 } 111 | Popular Tags |