Skip to main content
summaryrefslogtreecommitdiffstats
blob: ebe2a903f0478365a3adf607c757930d307e5beb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/**********************************************************************
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - Initial API and implementation
 **********************************************************************/
package org.eclipse.wst.server.core.model;

import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.wst.server.core.*;
import org.eclipse.wst.server.core.internal.Server;
import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
/**
 * A server delegate provides the implementation for various 
 * generic and server-type-specific operations for a specific type of server.
 * A server delegate is specified by the
 * <code>class</code> attribute of a <code>serverTypes</code> extension.
 * <p>
 * When the server instance needs to be given a delegate, the delegate class
 * specified for the server type is instantiated with a 0-argument constructor
 * and primed with <code>delegate.initialize(((IServerState)server)</code>, 
 * which it is expected to hang on to. Later, when
 * <code>delegate.dispose()</code> is called as the server instance is
 * being discarded, the delegate is expected to let go of the server instance.
 * </p>
 * <p>
 * ServerDelegate supports an open-ended set of attribute-value pairs. All
 * state stored in this manner will be saved when the server working copy is
 * saved, and persisted across workbench sessions.
 * Server delegates may keep state in instance fields, but that state is
 * transient and will not be persisted across workbench sessions. To save
 * state across workbench sessions, it must be persisted using the
 * attributes.
 * </p>
 * <p>
 * This abstract class is intended to be extended only by clients
 * to extend the <code>serverTypes</code> extension point.
 * </p>
 * 
 * @see IServer
 * @see IServerWorkingCopy
 * @since 1.0
 */
public abstract class ServerDelegate {
	private Server server;
	private ServerWorkingCopy serverWC;

	/**
	 * Delegates must have a public 0-arg constructor.
	 */
	public ServerDelegate() {
		// do nothing
	}

	/**
	 * Initializes this server delegate with its life-long server instance.
	 * <p>
	 * This method is called by the server core framework.
	 * Clients should never call this method.
	 * </p>
	 * 
	 * @param newServer the server instance
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 */
	final void initialize(Server newServer, IProgressMonitor monitor) {
		server = newServer;
		if (newServer instanceof ServerWorkingCopy)
			serverWC = (ServerWorkingCopy) newServer;
		initialize();
	}

	/**
	 * Initializes this server delegate. This method gives delegates a chance
	 * to do their own initialization.
	 * <p>
	 * This method is called by the server core framework.
	 * Clients should never call this method.
	 * </p>
	 */
	protected void initialize() {
		// do nothing
	}

	/**
	 * Returns the server that this server delegate corresponds to.
	 * 
	 * @return the server
	 */
	public final IServer getServer() {
		return server;
	}

	/**
	 * Returns the server working copy that this server delegate corresponds to.
	 * 
	 * @return the server
	 */
	public final IServerWorkingCopy getServerWorkingCopy() {
		return serverWC;
	}

	/**
	 * Returns the value of the specified int-valued attribute.
	 * 
	 * @param id the attribute id
	 * @param defaultValue the default value of the specified attribute
	 * @return the attribute value
	 * @see #setAttribute(String, int)
	 */
	protected final int getAttribute(String id, int defaultValue) {
		return server.getAttribute(id, defaultValue);
	}

	/**
	 * Returns the value of the specified boolean-valued attribute.
	 * 
	 * @param id the attribute id
	 * @param defaultValue the default value of the specified attribute
	 * @return the attribute value
	 * @see #setAttribute(String, boolean)
	 */
	protected final boolean getAttribute(String id, boolean defaultValue) {
		return server.getAttribute(id, defaultValue);
	}

	/**
	 * Returns the value of the specified String-valued attribute.
	 * 
	 * @param id the attribute id
	 * @param defaultValue the default value of the specified attribute
	 * @return the attribute value
	 * @see #setAttribute(String, String)
	 */
	protected final String getAttribute(String id, String defaultValue) {
		return server.getAttribute(id, defaultValue);
	}

	/**
	 * Returns the value of the specified List-valued attribute.
	 * 
	 * @param id the attribute id
	 * @param defaultValue the default value of the specified attribute
	 * @return the attribute value
	 * @see #setAttribute(String, List)
	 */
	protected final List getAttribute(String id, List defaultValue) {
		return server.getAttribute(id, defaultValue);
	}

	/**
	 * Returns the value of the specified Map-valued attribute.
	 * 
	 * @param id the attribute id
	 * @param defaultValue the default value of the specified attribute
	 * @return the attribute value
	 * @see #setAttribute(String, Map)
	 */
	protected final Map getAttribute(String id, Map defaultValue) {
		return server.getAttribute(id, defaultValue);
	}

	/**
	 * Disposes of this server delegate.
	 * <p>
	 * This method is called by the web server core framework.
	 * Clients should never call this method.
	 * </p>
	 * <p>
	 * Implementations are expected to let go of the delegate's reference
	 * to the server, deregister listeners, etc.
	 * </p>
	 */
	public void dispose() {
		// do nothing
	}

	/**
	 * Returns whether the specified module modifications could be made to this
	 * server at this time. See the specification of
	 * {@link IServerAttributes#canModifyModules(IModule[], IModule[], IProgressMonitor)}
	 * for further details. 
	 * <p>
	 * This method is called by the web server core framework,
	 * in response to a call to <code>IServer.canModifyModules</code>.
	 * Clients should never call this method.
	 * </p>
	 * <p>
	 * [issue: See IServerAttributes.canModifyModules(IModule[], IModule[], IProgressMonitor).]
	 * </p>
	 * [issue: doc that it should be quick]
	 *
	 * @param add a possibly-empty list of modules to add
	 * @param remove a possibly-empty list of modules to remove
	 * @return a status object with code <code>IStatus.OK</code> if the modules
	 *   can be modified, otherwise a status object indicating why they can't
	 */
	public abstract IStatus canModifyModules(IModule[] add, IModule[] remove);

	/**
	 * Returns the child module(s) of this module. If this
	 * module contains other modules, it should list those
	 * modules. If not, it should return an empty list.
	 *
	 * <p>This method should only return the direct children.
	 * To obtain the full module tree, this method may be
	 * recursively called on the children.</p>
	 *
	 * @param module a module
	 * @return the child modules
	 * @see IServerAttributes#getChildModules(IModule[], IProgressMonitor)
	 */
	public abstract IModule[] getChildModules(IModule[] module);

	/**
	 * Returns the parent module(s) of this module. When determining if a given
	 * project can run on a server, this method will be used to find the actual
	 * module(s) that may be run on the server. For instance, a Web module may
	 * return a list of EAR modules that it is contained in if the server only
	 * supports configuring EAR modules.
	 *
	 * <p>If the module type is not supported, this method will return null.
	 * If the type is normally supported but there is a configuration
	 * problem or missing parent, etc., this method will fire a CoreException
	 * that may then be presented to the user.</p>
	 *
	 * <p>If it does return valid parent(s), this method will always return
	 * the topmost parent module(s), even if there are a few levels
	 * (a heirarchy) of modules.</p>
	 * 
	 * [issue: should the parameter be IModule[]?]
	 *
	 * @param module a module
	 * @return an array of possible root modules
	 * @throws CoreException if anything went wrong
	 *
	 * @see org.eclipse.wst.server.core.IServerAttributes#getRootModules(IModule, IProgressMonitor)
	 */
	public abstract IModule[] getRootModules(IModule module) throws CoreException;

	/**
	 * Returns an array of IServerPorts that this server has.
	 *
	 * @return the server's ports
	 */
	public ServerPort[] getServerPorts() {
		return null;
	}

	/**
	 * Initializes this server with default values. This method is called when
	 * a new server is created so that the server can be initialized with
	 * meaningful values.
	 * 
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 */
	public void setDefaults(IProgressMonitor monitor) {
		// do nothing
	}
	
	/**
	 * Sets the value of the specified integer-valued attribute of this
	 * element.
	 * 
	 * @param id the attribute id
	 * @param value the value of the specified attribute
	 * @see #getAttribute(String, int)
	 */
	protected final void setAttribute(String id, int value) {
		serverWC.setAttribute(id, value);
	}

	/**
	 * Sets the value of the specified boolean-valued attribute of this
	 * element.
	 * 
	 * @param id the attribute id
	 * @param value the value of the specified attribute
	 * @see #getAttribute(String, boolean)
	 */
	protected final void setAttribute(String id, boolean value) {
		serverWC.setAttribute(id, value);
	}

	/**
	 * Sets the value of the specified string-valued attribute of this
	 * element.
	 * 
	 * @param id the attribute id
	 * @param value the value of the specified attribute
	 * @see #getAttribute(String, String)
	 */
	protected final void setAttribute(String id, String value) {
		serverWC.setAttribute(id, value);
	}

	/**
	 * Sets the value of the specified list-valued attribute of this
	 * element. The list may only contain String values.
	 * 
	 * @param id the attribute id
	 * @param value the value of the specified attribute
	 * @see #getAttribute(String, List)
	 */
	protected final void setAttribute(String id, List value) {
		serverWC.setAttribute(id, value);
	}

	/**
	 * Sets the value of the specified map-valued attribute of this
	 * element. The map may only contain String values.
	 * 
	 * @param id the attribute id
	 * @param value the value of the specified attribute
	 * @see #getAttribute(String, Map)
	 */
	protected final void setAttribute(String id, Map value) {
		serverWC.setAttribute(id, value);
	}

	/**
	 * Modifies the list of modules associated with the server.
	 * See the specification of
	 * {@link IServerWorkingCopy#modifyModules(IModule[], IModule[], IProgressMonitor)}
	 * for further details.
	 * <p>
	 * This method is called by the web server core framework,
	 * in response to a call to <code>IServerWorkingCopy.modifyModules</code>.
	 * Clients should never call this method.
	 * </p>
	 * <p>
	 * This method is called to update the server configuration (if any)
	 * or update the delegates internal state. Note that the actual list
	 * of modules is stored on the server and can be accessed at any time
	 * using server.getModules(). getModules() will not be updated until
	 * after this method successfully returns.
	 * </p>
	 * <p>
	 * This method will not communicate with the server. After saving,
	 * publish() can be used to sync up with the server.
	 * </p>
	 *
	 * @param add a possibly-empty list of modules to add
	 * @param remove a possibly-empty list of modules to remove
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 * @throws CoreException [missing]
	 */
	public abstract void modifyModules(IModule[] add, IModule[] remove, IProgressMonitor monitor) throws CoreException;

	/**
	 * This method is called to import the server configuration from the given
	 * runtime.
	 * 
	 * @param runtime a server runtime
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 */
	public void importConfiguration(IRuntime runtime, IProgressMonitor monitor) {
		// do nothing
	}

	/**
	 * This method is called whenever the server configuration should be saved.
	 * 
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 * @throws CoreException if there was a problem saving
	 */
	public void saveConfiguration(IProgressMonitor monitor) throws CoreException {
		// do nothing
	}

	/**
	 * This method is called whenever the server configuration folder has changed.
	 * It gives the server a chance to throw out any old data and be ready to
	 * reload the server configuration when it is needed next.
	 */
	public void configurationChanged() {
		// do nothing
	}
}

Back to the top