File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\jmx\DocumentedMBean.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.jmx;
8
9 import java.io.ByteArrayInputStream;
10 import java.io.IOException;
11 import java.util.Properties;
12 import javax.management.MBeanAttributeInfo;
13 import javax.management.MBeanInfo;
14 import javax.management.MBeanOperationInfo;
15 import javax.management.NotCompliantMBeanException;
16 import javax.management.StandardMBean;
17 import org.h2.util.Utils;
18
19 /**
20 * An MBean that reads the documentation from a resource file.
21 */
22 public class DocumentedMBean extends StandardMBean {
23
24 private final String interfaceName;
25 private Properties resources;
26
27 public <T> DocumentedMBean(T impl, Class<T> mbeanInterface) throws NotCompliantMBeanException {
28 super(impl, mbeanInterface);
29 this.interfaceName = impl.getClass().getName() + "MBean";
30 }
31
32 private Properties getResources() {
33 if (resources == null) {
34 resources = new Properties();
35 String resourceName = "/org/h2/res/javadoc.properties";
36 try {
37 byte[] buff = Utils.getResource(resourceName);
38 if (buff != null) {
39 resources.load(new ByteArrayInputStream(buff));
40 }
41 } catch (IOException e) {
42 // ignore
43 }
44 }
45 return resources;
46 }
47
48 @Override
49 protected String getDescription(MBeanInfo info) {
50 String s = getResources().getProperty(interfaceName);
51 return s == null ? super.getDescription(info) : s;
52 }
53
54 @Override
55 protected String getDescription(MBeanOperationInfo op) {
56 String s = getResources().getProperty(interfaceName + "." + op.getName());
57 return s == null ? super.getDescription(op) : s;
58 }
59
60 @Override
61 protected String getDescription(MBeanAttributeInfo info) {
62 String prefix = info.isIs() ? "is" : "get";
63 String s = getResources().getProperty(interfaceName + "." + prefix + info.getName());
64 return s == null ? super.getDescription(info) : s;
65 }
66
67 @Override
68 protected int getImpact(MBeanOperationInfo info) {
69 if (info.getName().startsWith("list")) {
70 return MBeanOperationInfo.INFO;
71 }
72 return MBeanOperationInfo.ACTION;
73 }
74
75 }
76