1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.resource; 27 28 import java.io.IOException ; 29 import java.net.URL ; 30 import java.util.ArrayList ; 31 import java.util.Collections ; 32 import java.util.Properties ; 33 34 import javax.management.ObjectName ; 35 import javax.servlet.ServletException ; 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpServletResponse ; 38 39 import org.apache.struts.action.ActionForm; 40 import org.apache.struts.action.ActionForward; 41 import org.apache.struts.action.ActionMapping; 42 import org.objectweb.jonas.jmx.JonasManagementRepr; 43 import org.objectweb.jonas.jmx.JonasObjectName; 44 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 45 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction; 46 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 47 import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator; 48 import org.objectweb.jonas.webapp.jonasadmin.common.ObjectNameItem; 49 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem; 50 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator; 51 52 55 56 public class EditResourceAdapterAction extends JonasBaseAction { 57 58 60 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 61 , HttpServletRequest p_Request, HttpServletResponse p_Response) 62 throws IOException , ServletException { 63 64 String sObjectName = p_Request.getParameter("select"); 66 67 ObjectName oObjectName = null; 68 String domainName = null; 69 String serverName = null; 70 String rarName = null; 71 String specVersion = null; 72 73 ResourceAdapterForm oForm = null; 75 if (sObjectName != null) { 77 String sPath = null; 78 try { 79 oObjectName = ObjectName.getInstance(sObjectName); 81 domainName = oObjectName.getDomain(); 82 serverName = oObjectName.getKeyProperty("J2EEServer"); 83 rarName = oObjectName.getKeyProperty("name"); 84 oForm = new ResourceAdapterForm(); 86 oForm.reset(p_Mapping, p_Request); 87 oForm.setName(rarName); 88 specVersion = getStringAttribute(oObjectName, "specVersion"); 89 oForm.setSpecVersion(specVersion); 90 91 if (oObjectName != null) { 92 oForm.setOName(oObjectName); 94 oForm.setJndiName(getStringAttribute(oObjectName, "jndiName")); 95 oForm.setPath(getStringAttribute(oObjectName, "fileName")); 96 oForm.setFile(JonasAdminJmx.extractFilename(oForm.getPath())); 97 oForm.setInEar(getBooleanAttribute(oObjectName, "inEarCase")); 98 oForm.setEarPath((URL ) JonasManagementRepr.getAttribute(oObjectName, "earURL")); 99 oForm.setListProperties((Properties ) JonasManagementRepr.getAttribute(oObjectName 100 , "properties")); 101 102 ObjectName oJCAResource = ObjectName.getInstance(getStringAttribute(oObjectName, "jcaResource")); 103 104 String [] cfs = (String []) JonasManagementRepr.getAttribute(oJCAResource, "connectionFactories"); 105 ArrayList cfAl = new ArrayList (); 106 String cfOn = null; 107 for (int i = 0; i < cfs.length; i++) { 108 cfOn = cfs[i]; 109 ObjectName onCf = ObjectName.getInstance(cfOn); 110 cfAl.add(new ObjectNameItem(onCf)); 111 } 112 Collections.sort(cfAl, new BeanComparator(new String [] { 113 "name"})); 114 oForm.setCF(cfAl); 115 116 String [] ass = (String []) JonasManagementRepr.getAttribute(oJCAResource, "activationSpecs"); 117 ArrayList asAl = new ArrayList (); 118 String asOn = null; 119 for (int i = 0; i < ass.length; i++) { 120 asOn = ass[i]; 121 ObjectName onAs = ObjectName.getInstance(asOn); 122 asAl.add(new ObjectNameItem(onAs)); 123 } 124 Collections.sort(asAl, new BeanComparator(new String [] { 125 "name"})); 126 oForm.setAS(asAl); 127 128 String [] aos = (String []) JonasManagementRepr.getAttribute(oJCAResource, "adminObjects"); 129 ArrayList aoAl = new ArrayList (); 130 String aoOn = null; 131 for (int i = 0; i < aos.length; i++) { 132 aoOn = aos[i]; 133 ObjectName onAo = ObjectName.getInstance(aoOn); 134 aoAl.add(new ObjectNameItem(onAo)); 135 } 136 Collections.sort(aoAl, new BeanComparator(new String [] { 137 "name"})); 138 oForm.setAO(aoAl); 139 140 if (specVersion == null || specVersion.equals("1.0")) { 141 populate(oForm, cfs[0]); 142 } 143 } 144 145 m_Session.setAttribute("resourceAdapterForm", oForm); 146 } catch (Throwable t) { 147 addGlobalError(t); 148 saveErrors(p_Request, m_Errors); 149 return (p_Mapping.findForward("Global Error")); 150 } 151 } else { 152 oForm = (ResourceAdapterForm) m_Session.getAttribute("resourceAdapterForm"); 154 specVersion = oForm.getSpecVersion(); 155 } 156 157 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR 159 + "services" + WhereAreYou.NODE_SEPARATOR + "resourceAdapter" 160 + WhereAreYou.NODE_SEPARATOR + oForm.getFile(), true); 161 162 if (specVersion != null && specVersion.equals("1.5")) { 164 return (p_Mapping.findForward("Resource Adapter1.5")); 165 } 166 return (p_Mapping.findForward("Resource Adapter1.0")); 167 } 168 169 171 protected void populate(ResourceAdapterForm p_Form, String cf) 172 throws Exception { 173 174 ObjectName oObjectName = ObjectName.getInstance(cf); 176 p_Form.setConnectionFactory (cf); 177 178 p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(oObjectName, "jdbcConnCheckLevel")); 179 p_Form.setConnMaxAge(toStringIntegerAttribute(oObjectName, "connMaxAge")); 180 p_Form.setMaxOpentime(toStringIntegerAttribute(oObjectName, "maxOpentime")); 181 p_Form.setJdbcTestStatement(getStringAttribute(oObjectName, "jdbcTestStatement")); 182 p_Form.setMaxSize(toStringIntegerAttribute(oObjectName, "maxSize")); 183 p_Form.setMinSize(toStringIntegerAttribute(oObjectName, "minSize")); 184 p_Form.setMaxWaitTime(toStringIntegerAttribute(oObjectName, "maxWaitTime")); 185 p_Form.setMaxWaiters(toStringIntegerAttribute(oObjectName, "maxWaiters")); 186 p_Form.setSamplingPeriod(toStringIntegerAttribute(oObjectName, "samplingPeriod")); 187 188 ArrayList al = new ArrayList (); 190 String [] asParam = new String [1]; 191 String [] asSignature = new String [1]; 192 asSignature[0] = "java.lang.String"; 193 asParam[0] = p_Form.getJndiName(); 194 if (JonasManagementRepr.isRegistered(JonasObjectName.ejbService())) { 195 java.util.Iterator it = ((java.util.Set ) JonasManagementRepr.invoke(JonasObjectName. 196 ejbService(), "getDataSourceDependence", asParam, asSignature)).iterator(); 197 while (it.hasNext()) { 198 al.add(new EjbItem((ObjectName ) it.next())); 199 } 200 } 201 Collections.sort(al, new EjbItemByNameComparator()); 203 p_Form.setListUsedByEjb(al); 205 } 206 } 207 | Popular Tags |