001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ExecuteEjbAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.ejb;
025:
026: import java.io.IOException;
027:
028: import javax.management.ObjectName;
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import org.apache.struts.action.ActionForm;
034: import org.apache.struts.action.ActionForward;
035: import org.apache.struts.action.ActionMapping;
036: import org.objectweb.jonas.jmx.JonasManagementRepr;
037: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
038: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
039:
040: /**
041: * @author Michel-Ange ANTON
042: */
043:
044: public class ExecuteEjbAction extends JonasBaseAction {
045:
046: // --------------------------------------------------------- Protected variables
047:
048: protected String mAction = null;
049: protected String mForward = null;
050:
051: // --------------------------------------------------------- Public Methods
052:
053: /**
054: * Execute a action.
055: *
056: * @param pMapping <code>ActionForward</code> instance
057: * @param pForm <code>ActionForm</code> instance
058: * @param pRequest <code>HttpServletRequest</code> instance
059: * @param pResponse <code>HttpServletResponse</code> instance
060: * @return <code>ActionForward</code> instance
061: * @throws IOException
062: * @throws ServletException
063: */
064: public ActionForward executeAction(ActionMapping pMapping,
065: ActionForm pForm, HttpServletRequest pRequest,
066: HttpServletResponse pResponse) throws IOException,
067: ServletException {
068:
069: // Current server
070: WhereAreYou oWhere = (WhereAreYou) pRequest.getSession()
071: .getAttribute(WhereAreYou.SESSION_NAME);
072: String serverName = oWhere.getCurrentJonasServerName();
073:
074: // Get Http parameters
075: mAction = pRequest.getParameter("action");
076: // Form used
077: EjbForm oForm = (EjbForm) m_Session.getAttribute("ejbForm");
078: // Type Ejb used
079: //m_Type = getIntegerType(oForm);
080:
081: try {
082: // Execute a method of Ejb
083: executeEjb(oForm, serverName);
084: } catch (Throwable t) {
085: addGlobalError(t);
086: saveErrors(pRequest, m_Errors);
087: return (pMapping.findForward("Global Error"));
088: }
089:
090: // Forward to the jsp or the action
091: pRequest.setAttribute("select", oForm.getObjectName());
092: return (pMapping.findForward(mForward));
093: }
094:
095: // --------------------------------------------------------- Protected Methods
096:
097: /**
098: * Dispath executing on Ejb.
099: *
100: * @param pForm Current form
101: * @throws Exception Could not execute the requested action
102: */
103: protected void executeEjb(EjbForm pForm, String serverName)
104: throws Exception {
105: // Object name used
106: String sObjectName = pForm.getObjectName();
107: ObjectName on = new ObjectName(sObjectName);
108: String mType = pForm.getType(); // j2eeType
109: if (mType.equals("EntityBean")) {
110: // set forward String
111: mForward = "ActionEditEjbEntity";
112: EjbEntityForm eForm = (EjbEntityForm) pForm;
113: String mPersistency = eForm.getPersistency();
114: if (mPersistency.startsWith("Cont")) {
115: if ("synchronize".equals(mAction)) {
116: JonasManagementRepr.invoke(on, "synchronize", null,
117: null, serverName);
118: } else if ("reduceCache".equals(mAction)) {
119: JonasManagementRepr.invoke(on, "reduceCache", null,
120: null, serverName);
121: }
122: }
123: } else if (mType.equals("StatelessSessionBean")) {
124: mForward = "ActionEditEjbSbl";
125: if ("reduceCache".equals(mAction)) {
126: JonasManagementRepr.invoke(on, "reduceCache", null,
127: null, serverName);
128: }
129: }
130: }
131:
132: }
|