01: package org.andromda.core.engine;
02:
03: import org.andromda.core.configuration.Configuration;
04: import org.andromda.core.metafacade.ModelValidationMessage;
05:
06: /**
07: * The <em>engine</em> of AndroMDA. Handles the configuration of AndroMDA and
08: * loading/processing of models by plugins. Basically a wrapper around the {@link ModelProcessor}
09: * that takes a configuration file in order to configure AndroMDA.
10: *
11: * @see ModelProcessor
12: * @author Chad Brandon
13: */
14: public class Engine {
15: /**
16: * Create a new Engine instance.
17: *
18: * @return the new instance of Engine.
19: */
20: public static Engine newInstance() {
21: return new Engine();
22: }
23:
24: /**
25: * The model processor for this engine.
26: */
27: private ModelProcessor modelProcessor;
28:
29: private Engine() {
30: // do not allow instantiation
31: this .modelProcessor = ModelProcessor.newInstance();
32: }
33:
34: /**
35: * Initializes Engine (discovers all plugins, etc) with the
36: * given configuration. This configuration is overridden (if changed)
37: * when calling {@link #run(Configuration)}.
38: */
39: public void initialize(final Configuration configuration) {
40: this .modelProcessor.initialize(configuration);
41: }
42:
43: /**
44: * Checks to see if any of the models in the given configuration
45: * should be loaded (based on whether or not they've been modified),
46: * and if so, performs the load. This way the
47: * models are loaded for the next run of the model processor.
48: *
49: * @param configuration the AndroMDA configuration the contains the repositories containing
50: * the models to load.
51: */
52: public ModelValidationMessage[] loadModelsIfNecessary(
53: final Configuration configuration) {
54: ModelValidationMessage[] messages = null;
55: if (configuration != null) {
56: messages = (ModelValidationMessage[]) this .modelProcessor
57: .loadIfNecessary(configuration.getRepositories())
58: .toArray(new ModelValidationMessage[0]);
59: }
60: return messages == null ? new ModelValidationMessage[0]
61: : messages;
62: }
63:
64: /**
65: * Runs Engine with the given configuration.
66: *
67: * @param configuration the String that contains the configuration
68: * contents for configuring Engine.
69: *
70: * @return the new instance of Engine.
71: */
72: public ModelValidationMessage[] run(
73: final Configuration configuration) {
74: ModelValidationMessage[] messages = null;
75: if (configuration != null) {
76: messages = this .modelProcessor.process(configuration);
77: }
78: return messages == null ? new ModelValidationMessage[0]
79: : messages;
80: }
81:
82: /**
83: * Shuts down this instance.
84: */
85: public void shutdown() {
86: this.modelProcessor.shutdown();
87: }
88: }
|