1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.container; 27 28 import java.io.IOException ; 29 import java.net.URL ; 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 33 import javax.management.MalformedObjectNameException ; 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.container.EJBServiceImpl; 43 import org.objectweb.jonas.jmx.J2eeObjectName; 44 import org.objectweb.jonas.jmx.JonasManagementRepr; 45 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 46 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction; 47 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 48 import org.objectweb.jonas.webapp.jonasadmin.common.ModuleItem; 49 50 54 55 public class EditEarAction extends JonasBaseAction { 56 57 65 private static String NONAME = ""; 66 67 public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm 68 , HttpServletRequest pRequest, HttpServletResponse pResponse) 69 throws IOException , ServletException { 70 71 String sObjectName = pRequest.getParameter("select"); 73 74 ObjectName oObjectName = null; 75 String domainName = null; 76 String serverName = null; 77 String appName = null; 78 79 EarForm oForm = null; 81 if (sObjectName != null) { 82 String sPath = null; 83 try { 84 oObjectName = ObjectName.getInstance(sObjectName); 86 domainName = oObjectName.getDomain(); 87 serverName = oObjectName.getKeyProperty("J2EEServer"); 88 appName = oObjectName.getKeyProperty("name"); 89 oForm = new EarForm(); 91 oForm.reset(pMapping, pRequest); 92 m_Session.setAttribute("earForm", oForm); 93 URL earUrl = (java.net.URL ) JonasManagementRepr.getAttribute(oObjectName, "earUrl"); 94 sPath = earUrl.toString(); 95 oForm.setFilename(JonasAdminJmx.extractFilename(sPath)); 97 } catch (Throwable t) { 100 addGlobalError(t); 101 saveErrors(pRequest, m_Errors); 102 return (pMapping.findForward("Global Error")); 103 } 104 } else { 105 oForm = (EarForm) m_Session.getAttribute("earForm"); 107 } 108 109 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR 111 + "services" + WhereAreYou.NODE_SEPARATOR + "ear" + WhereAreYou.NODE_SEPARATOR 112 + oForm.getFilename(), true); 113 114 try { 116 if (oObjectName != null) { 117 oForm.setEarPath((URL ) JonasManagementRepr.getAttribute(oObjectName, "earUrl")); 118 oForm.setXmlDeploymentDescriptor(getStringAttribute(oObjectName, "deploymentDescriptor")); 119 120 URL [] warPaths = (URL []) JonasManagementRepr.getAttribute(oObjectName, "wars"); 123 String [] webModuleObjectNames = (String []) JonasManagementRepr.getAttribute(oObjectName, "webModules"); 124 String [] arrayPathContext = getPathContexts(webModuleObjectNames); 125 ArrayList wars = new ArrayList (); 126 for (int i = 0; i < warPaths.length; i++) { 127 URL warPath = warPaths[i]; 128 String path = warPath.getPath(); 129 int index = getWebModuleIndex(warPath, webModuleObjectNames); 134 ModuleItem it = null; 135 if (index > -1) { 136 it = new ModuleItem(arrayPathContext[index], webModuleObjectNames[index], path); 139 } else { 140 it = new ModuleItem(NONAME, NONAME, path); 142 } 143 wars.add(it); 144 } 145 oForm.setWars(wars); 146 147 URL [] jarPaths = (URL []) JonasManagementRepr.getAttribute(oObjectName, "ejbJars"); 150 ArrayList ejbJars = new ArrayList (); 151 for (int i = 0; i < jarPaths.length; i++) { 152 URL jarPath = jarPaths[i]; 153 String path = jarPath.getPath(); 154 String name = EJBServiceImpl.buildEJBModuleName(jarPath); 155 ObjectName moduleObjectName = J2eeObjectName.getEJBModule(domainName, serverName, appName, name); 156 String objectName = moduleObjectName.toString(); 157 ModuleItem it = new ModuleItem(name, objectName, path); 158 ejbJars.add(it); 159 } 160 oForm.setEjbjars(ejbJars); 161 162 URL [] rarPaths = (URL []) JonasManagementRepr.getAttribute(oObjectName, "rars"); 166 ArrayList rars = new ArrayList (); 167 for (int i = 0; i < rarPaths.length; i++) { 168 URL rarPath = rarPaths[i]; 169 String path = rarPath.getPath(); 170 ObjectName resourceAdapterObjectNames = J2eeObjectName.getResourceAdapters(domainName, appName, serverName); 171 Iterator itNames = JonasManagementRepr.queryNames(resourceAdapterObjectNames).iterator(); 172 ModuleItem it = null; 173 while (itNames.hasNext()) { 174 ObjectName resourceAdapterObjectName = (ObjectName ) itNames.next(); 175 String raFileName = (String ) JonasManagementRepr.getAttribute(resourceAdapterObjectName, "fileName"); 176 if (raFileName.equals(path)) { 177 String objectName = resourceAdapterObjectName.toString(); 179 it = new ModuleItem(resourceAdapterObjectName.getKeyProperty("name"), objectName, path); 180 rars.add(it); 181 } 182 } 183 } 184 oForm.setRars(rars); 185 } 186 } catch (Throwable t) { 187 addGlobalError(t); 188 saveErrors(pRequest, m_Errors); 189 return (pMapping.findForward("Global Error")); 190 } 191 return (pMapping.findForward("Ear")); 193 } 194 195 205 private String [] getPathContexts(String [] webModuleObjectNames) { 206 int nbNames = webModuleObjectNames.length; 207 String [] ret = new String [nbNames]; 208 for (int i = 0; i < nbNames; i++) { 209 ObjectName oObjectName = null; 210 try { 211 oObjectName = ObjectName.getInstance(webModuleObjectNames[i]); 212 } catch (MalformedObjectNameException e) { 213 ret[i] = null; 214 } 215 String nameKeyProp = oObjectName.getKeyProperty("name"); 216 ret[i] = WebAppItem.extractLabelPathContext(nameKeyProp); 217 } 218 return ret; 219 } 220 229 private int getWebModuleIndex(URL warPath, String [] webModuleObjectNames) { 230 if (m_WhereAreYou != null && m_WhereAreYou.isJettyServer()) { 234 return -1; 235 } 236 int index = -1; 237 for (int i = 0; i < webModuleObjectNames.length; i++) { 238 ObjectName webModuleObjectName = null; 239 try { 240 webModuleObjectName = ObjectName.getInstance(webModuleObjectNames[i]); 241 } catch (MalformedObjectNameException e) { 242 return -1; 243 } 244 URL webModuleWarPath = (URL ) JonasManagementRepr.getAttribute(webModuleObjectName, "warURL"); 245 if (warPath.equals(webModuleWarPath)) { 246 index = i; 247 break; 248 } 249 } 250 return index; 251 } 252 } 253 | Popular Tags |