KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > jsr77 > JSR77ManagementIdentifier


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@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: JSR77ManagementIdentifier.java 643 2006-06-13 11:44:43Z sauthieg $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.jsr77;
27
28 import java.util.Hashtable JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import javax.management.MalformedObjectNameException JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33
34 import org.objectweb.easybeans.api.jmx.EZBManagementIdentifier;
35 import org.objectweb.easybeans.log.JLog;
36 import org.objectweb.easybeans.log.JLogFactory;
37
38 /**
39  * Specialized {@link EZBManagementIdentifier} for JSR77 MBeans.
40  * @author Guillaume Sauthier
41  *
42  * @param <T> Managed Type
43  */

44 public abstract class JSR77ManagementIdentifier<T> implements EZBManagementIdentifier<T> {
45
46     /**
47      * Logger.
48      */

49     private static JLog logger = JLogFactory.getLog(JSR77ManagementIdentifier.class);
50
51     /**
52      * Empty default constructor.
53      */

54     protected JSR77ManagementIdentifier() { }
55
56     /**
57      * @param name base ObjectName
58      * @return Returns a String that contains "inherited" properties from
59      * parent's ObjectName
60      */

61     protected static String JavaDoc getInheritedPropertiesAsString(final ObjectName JavaDoc name) {
62         Hashtable JavaDoc table = (Hashtable JavaDoc) name.getKeyPropertyList().clone();
63         // we remove some attributes from the ObjectName
64
table.remove("j2eeType");
65         table.remove("type");
66         table.remove("subtype");
67         table.remove("name");
68         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
69         for (Iterator JavaDoc i = table.keySet().iterator(); i.hasNext();) {
70             String JavaDoc key = (String JavaDoc) i.next();
71             sb.append(key + "=" + table.get(key) + ",");
72         }
73         if (sb.length() > 1) {
74             // remove the trailing comma
75
sb.setLength(sb.length() - 1);
76         }
77         return sb.toString();
78     }
79
80     /**
81      * @param parentObjectName Parent ObjectName.
82      * @return Returns the couple j2eetype=name of the parent ObjectName.
83      */

84     protected static String JavaDoc getParentNameProperty(final String JavaDoc parentObjectName) {
85         ObjectName JavaDoc on = null;
86         try {
87             on = ObjectName.getInstance(parentObjectName);
88         } catch (MalformedObjectNameException JavaDoc e) {
89             // TODO Add a log statement
90
return "";
91         } catch (NullPointerException JavaDoc e) {
92             // TODO Add a log statement
93
return "";
94         }
95
96         String JavaDoc type = on.getKeyProperty("j2eeType");
97         String JavaDoc name = on.getKeyProperty("name");
98
99         return type + "=" + name;
100     }
101
102     /**
103      * {@inheritDoc}
104      */

105     public String JavaDoc getDomain() {
106         // TODO Should be configurable
107
return "";
108     }
109
110     /**
111      * {@inheritDoc}
112      */

113     public String JavaDoc getTypeName() {
114         return "j2eeType";
115     }
116
117     /**
118      * {@inheritDoc}
119      */

120     public String JavaDoc getTypeProperty() {
121         // TODO Move in an AbstractManagementIdentifier
122
return getTypeName() + "=" + getTypeValue();
123     }
124
125     /**
126      * @return the logger
127      */

128     public static final JLog getLogger() {
129         return logger;
130     }
131
132 }
133
Popular Tags