KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > model > connector > AbstractConnectionService


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.model.connector;
14
15
16
17 import javax.management.MBeanServer JavaDoc;
18
19
20
21 import org.ejtools.jmx.browser.model.service.ConnectionService;
22
23 import org.ejtools.util.service.Profile;
24
25
26
27 /**
28
29  * Abstract connection that holds some common behaviour for the connectors
30
31  *
32
33  * @author letiembl
34
35  * @created 4 septembre 2002
36
37  * @version $Revision: 1.6 $
38
39  */

40
41 public abstract class AbstractConnectionService implements ConnectionService
42
43 {
44
45    /** Connected state */
46
47    protected boolean connected = false;
48
49    /** The connection profile */
50
51    protected Profile profile = null;
52
53    /** The proxied MBean server */
54
55    protected MBeanServer JavaDoc server = null;
56
57
58
59
60
61    /**Constructor for the AbstractConnectionService object */
62
63    protected AbstractConnectionService() { }
64
65
66
67
68
69    /**
70
71     * Connect to the MBean server with this profile
72
73     *
74
75     * @param profile Connection profile
76
77     */

78
79    public void connect(Profile profile)
80
81    {
82
83       this.profile = profile;
84
85       try
86
87       {
88
89          this.createMBeanServer();
90
91          this.setConnected(true);
92
93       }
94
95       catch (Exception JavaDoc e)
96
97       {
98
99          e.printStackTrace();
100
101          this.setConnected(false);
102
103       }
104
105    }
106
107
108
109
110
111    /** Disconnect from the MBean server */
112
113    public void disconnect() { }
114
115
116
117
118
119    /**
120
121     * Gets the proxied MBean server
122
123     *
124
125     * @return The MBeanServer proxy
126
127     */

128
129    public MBeanServer JavaDoc getMBeanServer()
130
131    {
132
133       if (!this.connected)
134
135       {
136
137          throw new IllegalStateException JavaDoc("The service is not connected. Call 'connect' method before.");
138
139       }
140
141       if (this.server == null)
142
143       {
144
145          throw new IllegalStateException JavaDoc("The server is null. Call 'connect' method before.");
146
147       }
148
149       return this.server;
150
151    }
152
153
154
155
156
157    /**
158
159     * Return whether the connector is connector
160
161     *
162
163     * @return true if connected
164
165     */

166
167    public boolean isConnected()
168
169    {
170
171       return this.connected;
172
173    }
174
175
176
177
178
179    /**
180
181     * Sets the connection state value
182
183     *
184
185     * @param connected The connection state
186
187     */

188
189    public void setConnected(boolean connected)
190
191    {
192
193       this.connected = connected;
194
195    }
196
197
198
199
200
201    /**
202
203     * Create the proxy to the MBean server. This method must set the MBean server after a successful creation.
204
205     *
206
207     * @exception Exception Description of the Exception
208
209     */

210
211    protected abstract void createMBeanServer()
212
213       throws Exception JavaDoc;
214
215
216
217
218
219    /**
220
221     * Sets the MBeanServer proxy for this connector
222
223     *
224
225     * @param server The MBeanServer proxy
226
227     */

228
229    protected void setMBeanServer(MBeanServer JavaDoc server)
230
231    {
232
233       this.server = server;
234
235    }
236
237 }
238
239
Popular Tags