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.ServletHolder;
031: import org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean;
032: import org.mortbay.util.LogSupport;
033:
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: /**
038: * Fix the uniqueObjectName method and generate a corrent ObjectName for the Servlet.
039: *
040: * @author Guillaume Sauthier
041: */
042: public class FixedJsr77ServletHolderMBean extends
043: Jsr77ServletHolderMBean {
044:
045: /**
046: * logger
047: */
048: private static Log log = LogFactory
049: .getLog(FixedJsr77ServletHolderMBean.class);
050:
051: /**
052: * Monitored resource
053: */
054: private ServletHolder servletHolder = null;
055:
056: /**
057: * domain name
058: */
059: private String j2EEDomainName = null;
060:
061: /**
062: * server name
063: */
064: private String j2EEServerName = null;
065:
066: /**
067: * application name
068: */
069: private String j2EEApplicationName = null;
070:
071: /**
072: * Default public Constrcuctor
073: * @throws MBeanException required by the spec
074: */
075: public FixedJsr77ServletHolderMBean() throws MBeanException {
076: super ();
077: }
078:
079: /**
080: *
081: * @see org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean#defineManagedResource()
082: */
083: protected void defineManagedResource() {
084: // TODO Auto-generated method stub
085: super .defineManagedResource();
086: servletHolder = (ServletHolder) getManagedResource();
087: }
088:
089: /**
090: * @return Returns the j2EEApplicationName.
091: */
092: public String getJ2EEApplicationName() {
093: return j2EEApplicationName;
094: }
095:
096: /**
097: * @param applicationName The j2EEApplicationName to set.
098: */
099: public void setJ2EEApplicationName(String applicationName) {
100: j2EEApplicationName = applicationName;
101: }
102:
103: /**
104: * @return Returns the j2EEDomainName.
105: */
106: public String getJ2EEDomainName() {
107: return j2EEDomainName;
108: }
109:
110: /**
111: * @param domainName The j2EEDomainName to set.
112: */
113: public void setJ2EEDomainName(String domainName) {
114: j2EEDomainName = domainName;
115: }
116:
117: /**
118: * @return Returns the j2EEServerName.
119: */
120: public String getJ2EEServerName() {
121: return j2EEServerName;
122: }
123:
124: /**
125: * @param serverName The j2EEServerName to set.
126: */
127: public void setJ2EEServerName(String serverName) {
128: j2EEServerName = serverName;
129: }
130:
131: /**
132: *
133: * @see org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean#uniqueObjectName(javax.management.MBeanServer,
134: * java.lang.String)
135: */
136: public synchronized ObjectName uniqueObjectName(
137: MBeanServer mbeanServer, String baseObjectName) {
138: ObjectName jsr77Name = null;
139: String context = servletHolder.getHttpContext()
140: .getContextPath();
141: if (context.length() == 0) {
142: context = "/";
143: }
144:
145: try {
146: jsr77Name = new ObjectName(getJ2EEDomainName()
147: + ":J2EEServer=" + getJ2EEServerName()
148: + ",J2EEApplication=" + getJ2EEApplicationName()
149: + ",WebModule=" + context
150: + ",j2eeType=Servlet,name="
151: + servletHolder.getName());
152: } catch (Exception e) {
153: log.warn(LogSupport.EXCEPTION, e);
154: }
155: return jsr77Name;
156: }
157:
158: }
|