001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 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$
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.web.jetty50.jmx;
025:
026: import javax.management.MBeanException;
027: import javax.management.MBeanServer;
028: import javax.management.ObjectName;
029:
030: import org.mortbay.jetty.servlet.WebApplicationContext;
031: import org.mortbay.util.LogSupport;
032: import org.mortbay.util.jmx.ModelMBeanImpl;
033:
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: /**
038: * Fake (at least not complete) implementation of the WebModule MBean.
039: * TODO for a full implementation, the MBean should be able to return
040: * a real ObjectName array for Servlets inside the WebApp.
041: *
042: * @author Guillaume Sauthier
043: */
044: public class J2EEWebModuleMBean extends ModelMBeanImpl {
045:
046: /**
047: * logger
048: */
049: private static Log log = LogFactory
050: .getLog(J2EEWebModuleMBean.class);
051:
052: /**
053: * Monitored WebApp
054: */
055: private WebApplicationContext waContext = null;
056:
057: /**
058: * list of Servlet's ObjectNames
059: */
060: private ObjectName[] servlets = null;
061:
062: /**
063: * Default public MBean Constructor
064: * @throws MBeanException required by the spec
065: */
066: public J2EEWebModuleMBean() throws MBeanException {
067: super ();
068: }
069:
070: /**
071: * @see org.mortbay.util.jmx.ModelMBeanImpl#defineManagedResource()
072: */
073: protected void defineManagedResource() {
074: // TODO Auto-generated method stub
075: super .defineManagedResource();
076: defineAttribute("servlets", READ_ONLY, ON_MBEAN);
077: waContext = (WebApplicationContext) getManagedResource();
078: }
079:
080: /**
081: * @return Returns the servlets.
082: */
083: public ObjectName[] getServlets() {
084: return servlets;
085: }
086:
087: /**
088: * @param servlets
089: */
090: public void setServlets(ObjectName[] servlets) {
091: this .servlets = servlets;
092: }
093:
094: /**
095: *
096: * @see org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean#uniqueObjectName(javax.management.MBeanServer,
097: * java.lang.String)
098: */
099: public synchronized ObjectName uniqueObjectName(
100: MBeanServer mbeanServer, String baseObjectName) {
101: ObjectName jsr77Name = null;
102:
103: // get the context name
104: String context = waContext.getHttpContext().getContextPath();
105: if (context.length() == 0) {
106: context = "/";
107: }
108:
109: try {
110: jsr77Name = new ObjectName(waContext
111: .getAttribute("J2EEDomainName")
112: + ":J2EEServer="
113: + waContext.getAttribute("J2EEServerName")
114: + ",J2EEApplication="
115: + waContext.getAttribute("J2EEApplicationName")
116: + ",j2eeType=WebModule,name=" + context);
117: } catch (Exception e) {
118: log.warn(LogSupport.EXCEPTION, e);
119: }
120: return jsr77Name;
121: }
122:
123: }
|