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 32 import javax.management.ObjectName ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 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.J2eeObjectName; 41 import org.objectweb.jonas.jmx.JonasManagementRepr; 42 import org.objectweb.jonas.jmx.JonasObjectName; 43 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction; 44 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 45 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem; 46 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator; 47 48 51 52 public class EditDatasourceAction extends JonasBaseAction { 53 54 56 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 57 , HttpServletRequest p_Request, HttpServletResponse p_Response) 58 throws IOException , ServletException { 59 60 String sName = p_Request.getParameter("name"); 62 63 DatasourceForm oForm = null; 65 if (sName != null) { 66 oForm = new DatasourceForm(); 68 oForm.reset(p_Mapping, p_Request); 69 m_Session.setAttribute("datasourceForm", oForm); 70 oForm.setDatasourceName(sName); 71 } else { 72 oForm = (DatasourceForm) m_Session.getAttribute("datasourceForm"); 74 } 75 76 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR 78 + "services" + WhereAreYou.NODE_SEPARATOR + "database" + WhereAreYou.NODE_SEPARATOR 79 + oForm.getDatasourceName(), true); 80 81 try { 83 if (sName != null) { 84 populate(oForm, m_WhereAreYou.getCurrentDomainName(), m_WhereAreYou.getCurrentJonasServerName()); 85 } 86 } catch (Throwable t) { 87 addGlobalError(t); 88 saveErrors(p_Request, m_Errors); 89 return (p_Mapping.findForward("Global Error")); 90 } 91 return (p_Mapping.findForward("Datasource")); 93 } 94 95 97 protected void populate(DatasourceForm p_Form, String domainName, String serverName) 98 throws Exception { 99 100 ObjectName oObjectName = J2eeObjectName.getJDBCDataSource(domainName, serverName, p_Form.getDatasourceName()); 102 String jdbcDriverON = getStringAttribute(oObjectName, "jdbcDriver"); 104 ObjectName onJdbcDriver = ObjectName.getInstance(jdbcDriverON); 105 p_Form.setClassName(getStringAttribute(onJdbcDriver, "driverClassName")); 107 p_Form.setDatasourceDescription(getStringAttribute(oObjectName, "description")); 108 p_Form.setDatasourceName(getStringAttribute(oObjectName, "name")); 109 p_Form.setDatasourceMapper(getStringAttribute(oObjectName, "mapperName")); 110 p_Form.setDsName(getStringAttribute(oObjectName, "jndiName")); 111 p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(oObjectName, "jdbcConnCheckLevel")); 112 p_Form.setJdbcConnMaxAge(toStringIntegerAttribute(oObjectName, "jdbcConnMaxAge")); 113 p_Form.setJdbcMaxOpenTime(toStringIntegerAttribute(oObjectName, "jdbcMaxOpenTime")); 114 p_Form.setJdbcTestStatement(getStringAttribute(oObjectName, "jdbcTestStatement")); 115 p_Form.setPassword(getStringAttribute(oObjectName, "userPassword")); 116 p_Form.setUrl(getStringAttribute(oObjectName, "url")); 117 p_Form.setUserName(getStringAttribute(oObjectName, "userName")); 118 p_Form.setJdbcMaxConnPool(toStringIntegerAttribute(oObjectName, "jdbcMaxConnPool")); 119 p_Form.setJdbcMinConnPool(toStringIntegerAttribute(oObjectName, "jdbcMinConnPool")); 120 p_Form.setJdbcMaxWaitTime(toStringIntegerAttribute(oObjectName, "jdbcMaxWaitTime")); 121 p_Form.setJdbcMaxWaiters(toStringIntegerAttribute(oObjectName, "jdbcMaxWaiters")); 122 p_Form.setJdbcSamplingPeriod(toStringIntegerAttribute(oObjectName, "jdbcSamplingPeriod")); 123 124 ArrayList al = new ArrayList (); 126 String [] asParam = new String [1]; 127 String [] asSignature = new String [1]; 128 asSignature[0] = "java.lang.String"; 129 asParam[0] = p_Form.getDsName(); 130 if (JonasManagementRepr.isRegistered(JonasObjectName.ejbService())) { 131 java.util.Iterator it = ((java.util.Set ) JonasManagementRepr.invoke(JonasObjectName. 132 ejbService(), "getDataSourceDependence", asParam, asSignature)).iterator(); 133 while (it.hasNext()) { 134 al.add(new EjbItem((ObjectName ) it.next())); 135 } 136 } 137 Collections.sort(al, new EjbItemByNameComparator()); 139 p_Form.setListUsedByEjb(al); 141 } 142 } 143 | Popular Tags |