001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 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: EditLoggingJonasAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.logging;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.Arrays;
029:
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.Jlists;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
042: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
043:
044: /**
045: * @author Michel-Ange ANTON
046: */
047:
048: public class EditLoggingJonasAction extends JonasBaseAction {
049:
050: // --------------------------------------------------------- Public Methods
051:
052: public ActionForward executeAction(ActionMapping p_Mapping,
053: ActionForm p_Form, HttpServletRequest p_Request,
054: HttpServletResponse p_Response) throws IOException,
055: ServletException {
056:
057: // Force the node selected in tree
058: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
059: + WhereAreYou.NODE_SEPARATOR + "logging"
060: + WhereAreYou.NODE_SEPARATOR + LoggerItem.LOGGER_JONAS,
061: true);
062:
063: // Form used
064: LoggingJonasForm oForm = (LoggingJonasForm) p_Form;
065:
066: // Current server
067: String serverName = m_WhereAreYou.getCurrentJonasServerName();
068:
069: try {
070: ObjectName oObjectName = null;
071: oObjectName = JonasObjectName.logService("trace");
072: String[] asTopic = (String[]) JonasManagementRepr
073: .getAttribute(oObjectName, "Topics", serverName);
074:
075: ArrayList alTopic = new ArrayList(Arrays.asList(asTopic));
076: int iPos = alTopic.indexOf("root");
077: if (iPos > -1) {
078: alTopic.remove(iPos);
079: alTopic.add(0, "root");
080: Object[] ao = alTopic.toArray();
081: for (int i = 0; i < ao.length; i++) {
082: asTopic[i] = ao[i].toString();
083: }
084: }
085:
086: // Search the level of each topic
087: String[] asParam = new String[1];
088: String[] asSignature = new String[1];
089: asSignature[0] = "java.lang.String";
090: String sLevel = null;
091: ArrayList al = new ArrayList();
092: String[] asLevel = new String[asTopic.length];
093: for (int i = 0; i < asTopic.length; i++) {
094: asParam[0] = asTopic[i];
095: sLevel = (String) JonasManagementRepr.invoke(
096: oObjectName, "getTopicLevel", asParam,
097: asSignature, serverName);
098: asLevel[i] = sLevel;
099: al.add(new TopicLevel(asTopic[i], sLevel));
100: }
101: oForm.setTopicLevelList(al);
102: oForm.setTopics(asTopic);
103: oForm.setLoggerJonasLevels(Jlists.getLoggerJonasLevels());
104: } catch (Throwable t) {
105: addGlobalError(t);
106: saveErrors(p_Request, m_Errors);
107: return (p_Mapping.findForward("Global Error"));
108: }
109: // Forward to the jsp.
110: return (p_Mapping.findForward("Logging Jonas"));
111: }
112: }
|