EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.jmx]

COVERAGE SUMMARY FOR SOURCE FILE [DocumentedMBean.java]

nameclass, %method, %block, %line, %
DocumentedMBean.java100% (1/1)100% (6/6)88%  (109/124)88%  (19.4/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DocumentedMBean100% (1/1)100% (6/6)88%  (109/124)88%  (19.4/22)
getDescription (MBeanInfo): String 100% (1/1)71%  (10/14)86%  (1.7/2)
getImpact (MBeanOperationInfo): int 100% (1/1)78%  (7/9)67%  (2/3)
getDescription (MBeanOperationInfo): String 100% (1/1)83%  (20/24)92%  (1.8/2)
getDescription (MBeanAttributeInfo): String 100% (1/1)88%  (29/33)95%  (2.8/3)
getResources (): Properties 100% (1/1)96%  (26/27)89%  (8/9)
DocumentedMBean (Object, Class): void 100% (1/1)100% (17/17)100% (3/3)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.jmx;
7 
8import java.io.ByteArrayInputStream;
9import java.io.IOException;
10import java.util.Properties;
11import javax.management.MBeanAttributeInfo;
12import javax.management.MBeanInfo;
13import javax.management.MBeanOperationInfo;
14import javax.management.NotCompliantMBeanException;
15import javax.management.StandardMBean;
16import org.h2.util.Utils;
17 
18/**
19 * An MBean that reads the documentation from a resource file.
20 */
21public class DocumentedMBean extends StandardMBean {
22 
23    private final String interfaceName;
24    private Properties resources;
25 
26    public <T> DocumentedMBean(T impl, Class<T> mbeanInterface)
27            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(
64                interfaceName + "." + prefix + info.getName());
65        return s == null ? super.getDescription(info) : s;
66    }
67 
68    @Override
69    protected int getImpact(MBeanOperationInfo info) {
70        if (info.getName().startsWith("list")) {
71            return MBeanOperationInfo.INFO;
72        }
73        return MBeanOperationInfo.ACTION;
74    }
75 
76}

[all classes][org.h2.jmx]
EMMA 2.0.5312 (C) Vladimir Roubtsov