KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > registration > support > RegistrationAware


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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