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
14
15
16
17 public final class AndroMDAServer
18 {
19
20
21
22 private Server server;
23
24
25
26
27
28
29 public static AndroMDAServer newInstance()
30 {
31 return new AndroMDAServer();
32 }
33
34 private AndroMDAServer()
35 {
36 AndroMDALogger.initialize();
37 this.server = (Server)ComponentContainer.instance().findRequiredComponent(Server.class);
38 }
39
40
41
42
43
44
45 public void start(final Configuration configuration)
46 {
47 if (configuration == null)
48 {
49 throw new ServerException("You must specify a valid 'configuration' in order to start the server");
50 }
51 final org.andromda.core.configuration.Server serverConfiguration = configuration.getServer();
52 if (serverConfiguration == null)
53 {
54 AndroMDALogger.warn(
55 "Can not start the server, you must define the " + "server element within your AndroMDA configuration");
56 }
57 else
58 {
59 this.server.start(configuration);
60 }
61 }
62
63
64
65
66
67 public void stop(final Configuration configuration)
68 {
69 final ComponentContainer container = ComponentContainer.instance();
70 final Client serverClient = (Client)container.findComponent(Client.class);
71 if (serverClient != null)
72 {
73 try
74 {
75 serverClient.stop(configuration);
76 }
77 catch (final Throwable throwable)
78 {
79 throw new ClientException(throwable);
80 }
81 }
82 }
83 }