00001
00026 package org.objectweb.jonas.webapp.jonasadmin.service.container;
00027
00028 import java.io.IOException;
00029 import java.net.URL;
00030 import java.util.ArrayList;
00031
00032 import javax.management.MalformedObjectNameException;
00033 import javax.management.ObjectName;
00034 import javax.servlet.ServletException;
00035 import javax.servlet.http.HttpServletRequest;
00036 import javax.servlet.http.HttpServletResponse;
00037
00038 import org.apache.struts.action.ActionForm;
00039 import org.apache.struts.action.ActionForward;
00040 import org.apache.struts.action.ActionMapping;
00041 import org.objectweb.jonas.container.EJBServiceImpl;
00042 import org.objectweb.jonas.jmx.J2eeObjectName;
00043 import org.objectweb.jonas.jmx.JonasManagementRepr;
00044 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
00045 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00046 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00047 import org.objectweb.jonas.webapp.jonasadmin.common.ModuleItem;
00048
00054 public class EditEarAction extends JonasBaseAction {
00055
00056
00064 private static String NONAME = "";
00065
00066 public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm
00067 , HttpServletRequest pRequest, HttpServletResponse pResponse)
00068 throws IOException, ServletException {
00069
00070
00071 String sObjectName = pRequest.getParameter("select");
00072
00073 ObjectName oObjectName = null;
00074 String domainName = null;
00075 String serverName = null;
00076 String appName = null;
00077
00078
00079 EarForm oForm = null;
00080 if (sObjectName != null) {
00081 String sPath = null;
00082 try {
00083
00084 oObjectName = ObjectName.getInstance(sObjectName);
00085 domainName = oObjectName.getDomain();
00086 serverName = oObjectName.getKeyProperty("J2EEServer");
00087 appName = oObjectName.getKeyProperty("name");
00088
00089 oForm = new EarForm();
00090 oForm.reset(pMapping, pRequest);
00091 m_Session.setAttribute("earForm", oForm);
00092 URL earUrl = (java.net.URL) JonasManagementRepr.getAttribute(oObjectName, "earUrl");
00093 sPath = earUrl.toString();
00094
00095 oForm.setFilename(JonasAdminJmx.extractFilename(sPath));
00096
00097
00098 } catch (Throwable t) {
00099 addGlobalError(t);
00100 saveErrors(pRequest, m_Errors);
00101 return (pMapping.findForward("Global Error"));
00102 }
00103 } else {
00104
00105 oForm = (EarForm) m_Session.getAttribute("earForm");
00106 }
00107
00108
00109 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
00110 + "services" + WhereAreYou.NODE_SEPARATOR + "ear" + WhereAreYou.NODE_SEPARATOR
00111 + oForm.getFilename(), true);
00112
00113
00114 try {
00115 if (oObjectName != null) {
00116 oForm.setEarPath((URL) JonasManagementRepr.getAttribute(oObjectName, "earUrl"));
00117 oForm.setXmlDeploymentDescriptor(getStringAttribute(oObjectName, "deploymentDescriptor"));
00118
00119
00120
00121 URL[] warPaths = (URL[]) JonasManagementRepr.getAttribute(oObjectName, "wars");
00122 String[] webModuleObjectNames = (String[]) JonasManagementRepr.getAttribute(oObjectName, "webModules");
00123 String[] arrayPathContext = getPathContexts(webModuleObjectNames);
00124 ArrayList wars = new ArrayList();
00125 for (int i = 0; i < warPaths.length; i++) {
00126 URL warPath = warPaths[i];
00127 String path = warPath.getPath();
00128
00129
00130
00131
00132 int index = getWebModuleIndex(warPath, arrayPathContext);
00133 ModuleItem it = null;
00134 if (index > -1) {
00135
00136
00137 it = new ModuleItem(arrayPathContext[index], webModuleObjectNames[index], path);
00138 } else {
00139
00140 it = new ModuleItem(NONAME, NONAME, path);
00141 }
00142 wars.add(it);
00143 }
00144 oForm.setWars(wars);
00145
00146
00147
00148 URL[] jarPaths = (URL[]) JonasManagementRepr.getAttribute(oObjectName, "ejbJars");
00149 ArrayList ejbJars = new ArrayList();
00150 for (int i = 0; i < jarPaths.length; i++) {
00151 URL jarPath = jarPaths[i];
00152 String path = jarPath.getPath();
00153 String name = EJBServiceImpl.buildEJBModuleName(jarPath);
00154 ObjectName moduleObjectName = J2eeObjectName.getEJBModule(domainName, serverName, appName, name);
00155 String objectName = moduleObjectName.toString();
00156 ModuleItem it = new ModuleItem(name, objectName, path);
00157 ejbJars.add(it);
00158 }
00159 oForm.setEjbjars(ejbJars);
00160
00161
00162
00163 oForm.setListRars((URL[]) JonasManagementRepr.getAttribute(oObjectName, "rars"));
00164
00165 }
00166 } catch (Throwable t) {
00167 addGlobalError(t);
00168 saveErrors(pRequest, m_Errors);
00169 return (pMapping.findForward("Global Error"));
00170 }
00171
00172 return (pMapping.findForward("Ear"));
00173 }
00174
00185 private String[] getPathContexts(String[] webModuleObjectNames) {
00186 int nbNames = webModuleObjectNames.length;
00187 String[] ret = new String[nbNames];
00188 for (int i = 0; i < nbNames; i++) {
00189 ObjectName oObjectName = null;
00190 try {
00191 oObjectName = ObjectName.getInstance(webModuleObjectNames[i]);
00192 } catch (MalformedObjectNameException e) {
00193 ret[i] = null;
00194 }
00195 String nameKeyProp = oObjectName.getKeyProperty("name");
00196 ret[i] = WebAppItem.extractPathContext(nameKeyProp);
00197 }
00198 return ret;
00199 }
00210 private int getWebModuleIndex(URL warPath, String[] arrayPathContext) {
00211 int index = -1;
00212 StringBuffer sbWarPath = new StringBuffer(warPath.toString());
00213 for (int i = 0; i < arrayPathContext.length; i++) {
00214 String sWarPath = warPath.toString();
00215 String pathContext = arrayPathContext[i];
00216 if (pathContext != null) {
00217 int indexPath = sbWarPath.indexOf(pathContext);
00218 if (indexPath > -1) {
00219 index = i;
00220 break;
00221 }
00222 }
00223 }
00224 return index;
00225 }
00226 }