6161import fr .inria .diverse .trace .commons .model .trace .ModelURIParameter ;
6262import fr .inria .diverse .trace .commons .model .trace .TraceFactory ;
6363
64+ /**
65+ * Implementation of the GEMOC Execution engine dedicated to run Kermeta 3 operational semantic
66+ *
67+ * @author Didier Vojtisek<didier.vojtisek@inria.fr>
68+ *
69+ */
6470public class PlainK3ExecutionEngine extends AbstractCommandBasedSequentialExecutionEngine implements IStepManager {
6571
6672 private Method initializeMethod ;
@@ -94,8 +100,8 @@ protected void prepareEntryPoint(IExecutionContext executionContext) {
94100 /*
95101 * Find the entry point in the workspace
96102 */
97- final String PREFIX = "public static void " ;
98- int startName = PREFIX .length ();
103+ final String prefix = "public static void " ;
104+ int startName = prefix .length ();
99105 int endName = entryPoint .lastIndexOf ("(" );
100106 String methodFullName = entryPoint .substring (startName , endName );
101107
@@ -191,18 +197,18 @@ protected void prepareInitializeModel(IExecutionContext executionContext) {
191197 "Could not find method " + modelInitializationMethodName + " with correct parameters." );
192198 }
193199 }
194- final boolean final_isListArgs = isListArgs ;
195- final boolean final_isEListArgs = isEListArgs ;
200+ final boolean finalIsListArgs = isListArgs ;
201+ final boolean finalIsEListArgs = isEListArgs ;
196202 this .initializeMethodParameters = new ArrayList <>();
197203 initializeMethodParameters .add (entryPointMethodParameters .get (0 ));
198- if (final_isListArgs ) {
204+ if (finalIsListArgs ) {
199205 final ArrayList <Object > modelInitializationListParameters = new ArrayList <>();
200206 for (String s : executionContext .getRunConfiguration ().getModelInitializationArguments ()
201207 .split ("\\ r?\\ n" )) {
202208 modelInitializationListParameters .add (s );
203209 }
204210 initializeMethodParameters .add (modelInitializationListParameters );
205- } else if (final_isEListArgs ) {
211+ } else if (finalIsEListArgs ) {
206212 final EList <Object > modelInitializationListParameters = new BasicEList <>();
207213 for (String s : executionContext .getRunConfiguration ().getModelInitializationArguments ()
208214 .split ("\\ r?\\ n" )) {
@@ -216,9 +222,10 @@ protected void prepareInitializeModel(IExecutionContext executionContext) {
216222 }
217223 }
218224
219- @ Override
220- protected void initializeModel () {
221- StepManagerRegistry .getInstance ().registerManager (PlainK3ExecutionEngine .this );
225+ /**
226+ * Invoke the initialize method
227+ */
228+ private void callInitializeModel () {
222229 try {
223230 initializeMethod .invoke (null , initializeMethodParameters .toArray ());
224231 } catch (EngineStoppedException stopExeception ) {
@@ -233,6 +240,26 @@ protected void initializeModel() {
233240 }
234241 } catch (Exception e ) {
235242 throw new RuntimeException (e );
243+ }
244+ }
245+
246+ @ Override
247+ protected void initializeModel () {
248+ StepManagerRegistry .getInstance ().registerManager (PlainK3ExecutionEngine .this );
249+ try {
250+ final boolean isStepMethod = initializeMethod .isAnnotationPresent (fr .inria .diverse .k3 .al .annotationprocessor .Step .class );
251+ if (!isStepMethod ){
252+ fr .inria .diverse .k3 .al .annotationprocessor .stepmanager .StepCommand command = new fr .inria .diverse .k3 .al .annotationprocessor .stepmanager .StepCommand () {
253+ @ Override
254+ public void execute () {
255+ callInitializeModel ();
256+ }
257+ };
258+ fr .inria .diverse .k3 .al .annotationprocessor .stepmanager .IStepManager stepManager = PlainK3ExecutionEngine .this ;
259+ stepManager .executeStep (entryPointMethodParameters .get (0 ),command ,entryPointClass .getName (),initializeMethod .getName ());
260+ } else {
261+ callInitializeModel ();
262+ }
236263 } finally {
237264 StepManagerRegistry .getInstance ().unregisterManager (PlainK3ExecutionEngine .this );
238265 }
@@ -290,8 +317,8 @@ public void run() {
290317 */
291318 public boolean canHandle (Object caller ) {
292319 if (caller instanceof EObject ) {
293- EObject caller_cast = (EObject ) caller ;
294- org .eclipse .emf .transaction .TransactionalEditingDomain editingDomain = getEditingDomain (caller_cast );
320+ EObject eObj = (EObject ) caller ;
321+ org .eclipse .emf .transaction .TransactionalEditingDomain editingDomain = getEditingDomain (eObj );
295322 return editingDomain == this .editingDomain ;
296323
297324 }
@@ -396,6 +423,11 @@ private static InternalTransactionalEditingDomain getEditingDomain(ResourceSet r
396423 return null ;
397424 }
398425
426+ /**
427+ * Load the model for the given URI
428+ * @param modelURI to load
429+ * @return the loaded resource
430+ */
399431 public static Resource loadModel (URI modelURI ) {
400432 Resource resource = null ;
401433 ResourceSet resourceSet ;
0 commit comments