1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.ejb; 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 import javax.management.MalformedObjectNameException ; 34 import javax.management.ObjectName ; 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.JonasManagementRepr; 42 import org.objectweb.jonas.jmx.JonasObjectName; 43 import org.objectweb.jonas.jmx.JoramObjectName; 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.service.container.ContainerForm; 48 49 52 53 public abstract class EditEjbAction extends JonasBaseAction { 54 55 58 private String ejbObjectName = null; 59 60 70 public ActionForward executeAction(ActionMapping pMapping, 71 ActionForm pForm, 72 HttpServletRequest pRequest, 73 HttpServletResponse pResponse) { 74 EjbForm setForm = (EjbForm) m_Session.getAttribute("ejbForm"); 76 String sObjectName = pRequest.getParameter("select"); 78 if (sObjectName == null) { 79 sObjectName = (String ) pRequest.getAttribute("select"); 81 } 82 83 if (sObjectName == null) { 84 sObjectName = (setForm != null && setForm.getObjectName() != null) ? setForm.getObjectName() : null; 86 } 87 88 ObjectName oObjectName = null; 89 if (sObjectName != null) { 90 try { 91 oObjectName = ObjectName.getInstance(sObjectName); 92 } catch (Throwable t) { 93 addGlobalError(t); 94 saveErrors(pRequest, m_Errors); 95 return (pMapping.findForward("Global Error")); 96 } 97 } 98 99 EjbForm oForm = getEjbForm(); 101 ejbObjectName = sObjectName; 102 String msParamType = oObjectName.getKeyProperty("j2eeType"); 103 String msParamName = oObjectName.getKeyProperty("name"); 104 String msParamFile = getStringAttribute(oObjectName, "fileName"); 105 106 oForm.setType(msParamType); 108 oForm.setName(msParamName); 109 oForm.setObjectName(ejbObjectName); 110 oForm.setFile(msParamFile); 111 if (msParamType != null) { 112 String sFullType = m_Resources.getMessage("ejb.fulltype." + msParamType); 113 oForm.setFullType(sFullType); 114 } 115 116 String serverNodeName = "domain" + WhereAreYou.NODE_SEPARATOR 122 + m_WhereAreYou.getCurrentJonasServerName(); 123 124 m_WhereAreYou.selectNameNode(serverNodeName 125 + WhereAreYou.NODE_SEPARATOR + "services" 126 + WhereAreYou.NODE_SEPARATOR + "ejbContainers" 127 + WhereAreYou.NODE_SEPARATOR + JonasAdminJmx.extractFilename(oForm.getFile()) 128 + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true); 129 130 try { 131 fillEjbInfo(oForm, oObjectName); 133 fillEjbDependencies(oForm, oObjectName); 135 } catch (Throwable t) { 136 addGlobalError(t); 137 saveErrors(pRequest, m_Errors); 138 return (pMapping.findForward("Global Error")); 139 } 140 141 if (setForm != null && oForm.getObjectName() == null) { 142 sObjectName = setForm.getObjectName(); 143 oForm = setForm; 144 } 145 pRequest.setAttribute("select", sObjectName); 146 147 m_Session.setAttribute("ejbForm", oForm); 148 149 150 String sForward = getEjbForward(); 152 153 154 155 ContainerForm oContForm = (ContainerForm) m_Session.getAttribute("containerForm"); 157 boolean bChangeForward = false; 158 if (oContForm == null) { 159 bChangeForward = true; 160 } else { 161 if (!oContForm.getPath().equals(oForm.getFile())) { 162 bChangeForward = true; 163 } 164 } 165 if (bChangeForward) { 167 pRequest.setAttribute("NextForward", sForward); 169 sForward = "ActionEditContainer"; 172 } 173 174 return (pMapping.findForward(sForward)); 176 } 177 178 180 185 protected abstract String getEjbForward(); 186 187 192 protected abstract EjbForm getEjbForm(); 193 194 201 protected abstract void fillEjbInfo(EjbForm pForm, ObjectName pObjectName) 202 throws Exception ; 203 204 210 protected ObjectName getEjbObjectName() 211 throws Exception { 212 return ObjectName.getInstance(ejbObjectName); 213 } 214 215 221 protected void fillEjbGlobalInfo(EjbForm pForm, ObjectName pObjectName) { 222 pForm.setCurrentInstancePoolSize(getIntegerAttribute(pObjectName 223 , "currentInstancePoolSize")); 224 pForm.setDisplayName(getStringAttribute(pObjectName, "displayName")); 225 pForm.setEjbClass(getStringAttribute(pObjectName, "ejbClass")); 226 pForm.setEjbFileName(getStringAttribute(pObjectName, "fileName")); 227 pForm.setEjbName(pObjectName.getKeyProperty("name")); 228 pForm.setHomeClass(getStringAttribute(pObjectName, "homeClass")); 229 pForm.setJndiName(getStringAttribute(pObjectName, "jndiName")); 230 pForm.setLocalClass(getStringAttribute(pObjectName, "localClass")); 231 pForm.setLocalHomeClass(getStringAttribute(pObjectName, "localHomeClass")); 232 pForm.setRemoteClass(getStringAttribute(pObjectName, "remoteClass")); 233 } 234 235 241 protected void fillEjbDependencies(EjbForm pForm, ObjectName pObjectName) { 242 pForm.setDatabaseServiceActivated(JonasManagementRepr.isRegistered(JonasObjectName. 244 databaseService())); 245 HashMap hDataSources = new HashMap ((Map ) JonasManagementRepr.getAttribute(pObjectName 246 , "allDataSourceName")); 247 if (hDataSources.size() > 0) { 248 pForm.setDataSource(true); 249 pForm.setDataSources(hDataSources); 250 } 251 pForm.setJmsServiceActivated(JonasManagementRepr.isRegistered(JonasObjectName.jmsService())); 253 ObjectName jormamPlatformObjectName = null; 254 try { 255 jormamPlatformObjectName = JoramObjectName.joramPlatform(); 256 pForm.setJoramResourceLoaded(JonasManagementRepr.isRegistered(jormamPlatformObjectName)); 257 } catch (MalformedObjectNameException e) { 258 pForm.setJoramResourceLoaded(false); 259 } 260 ArrayList alJmsConnections = new ArrayList ((Collection ) JonasManagementRepr.getAttribute( 261 pObjectName, "allJMSConnectionFactoryName")); 262 if (alJmsConnections.size() > 0) { 263 pForm.setJmsConnection(true); 264 pForm.setJmsConnections(alJmsConnections); 265 } 266 ArrayList alJmsDestinations = new ArrayList ((Collection ) JonasManagementRepr.getAttribute( 267 pObjectName, "allJMSDestinationName")); 268 if (alJmsDestinations.size() > 0) { 269 pForm.setJmsDestination(true); 270 pForm.setJmsDestinations(alJmsDestinations); 271 } 272 pForm.setMailServiceActivated(JonasManagementRepr.isRegistered(JonasObjectName.mailService())); 274 HashMap hMailSessions = new HashMap ((Map ) JonasManagementRepr.getAttribute(pObjectName 275 , "allMailFactorySName")); 276 if (hMailSessions.size() > 0) { 277 pForm.setMailSession(true); 278 pForm.setMailSessions(hMailSessions); 279 } 280 HashMap hMailMimes = new HashMap ((Map ) JonasManagementRepr.getAttribute(pObjectName 281 , "allMailFactoryMName")); 282 if (hMailMimes.size() > 0) { 283 pForm.setMailMime(true); 284 pForm.setMailMimes(hMailMimes); 285 } 286 pForm.setDependency(pForm.isDataSource() || pForm.isJmsConnection() 288 || pForm.isJmsDestination() || pForm.isMailSession() || pForm.isMailMime()); 289 } 290 } 291 | Popular Tags |