KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > registration > support > RegistrationAware


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.registration.support;
9
10 import javax.management.MBeanRegistration;
11 import javax.management.ObjectName;
12 import javax.management.MBeanServer;
13
14 public class RegistrationAware implements RegistrationAwareMBean, MBeanRegistration
15 {
16    private String something;
17
18    private boolean preRegisterCalled = false;
19    private boolean preDeRegisterCalled = false;
20    private boolean postRegisterCalled = false;
21    private boolean postDeRegisterCalled = false;
22    private boolean postRegisterRegistrationDone = false;
23
24    private MBeanServer registeredServer = null;
25    private ObjectName registeredObjectName = null;
26
27    private Exception exceptionOnPreRegister = null;
28    private Exception exceptionOnPreDeRegister = null;
29
30    private ObjectName alternateObjectName = null;
31    private boolean returnAlternateObjectName = false;
32
33    public RegistrationAware()
34    {
35    }
36
37    public void setSomething(String something)
38    {
39       this.something = something;
40    }
41
42    public String getSomething()
43    {
44       return something;
45    }
46
47
48    public ObjectName preRegister(MBeanServer server, ObjectName name)
49       throws Exception
50    {
51       preRegisterCalled = true;
52       registeredServer = server;
53       registeredObjectName = name;
54
55       if (null != exceptionOnPreRegister)
56       {
57          exceptionOnPreRegister.fillInStackTrace();
58          throw exceptionOnPreRegister;
59       }
60
61       if (returnAlternateObjectName)
62       {
63          return alternateObjectName;
64       }
65
66       return name;
67    }
68
69    // MBeanRegistration impl -------------------------------------
70
public void postRegister(Boolean registrationDone)
71    {
72       postRegisterCalled = true;
73       postRegisterRegistrationDone = registrationDone.booleanValue();
74    }
75
76    public void preDeregister()
77       throws Exception
78    {
79       preDeRegisterCalled = true;
80
81       if (null != exceptionOnPreDeRegister)
82       {
83          exceptionOnPreDeRegister.fillInStackTrace();
84          throw exceptionOnPreDeRegister;
85       }
86    }
87
88    public void postDeregister()
89    {
90       postDeRegisterCalled = true;
91    }
92
93    // Settings setters -------------------------------------------
94
public void setExceptionOnPreRegister(Exception exceptionOnPreRegister)
95    {
96       this.exceptionOnPreRegister = exceptionOnPreRegister;
97    }
98
99    public void setExceptionOnPreDeRegister(Exception exceptionOnPreDeRegister)
100    {
101       this.exceptionOnPreDeRegister = exceptionOnPreDeRegister;
102    }
103
104    public void setAlternateObjectName(ObjectName alternateObjectName)
105    {
106       this.returnAlternateObjectName = true;
107       this.alternateObjectName = alternateObjectName;
108    }
109
110    // Status getters ---------------------------------------------
111
public boolean isPreRegisterCalled()
112    {
113       return preRegisterCalled;
114    }
115
116    public boolean isPreDeRegisterCalled()
117    {
118       return preDeRegisterCalled;
119    }
120
121    public boolean isPostRegisterCalled()
122    {
123       return postRegisterCalled;
124    }
125
126    public boolean isPostDeRegisterCalled()
127    {
128       return postDeRegisterCalled;
129    }
130
131    public boolean isPostRegisterRegistrationDone()
132    {
133       return postRegisterRegistrationDone;
134    }
135
136    public MBeanServer getRegisteredServer()
137    {
138       return registeredServer;
139    }
140
141    public ObjectName getRegisteredObjectName()
142    {
143       return registeredObjectName;
144    }
145 }
146
Popular Tags