KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jmx > export > naming > IdentityNamingStrategy


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jmx.export.naming;
18
19 import java.util.Hashtable JavaDoc;
20
21 import javax.management.MalformedObjectNameException JavaDoc;
22 import javax.management.ObjectName JavaDoc;
23
24 import org.springframework.jmx.support.ObjectNameManager;
25 import org.springframework.util.ClassUtils;
26 import org.springframework.util.ObjectUtils;
27
28 /**
29  * An implementation of the <code>ObjectNamingStrategy</code> interface that
30  * creates a name based on the the identity of a given instance.
31  *
32  * <p>The resulting <code>ObjectName</code> will be in the form
33  * <i>package</i>:class=<i>class name</i>,hashCode=<i>identity hash (in hex)</i>
34  *
35  * @author Rob Harrop
36  * @since 1.2
37  */

38 public class IdentityNamingStrategy implements ObjectNamingStrategy {
39
40     public static final String JavaDoc TYPE_KEY = "type";
41
42     public static final String JavaDoc HASH_CODE_KEY = "hashCode";
43
44
45     /**
46      * Returns an instance of <code>ObjectName</code> based on the identity
47      * of the managed resource.
48      */

49     public ObjectName JavaDoc getObjectName(Object JavaDoc managedBean, String JavaDoc beanKey) throws MalformedObjectNameException JavaDoc {
50         String JavaDoc domain = managedBean.getClass().getPackage().getName();
51
52         Hashtable JavaDoc keys = new Hashtable JavaDoc();
53         keys.put(TYPE_KEY, ClassUtils.getShortName(managedBean.getClass()));
54         keys.put(HASH_CODE_KEY, ObjectUtils.getIdentityHexString(managedBean));
55
56         return ObjectNameManager.getInstance(domain, keys);
57     }
58
59 }
60
Popular Tags