KickJava   Java API By Example, From Geeks To Geeks.

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


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.WebApplicationContext;
32 import org.mortbay.util.LogSupport;
33 import org.mortbay.util.jmx.ModelMBeanImpl;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 /**
39  * Fake (at least not complete) implementation of the WebModule MBean.
40  * TODO for a full implementation, the MBean should be able to return
41  * a real ObjectName array for Servlets inside the WebApp.
42  *
43  * @author Guillaume Sauthier
44  */

45 public class J2EEWebModuleMBean extends ModelMBeanImpl {
46
47     /**
48      * logger
49      */

50     private static Log log = LogFactory.getLog(J2EEWebModuleMBean.class);
51
52     /**
53      * Monitored WebApp
54      */

55     private WebApplicationContext waContext = null;
56
57     /**
58      * list of Servlet's ObjectNames
59      */

60     private ObjectName JavaDoc[] servlets = null;
61
62     /**
63      * Default public MBean Constructor
64      * @throws MBeanException required by the spec
65      */

66     public J2EEWebModuleMBean() throws MBeanException JavaDoc {
67         super();
68     }
69
70     /**
71      * @see org.mortbay.util.jmx.ModelMBeanImpl#defineManagedResource()
72      */

73     protected void defineManagedResource() {
74         // TODO Auto-generated method stub
75
super.defineManagedResource();
76         defineAttribute("servlets", READ_ONLY, ON_MBEAN);
77         waContext = (WebApplicationContext) getManagedResource();
78     }
79
80     /**
81      * @return Returns the servlets.
82      */

83     public ObjectName JavaDoc[] getServlets() {
84         return servlets;
85     }
86
87     /**
88      *
89      * @see org.mortbay.jetty.servlet.jsr77.jmx.Jsr77ServletHolderMBean#uniqueObjectName(javax.management.MBeanServer,
90      * java.lang.String)
91      */

92     public synchronized ObjectName JavaDoc uniqueObjectName(MBeanServer JavaDoc mbeanServer, String JavaDoc baseObjectName) {
93         ObjectName JavaDoc jsr77Name = null;
94
95         // get the context name
96
String JavaDoc context = waContext.getHttpContext().getContextPath();
97         if (context.length() == 0) {
98             context = "/";
99         }
100
101         try {
102             jsr77Name = new ObjectName JavaDoc(waContext.getAttribute("J2EEDomainName")
103                     + ":J2EEServer=" + waContext.getAttribute("J2EEServerName")
104                     + ",J2EEApplication=" + waContext.getAttribute("J2EEApplicationName")
105                     + ",j2eeType=WebModule,name=" + context);
106         } catch (Exception JavaDoc e) {
107             log.warn(LogSupport.EXCEPTION, e);
108         }
109         return jsr77Name;
110     }
111
112 }
113
Popular Tags