KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > jetty50 > jmx > FixedJsr77ServletHolderMBean


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id$
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.web.jetty50.jmx;
26
27 import javax.management.MBeanException JavaDoc;
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30
31 import org.mortbay.jetty.servlet.ServletHolder;
32 import org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean;
33 import org.mortbay.util.LogSupport;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 /**
39  * Fix the uniqueObjectName method and generate a corrent ObjectName for the Servlet.
40  *
41  * @author Guillaume Sauthier
42  */

43 public class FixedJsr77ServletHolderMBean extends Jsr77ServletHolderMBean {
44
45     /**
46      * logger
47      */

48     private static Log log = LogFactory.getLog(FixedJsr77ServletHolderMBean.class);
49
50     /**
51      * Monitored resource
52      */

53     private ServletHolder servletHolder = null;
54
55     /**
56      * domain name
57      */

58     private String JavaDoc j2EEDomainName = null;
59
60     /**
61      * server name
62      */

63     private String JavaDoc j2EEServerName = null;
64
65     /**
66      * application name
67      */

68     private String JavaDoc j2EEApplicationName = null;
69
70     /**
71      * Default public Constrcuctor
72      * @throws MBeanException required by the spec
73      */

74     public FixedJsr77ServletHolderMBean() throws MBeanException JavaDoc {
75         super();
76     }
77
78     /**
79      *
80      * @see org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean#defineManagedResource()
81      */

82     protected void defineManagedResource() {
83         // TODO Auto-generated method stub
84
super.defineManagedResource();
85         servletHolder = (ServletHolder) getManagedResource();
86     }
87
88     /**
89      * @return Returns the j2EEApplicationName.
90      */

91     public String JavaDoc getJ2EEApplicationName() {
92         return j2EEApplicationName;
93     }
94
95     /**
96      * @param applicationName The j2EEApplicationName to set.
97      */

98     public void setJ2EEApplicationName(String JavaDoc applicationName) {
99         j2EEApplicationName = applicationName;
100     }
101
102     /**
103      * @return Returns the j2EEDomainName.
104      */

105     public String JavaDoc getJ2EEDomainName() {
106         return j2EEDomainName;
107     }
108
109     /**
110      * @param domainName The j2EEDomainName to set.
111      */

112     public void setJ2EEDomainName(String JavaDoc domainName) {
113         j2EEDomainName = domainName;
114     }
115
116     /**
117      * @return Returns the j2EEServerName.
118      */

119     public String JavaDoc getJ2EEServerName() {
120         return j2EEServerName;
121     }
122
123     /**
124      * @param serverName The j2EEServerName to set.
125      */

126     public void setJ2EEServerName(String JavaDoc serverName) {
127         j2EEServerName = serverName;
128     }
129
130     /**
131      *
132      * @see org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean#uniqueObjectName(javax.management.MBeanServer,
133      * java.lang.String)
134      */

135     public synchronized ObjectName JavaDoc uniqueObjectName(MBeanServer JavaDoc mbeanServer, String JavaDoc baseObjectName) {
136         ObjectName JavaDoc jsr77Name = null;
137         String JavaDoc context = servletHolder.getHttpContext().getContextPath();
138         if (context.length() == 0) {
139             context = "/";
140         }
141
142         try {
143             jsr77Name = new ObjectName JavaDoc(getJ2EEDomainName()
144                     + ":J2EEServer=" + getJ2EEServerName()
145                     + ",J2EEApplication=" + getJ2EEApplicationName()
146                     + ",WebModule=" + context
147                     + ",j2eeType=Servlet,name=" + servletHolder.getName());
148         } catch (Exception JavaDoc e) {
149             log.warn(LogSupport.EXCEPTION, e);
150         }
151         return jsr77Name;
152     }
153
154 }
155
Popular Tags