EMMA Coverage Report (generated Thu Aug 04 11:43:22 MEST 2005)
[all classes][org.jsesoft.mmbi]

COVERAGE SUMMARY FOR SOURCE FILE [NamedModelMBean.java]

nameclass, %method, %block, %line, %
NamedModelMBean.java100% (1/1)75%  (6/8)62%  (43/69)64%  (14/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NamedModelMBean100% (1/1)75%  (6/8)62%  (43/69)64%  (14/22)
removeNotificationListener (NotificationListener): void 0%   (0/1)0%   (0/11)0%   (0/4)
removeNotificationListener (NotificationListener, NotificationFilter, Object)... 0%   (0/1)0%   (0/15)0%   (0/4)
NamedModelMBean (): void 100% (1/1)100% (3/3)100% (2/2)
addNotificationListener (NotificationListener, NotificationFilter, Object): void 100% (1/1)100% (15/15)100% (4/4)
getInstance (): ObjectInstance 100% (1/1)100% (3/3)100% (1/1)
getName (): ObjectName 100% (1/1)100% (4/4)100% (1/1)
setInstance (ObjectInstance): void 100% (1/1)100% (4/4)100% (2/2)
setManagedResource (Object, String): void 100% (1/1)100% (14/14)100% (4/4)

1/**
2 * Class <code>NamedModelMBean</code>.
3 */
4package org.jsesoft.mmbi;
5 
6import javax.management.*;
7import javax.management.modelmbean.*;
8 
9/**
10 * Couples the Model MBean with its <code>ObjectInstance</code>
11 * information (eg <code>ObjectName</code>).
12 *
13 * <p>
14 * This convenience class provides a ModelMBean with attached
15 * <code>ObjectInstance</code> information. Especially, it provides
16 * the <code>ObjectName</code>.
17 * </p>
18 * <p>
19 * If the managed resource emits JMX notification (i.e. implements
20 * the <code>NotificationEmitter</code> interface, adding and removing
21 * Notification listeners is forwarded to the managed resource (which
22 * should be done by the <code>RequiredModelMBean</code>).
23 * </p>
24 * <p>
25 * <b>Example:</b>
26 * <code>
27 * <pre>
28 * NamedModelMBean mbean = new NamedModelMBean();
29 * mbean.setModelMBeanInfo( ... );
30 * mbean.setManagedResource( ..., "ObjectReference");
31 * ObjectName objectName = new ObjectName( ... );
32 * MBeanServer server =
33 *     java.lang.management.ManagementFactory.getPlatformMBeanServer();
34 * mbean.setInstance( server.registerMBean( mbean, objectName ) );
35 * ...
36 * server.unregisterMBean( mbean.getName() );
37 * </pre>
38 * </code>
39 * </p>
40 
41 * @author JSESoft
42 * @version 1.0
43 */
44public class NamedModelMBean
45    extends RequiredModelMBean
46{
47 
48    /**
49     * The attached object instance.
50     */
51    private ObjectInstance instance;
52 
53    private NotificationEmitter resource;
54 
55 
56    /**
57     * Creates an <code>NamedModelMBean</code> instance from the
58     * <code>RequiredModelMBean</code>.
59     *
60     * @throws Exception if <code>RequiredModelMBean</code> construction fails
61     */
62    public NamedModelMBean()
63        throws Exception
64    {
65    }
66 
67    /**
68     * Sets the instance attribute.
69     *
70     * @see #getInstance
71     * @param instance ObjectInstance
72     */
73    public void setInstance( ObjectInstance instance )
74    {
75        this.instance = instance;
76    }
77 
78    /**
79     * Gets the instance attribute.
80     *
81     * @return the instance value (maybe null)
82     * @see #setInstance
83     */
84    public ObjectInstance getInstance()
85    {
86        return instance;
87    }
88 
89    /**
90     * Gets the object name.
91     *
92     * @return the MBean's object name from the instance.
93     */
94    public ObjectName getName()
95    {
96        return getInstance().getObjectName();
97    }
98 
99    /**
100     * Sets the manages resource (and remembers ist).
101     */
102    @Override
103    public void setManagedResource( Object managed, String type )
104      throws MBeanException, RuntimeOperationsException,
105      InstanceNotFoundException, InvalidTargetObjectTypeException
106    {
107      if( NotificationEmitter.class.isInstance( managed ) ) {
108        this.resource = ( NotificationEmitter ) managed;
109      }
110      super.setManagedResource( resource, type );
111    }
112 
113    /**
114     * Adds a notification listener (to the managed resource as well).
115     *
116     * @see #removeNotificationListener
117     */
118    @Override
119    public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
120    {
121      if( resource != null ) {
122        resource.addNotificationListener( listener, filter, handback );
123      }
124      super.addNotificationListener( listener, filter, handback );
125    }
126 
127    /**
128     * Removes a notification listener (from the managed resource as well).
129     *
130     * @see #addNotificationListener
131     */
132    @Override
133    public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
134      throws ListenerNotFoundException
135    {
136      if( resource != null ) {
137        resource.removeNotificationListener( listener, filter, handback );
138      }
139      super.removeNotificationListener( listener, filter, handback );
140    }
141 
142    /**
143     * Removes a notification listener (from the managed resource as well).
144     *
145     * @see #addNotificationListener
146     */
147    @Override
148    public void removeNotificationListener(NotificationListener listener)
149      throws ListenerNotFoundException
150    {
151      if( resource != null ) {
152        resource.removeNotificationListener( listener );
153      }
154      super.removeNotificationListener( listener );
155    }
156}

[all classes][org.jsesoft.mmbi]
EMMA 2.0.5312 (C) Vladimir Roubtsov