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