01: package org.andromda.core;
02:
03: import org.andromda.core.common.AndroMDALogger;
04: import org.andromda.core.common.ComponentContainer;
05: import org.andromda.core.configuration.Configuration;
06: import org.andromda.core.server.Client;
07: import org.andromda.core.server.ClientException;
08: import org.andromda.core.server.Server;
09: import org.andromda.core.server.ServerException;
10:
11: /**
12: * Provides the ability to manage an AndroMDA server instance.
13: *
14: * @see org.andromda.core.server.Server
15: * @author Chad Brandon
16: */
17: public class AndroMDAServer {
18: /**
19: * The actual server instance.
20: */
21: private Server server;
22:
23: /**
24: * Creates a new instance of class.
25: *
26: * @return the new instance.
27: */
28: public static AndroMDAServer newInstance() {
29: return new AndroMDAServer();
30: }
31:
32: private AndroMDAServer() {
33: AndroMDALogger.initialize();
34: this .server = (Server) ComponentContainer.instance()
35: .findRequiredComponent(Server.class);
36: }
37:
38: /**
39: * Starts the AndroMDA server instance listening for requests.
40: *
41: * @param configuration the Configuration instance used to configure the
42: * server.
43: */
44: public void start(final Configuration configuration) {
45: if (configuration == null) {
46: throw new ServerException(
47: "You must specify a valid 'configuration' in order to start the server");
48: }
49: final org.andromda.core.configuration.Server serverConfiguration = configuration
50: .getServer();
51: if (serverConfiguration == null) {
52: AndroMDALogger
53: .warn("Can not start the server, you must define the "
54: + "server element within your AndroMDA configuration");
55: } else {
56: this .server.start(configuration);
57: }
58: }
59:
60: /**
61: * Stops the AndroMDA server instance.
62: */
63: public void stop(final Configuration configuration) {
64: final ComponentContainer container = ComponentContainer
65: .instance();
66: final Client serverClient = (Client) container
67: .findComponent(Client.class);
68: if (serverClient != null) {
69: try {
70: serverClient.stop(configuration);
71: } catch (final Throwable throwable) {
72: throw new ClientException(throwable);
73: }
74: }
75: }
76: }
|