KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > jetty > servlet > jmx > HolderMBean


1 // ========================================================================
2
// $Id: HolderMBean.java,v 1.5 2005/08/13 00:01:27 gregwilkins Exp $
3
// Copyright 200-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.jetty.servlet.jmx;
17
18 import javax.management.MBeanException JavaDoc;
19 import javax.management.MBeanServer JavaDoc;
20 import javax.management.ObjectName JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.mortbay.log.LogFactory;
24 import org.mortbay.jetty.servlet.Holder;
25 import org.mortbay.util.LogSupport;
26 import org.mortbay.util.jmx.LifeCycleMBean;
27
28
29 /* ------------------------------------------------------------ */
30 /**
31  *
32  * @version $Revision: 1.5 $
33  * @author Greg Wilkins (gregw)
34  */

35 public class HolderMBean extends LifeCycleMBean
36 {
37     private static Log log = LogFactory.getLog(HolderMBean.class);
38
39     /* ------------------------------------------------------------ */
40     private Holder _holder;
41     
42     /* ------------------------------------------------------------ */
43     /** Constructor.
44      * @exception MBeanException
45      */

46     public HolderMBean()
47         throws MBeanException JavaDoc
48     {}
49     
50     /* ------------------------------------------------------------ */
51     protected void defineManagedResource()
52     {
53         super.defineManagedResource();
54         
55         defineAttribute("name");
56         defineAttribute("displayName");
57         defineAttribute("className");
58         defineAttribute("initParameters",READ_ONLY,ON_MBEAN);
59         
60         _holder=(Holder)getManagedResource();
61     }
62     
63     /* ---------------------------------------------------------------- */
64     public String JavaDoc getInitParameters()
65     {
66         return ""+_holder.getInitParameters();
67     }
68     
69     /* ------------------------------------------------------------ */
70     public synchronized ObjectName JavaDoc uniqueObjectName(MBeanServer JavaDoc server,
71                                                     String JavaDoc objectName)
72     {
73         try
74         {
75             String JavaDoc name=_holder.getDisplayName();
76             if (name==null || name.length()==0)
77                 name=_holder.getClassName();
78             return new ObjectName JavaDoc(objectName+",name="+name);
79         }
80         catch(Exception JavaDoc e)
81         {
82             log.warn(LogSupport.EXCEPTION,e);
83             return super.uniqueObjectName(server,objectName);
84         }
85     }
86 }
87
Popular Tags