View Javadoc
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   * Provides the ability to manage an AndroMDA server instance.
13   *
14   * @see org.andromda.core.server.Server
15   * @author Chad Brandon
16   */
17  public final class AndroMDAServer
18  {
19      /**
20       * The actual server instance.
21       */
22      private Server server;
23  
24      /**
25       * Creates a new instance of class.
26       *
27       * @return the new instance.
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       * Starts the AndroMDA server instance listening for requests.
42       *
43       * @param configuration the Configuration instance used to configure the server.
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       * Stops the AndroMDA server instance.
65       * @param configuration the Configuration instance used to configure the server.
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  }