Просмотр исходного кода

migrated simulatiojn runtime from SCT1 to SCT2

terfloth@itemis.de 14 лет назад
Родитель
Сommit
f1d3c8eae6
65 измененных файлов с 3911 добавлено и 0 удалено
  1. 8 0
      plugins/org.yakindu.sct.simulation.runtime/.classpath
  2. 40 0
      plugins/org.yakindu.sct.simulation.runtime/.project
  3. 3 0
      plugins/org.yakindu.sct.simulation.runtime/.settings/org.eclipse.core.resources.prefs
  4. 12 0
      plugins/org.yakindu.sct.simulation.runtime/.settings/org.eclipse.jdt.core.prefs
  5. 17 0
      plugins/org.yakindu.sct.simulation.runtime/META-INF/MANIFEST.MF
  6. 8 0
      plugins/org.yakindu.sct.simulation.runtime/build.properties
  7. 187 0
      plugins/org.yakindu.sct.simulation.runtime/customBuildCallbacks.xml
  8. 120 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/AbstractStatechart.java
  9. 7 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Action.java
  10. 89 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/CompoundState.java
  11. 14 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/ConstantTimeEvent.java
  12. 45 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/DefaultTimingService.java
  13. 14 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Event.java
  14. 31 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/FinalState.java
  15. 7 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Guard.java
  16. 5 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/HistoryMode.java
  17. 57 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Node.java
  18. 54 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Pseudostate.java
  19. 5 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/PseudostateKind.java
  20. 106 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Region.java
  21. 9 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/SignalEvent.java
  22. 32 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/SimpleState.java
  23. 118 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/State.java
  24. 10 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/TimeEvent.java
  25. 9 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/TimingService.java
  26. 194 0
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Transition.java
  27. 32 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/EvaluationException.java
  28. 27 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/ExecutionScope.java
  29. 18 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/AbstractStatechartAdvice.xpt
  30. 18 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/CompoundStateAdvice.xpt
  31. 13 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/GeneratorAdvice.ext
  32. 24 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/NodeAdvice.xpt
  33. 17 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/RegionAdvice.xpt
  34. 20 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/SimpleStateAdvice.xpt
  35. 36 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/StateAdvice.xpt
  36. 51 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/TransitionAdvice.xpt
  37. 21 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/generate_Runtime.oaw
  38. 61 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/ActionStatement.java
  39. 60 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/GuardExpression.java
  40. 224 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/Statechart.java
  41. 22 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/StatechartListener.java
  42. 30 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/StatechartRuntimeException.java
  43. 47 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/TimeEventExpression.java
  44. 268 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/builder/StatechartBuilder.java
  45. 29 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Assert.java
  46. 56 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Assign.java
  47. 113 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/BinaryOperation.java
  48. 78 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Conditional.java
  49. 38 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Constant.java
  50. 243 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/CoreFunction.java
  51. 19 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Expression.java
  52. 33 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/ExpressionRuntimeException.java
  53. 110 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Function.java
  54. 30 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/FunctionMethod.java
  55. 42 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/ProcedureCall.java
  56. 45 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Raise.java
  57. 67 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Scope.java
  58. 18 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Statement.java
  59. 32 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/StatementSequence.java
  60. 58 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Trigger.java
  61. 59 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/UnaryOperation.java
  62. 74 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Variable.java
  63. 48 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/VariableRef.java
  64. 32 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/BuilderException.java
  65. 497 0
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/ExpressionBuilder.java

+ 8 - 0
plugins/org.yakindu.sct.simulation.runtime/.classpath

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="src-gen"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 40 - 0
plugins/org.yakindu.sct.simulation.runtime/.project

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.simulation.runtime</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.openarchitectureware.base.oawBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.openarchitectureware.base.oawNature</nature>
+		<nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
+	</natures>
+</projectDescription>

+ 3 - 0
plugins/org.yakindu.sct.simulation.runtime/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,3 @@
+#Fri Nov 27 18:28:57 CET 2009
+eclipse.preferences.version=1
+encoding/<project>=UTF-8

+ 12 - 0
plugins/org.yakindu.sct.simulation.runtime/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Tue Nov 24 17:42:55 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

+ 17 - 0
plugins/org.yakindu.sct.simulation.runtime/META-INF/MANIFEST.MF

@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: YAKINDU SCT Runtime
+Bundle-SymbolicName: org.yakindu.sct.simulation.runtime
+Bundle-Version: 1.1.0.qualifier
+Bundle-Vendor: YAKINDU.org
+Require-Bundle: org.yakindu.sct.model.sgraph;bundle-version="1.0.0",
+ com.yakindu.statechart.codegenerator.java;bundle-version="1.1.0",
+ org.eclipse.xtext;bundle-version="2.0.0",
+ org.eclipse.emf.mwe.core;bundle-version="1.1.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: org.yakindu.sct.simulation.runtime,
+ org.yakindu.sct.simulation.runtime.sgraph,
+ org.yakindu.sct.simulation.runtime.sgraph.builder,
+ org.yakindu.sct.simulation.runtime.stext,
+ org.yakindu.sct.simulation.runtime.stext.builder

+ 8 - 0
plugins/org.yakindu.sct.simulation.runtime/build.properties

@@ -0,0 +1,8 @@
+source.. = src/,\
+           src-gen/
+output.. = bin/
+customBuildCallbacks = customBuildCallbacks.xml
+bin.includes = META-INF/,\
+               .
+src.includes = src/,\
+               src-gen/

+ 187 - 0
plugins/org.yakindu.sct.simulation.runtime/customBuildCallbacks.xml

@@ -0,0 +1,187 @@
+<!--
+
+    Copyright (c) 2010 committers of YAKINDU and others.
+    All rights reserved. This program and the accompanying materials
+    are made available under the terms of the Eclipse Public License v1.0
+    which accompanies this distribution, and is available at
+    http://www.eclipse.org/legal/epl-v10.html
+
+    Contributors:
+        committers of YAKINDU - initial API and implementation
+
+-->
+<!-- ===================================================================== -->
+<!-- Custom targets called from a project's generated build.xml            -->
+<!-- Set customBuildCallbacks=<path/to/this/file> in your build.properties.-->
+<!-- ===================================================================== -->
+<project name="Build specific targets and properties" default="noDefault">
+
+	<!-- ===================================================================== -->
+	<!-- Default target                                                        -->
+	<!-- ===================================================================== -->
+	<target name="noDefault">
+		<echo message="This file must be called with explicit targets" />
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the target build.jars                              -->
+	<!-- Available parameters :                                                -->
+	<!--   build.result.folder - folder to contain the build results           -->
+	<!-- ===================================================================== -->
+	<target name="pre.build.jars">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the target build.jars                               -->
+	<!-- Available parameters :                                                -->
+	<!--   build.result.folder - folder to contain the build results           -->
+	<!-- ===================================================================== -->
+	<target name="post.build.jars">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the target build.sources                           -->
+	<!-- Available parameters :                                                -->
+	<!--   build.result.folder - folder to contain the build results           -->
+	<!-- ===================================================================== -->
+	<target name="pre.build.sources">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the target build.sources                            -->
+	<!-- Available parameters :                                                -->
+	<!--   build.result.folder - folder to contain the build results           -->
+	<!-- ===================================================================== -->
+	<target name="post.build.sources">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the compilation target <name>                      -->
+	<!-- Substitute "name" with the name of the compilation target, eg @dot    -->
+	<!-- Available parameters :                                                -->
+	<!--   source.foldern : n = 1 ... N, the source folders                    -->
+	<!--   target.folder  : where the results of the compilation go            -->
+	<!--   <name>.classpath : name = name of the compilation target. A         -->
+	<!--                      reference to the classpath structure.            -->
+	<!-- ===================================================================== -->
+	<target name="pre.name">
+	</target>
+
+	<target name="pre.@dot">
+		<!-- generate code, making use of oaw workflow -->
+		<echo message="GENERATING CODE ..." />
+
+		<path id="oaw.classpath">
+			<pathelement path="${source.folder1}" />
+			<path refid="@dot.classpath" />
+		</path>
+		
+		<!--<pathconvert pathsep="${line.separator}|   |- " property="echo.oaw.classpath" refid="oaw.classpath" />
+				<echo message="|- oaw.classpath" />
+				<echo message="|   |" />
+				<echo message="|   |- ${echo.oaw.classpath}" />-->			
+
+		<taskdef name="oaw4" classname="org.eclipse.emf.mwe.core.ant.WorkflowAntTask" classpathref="oaw.classpath" />
+		<oaw4 file="${source.folder1}com/yakindu/statechart/runtime/generator/generate_Runtime.oaw" fork="true" failOnError="true" classpathref="oaw.classpath"/>
+
+		<echo message="DONE!" />
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do during the compilation target <name>, after the compile   -->
+	<!-- but before jaring.  Substitute "name" with the name of the compilation-->
+	<!-- target, eg @dot                                                       -->
+	<!-- Available parameters :                                                -->
+	<!--   source.foldern : n = 1 ... N, the source folders                    -->
+	<!--   target.folder  : where the results of the compilation go            -->
+	<!--   <name>.classpath : name = name of the compilation target. A         -->
+	<!--                      reference to the classpath structure.            -->
+	<!-- ===================================================================== -->
+	<target name="post.compile.name">
+	</target>
+
+	<target name="post.compile.@dot">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the compilation target <name>                       -->
+	<!-- Substitute "name" with the name of the compilation target, eg @dot    -->
+	<!-- Available parameters :                                                -->
+	<!--   jar.location - the location of the compilation results              -->
+	<!--   <name>.classpath : name = name of the compilation target. A         -->
+	<!--                      reference to the classpath structure.            -->
+	<!-- ===================================================================== -->
+	<target name="post.name">
+	</target>
+
+	<target name="post.@dot">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the target gather.bin.parts                         -->
+	<!-- Available parameters :                                                -->
+	<!--   build.result.folder - folder containing the build results           -->
+	<!--   target.folder - destination folder                                  -->
+	<!-- ===================================================================== -->
+	<target name="pre.gather.bin.parts">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the target gather.bin.parts                         -->
+	<!-- Available parameters :                                                -->
+	<!--   build.result.folder - folder containing the build results           -->
+	<!--   target.folder - destination folder                                  -->
+	<!-- ===================================================================== -->
+	<target name="post.gather.bin.parts">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the target gather.sources                          -->
+	<!-- Available parameters :                                                -->
+	<!--   destination.temp.folder - destination folder                        -->
+	<!-- ===================================================================== -->
+	<target name="pre.gather.sources">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the target gather.sources                           -->
+	<!-- Available parameters :                                                -->
+	<!--   destination.temp.folder - destination folder                        -->
+	<!-- ===================================================================== -->
+	<target name="post.gather.sources">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the target gather.logs                             -->
+	<!-- Available parameters :                                                -->
+	<!--   destination.temp.folder - destination folder                        -->
+	<!-- ===================================================================== -->
+	<target name="pre.gather.logs">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the target gather.logs                              -->
+	<!-- Available parameters :                                                -->
+	<!--   destination.temp.folder - destination folder                        -->
+	<!-- ===================================================================== -->
+	<target name="post.gather.logs">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do before the target clean                                   -->
+	<!-- Available parameters :                                                -->
+	<!--   destination.temp.folder - destination folder                        -->
+	<!-- ===================================================================== -->
+	<target name="pre.clean">
+	</target>
+
+	<!-- ===================================================================== -->
+	<!-- Steps to do after the target clean                                    -->
+	<!-- Available parameters :                                                -->
+	<!--   plugin.destination - final destination of the build                 -->
+	<!--   build.result.folder - results of the compilation                    -->
+	<!--   temp.folder - temporary folder                                      -->
+	<!-- ===================================================================== -->
+	<target name="post.clean">
+	</target>
+</project>

+ 120 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/AbstractStatechart.java

@@ -0,0 +1,120 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+public abstract class AbstractStatechart {
+
+	protected Set<Event> raisedEvents = new HashSet<Event>();
+
+	// ------------------------------------------------------------------------
+	// (EXTERNAL) EVENT-INTERFACE IMPLEMENTATION
+	// ------------------------------------------------------------------------
+
+	public void setEvent(Event event) {
+
+		synchronized (raisedEvents) {
+			raisedEvents.add(event);
+		}
+
+	}
+
+	// ------------------------------------------------------------------------
+	// (INTERNAL) TIMING-SERVICE-INTERFACE IMPLEMENTATION
+	// ------------------------------------------------------------------------
+
+	protected void requestTimeEvent(TimeEvent event) {
+		timingService.requestTimeEvent(event);
+	}
+
+	protected void cancelTimeEvent(TimeEvent event) {
+		timingService.cancelTimeEvent(event);
+	}
+
+	// ------------------------------------------------------------------------
+	// (EXTERNAL) EXECUTION-INTERFACE IMPLEMENTATION
+	// ------------------------------------------------------------------------
+
+	public void enter() {
+
+		// enter all nested regions (in the order of their priority)
+		for (Region region : regions) {
+			region.enter();
+		}
+
+	}
+
+	public void runCycle() {
+
+		Set<Event> currentEvents = new HashSet<Event>();
+		synchronized (raisedEvents) {
+			currentEvents.addAll(raisedEvents);
+			raisedEvents.clear();
+		}
+		reactOn(currentEvents);
+
+	}
+
+	public void leave() {
+
+		// leave all nested regions (in the reverse order of their priority)
+		for (ListIterator<Region> iterator = regions.listIterator(regions
+				.size()); iterator.hasPrevious();) {
+			iterator.previous().leave();
+		}
+
+	}
+
+	// ------------------------------------------------------------------------
+	// INITIALIZATION CODE
+	// ------------------------------------------------------------------------
+
+	// the unique id of this statechart instance
+	private String id;
+
+	// the nested regions of this state, sorted by priority
+
+	private List<Region> regions = new ArrayList<Region>();
+
+	private List<Transition> transitions = new ArrayList<Transition>();
+
+	// used to request time events from environment
+	protected TimingService timingService = null;
+
+	protected AbstractStatechart(String id) {
+		this.id = id;
+		this.timingService = new DefaultTimingService(this);
+	}
+
+	protected AbstractStatechart(String id, TimingService timingService) {
+		this.id = id;
+		this.timingService = timingService;
+	}
+
+	public List<Region> getRegions() {
+		return regions;
+	}
+
+	protected List<Transition> getTransitions() {
+
+		return transitions;
+
+	}
+
+	// ------------------------------------------------------------------------
+	// INTERNAL STATECHART BEHAVIOUR
+	// ------------------------------------------------------------------------
+
+	private void reactOn(Set<Event> events) {
+
+		// pass events to our nested regions (in the order of their priority)
+		for (Region region : regions) {
+			region.reactOn(events);
+		}
+
+	}
+
+}

+ 7 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Action.java

@@ -0,0 +1,7 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public abstract class Action {
+
+	public abstract void execute();
+
+}

+ 89 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/CompoundState.java

@@ -0,0 +1,89 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * Representation of a state that contains nested regions with sub-states.
+ * Composite states may have an arbitrary number of nested regions, which are
+ * virtually executed in parallel (in fact, there execution is sequentialized
+ * based on their priorities). As a composite state always is "in" its
+ * sub-states, it may itself not contain a do action.
+ */
+public class CompoundState extends State {
+
+	// the nested regions of this state, sorted by priority
+	private List<Region> regions = new ArrayList<Region>();
+
+	public CompoundState(String id, String name, Region container,
+			Action entryAction, Action exitAction) {
+		super(id, name, container, entryAction, exitAction);
+	}
+
+	public List<Region> getRegions() {
+		return regions;
+	}
+
+	protected void enter() {
+
+		shallowEnter();
+		// now enter all nested regions (in the order of their priority)
+		for (Region region : regions) {
+			region.enter();
+		}
+
+	}
+
+	protected void shallowEnter() {
+
+		// let the super implementation request time events and execute the entry action of this state
+		super.enter();
+
+	}
+
+	protected void reenter(HistoryMode history) {
+
+		shallowEnter();
+		// let the nested regions re-enter their former states
+		for (Region region : regions) {
+			// if we have are in DEEP history mode, notify our nested regions 
+			// to reenter into their former states as well
+			if (history == HistoryMode.DEEP) {
+				region.reenter(history);
+			} else {
+				region.enter();
+			}
+		}
+
+	}
+
+	protected void reactLocallyOn(Set<Event> events) {
+		// as a compound state does not locally react on events (it may not
+		// specify a do action), forward to the nested regions (in the order of
+		// their priority)
+		for (Region region : regions) {
+			region.reactOn(events);
+		}
+	}
+
+	protected void leave() {
+
+		// leave all nested regions (in the reverse order of their priority)
+		for (ListIterator<Region> iterator = regions.listIterator(regions
+				.size()); iterator.hasPrevious();) {
+			iterator.previous().leave();
+		}
+		shallowLeave();
+
+	}
+
+	protected void shallowLeave() {
+
+		// let the super implementation execute the exit action of this state
+		super.leave();
+
+	}
+
+}

+ 14 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/ConstantTimeEvent.java

@@ -0,0 +1,14 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public class ConstantTimeEvent extends TimeEvent {
+	private long duration = -1;
+
+	public ConstantTimeEvent(String id, long duration) {
+		super(id);
+		this.duration = duration;
+	}
+
+	public long getDuration() {
+		return duration;
+	}
+}

+ 45 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/DefaultTimingService.java

@@ -0,0 +1,45 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class DefaultTimingService implements TimingService {
+
+	private final AbstractStatechart statechart;
+
+	public DefaultTimingService(AbstractStatechart statechart) {
+		this.statechart = statechart;
+	}
+
+	private Set<TimeEvent> canceledRequestedEvents = new HashSet<TimeEvent>();
+
+	public void requestTimeEvent(final TimeEvent timeEvent) {
+
+		canceledRequestedEvents.remove(timeEvent);
+
+		// run a timer (there is an own thread for this);
+		Timer timer = new Timer();
+		timer.schedule(new TimerTask() {
+
+			@Override
+			public void run() {
+				if (canceledRequestedEvents.contains(timeEvent)) {
+					canceledRequestedEvents.remove(timeEvent);
+				} else {
+					statechart.setEvent(timeEvent);
+				}
+			}
+
+		}, timeEvent.getDuration());
+
+	}
+
+	public void cancelTimeEvent(final TimeEvent timeEvent) {
+
+		canceledRequestedEvents.add(timeEvent);
+
+	}
+
+}

+ 14 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Event.java

@@ -0,0 +1,14 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public abstract class Event {
+
+	private String id;
+
+	public Event(String id) {
+		this.id = id;
+	}
+
+	public String getId() {
+		return id;
+	}
+}

+ 31 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/FinalState.java

@@ -0,0 +1,31 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.Set;
+
+/**
+ * Representation of a final state. A final state is some sort of event sink, i.e.
+ * it does not react on any events, and it further has to entry, do, or exit action.
+ */
+public class FinalState extends State {
+
+	public FinalState(String id, Region owningRegion) {
+		super(id, "FINAL", owningRegion, null, null);
+	}
+
+	protected void enter() {
+		// only notify the containing region that we are the current state
+		owningRegion.setCurrentState(this);
+	}
+
+	protected void reactOn(Set<Event> events) {
+		// do nothing, just ignore all events 
+	}
+
+	protected void reactLocallyOn(Set<Event> events) {
+		// never called, as reactOn is overwritten as well
+	}
+
+	protected void leave() {
+		// do nothing, just ignore
+	}
+}

+ 7 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Guard.java

@@ -0,0 +1,7 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public abstract class Guard {
+
+	public abstract boolean evaluate();
+
+}

+ 5 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/HistoryMode.java

@@ -0,0 +1,5 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public enum HistoryMode {
+	SHALLOW, DEEP
+}

+ 57 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Node.java

@@ -0,0 +1,57 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of a node (which is the abstract super concept of State and
+ * Pseudostate). A node may have incoming and outgoing transitions. As the
+ * statechart may only reside "in" states, pseudostates will normally directly
+ * trigger an outgoing transition when being entered.
+ */
+public abstract class Node {
+
+	private String id;
+	protected Region owningRegion;
+
+	protected List<Transition> incomingTransitions = new ArrayList<Transition>();
+	protected List<Transition> outgoingTransitions = new ArrayList<Transition>();
+
+	public Node(String id, Region owner) {
+		this.id = id;
+		this.owningRegion = owner;
+		this.owningRegion.getNodes().add(this);
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	protected Region getOwningRegion() {
+		return owningRegion;
+	}
+
+	public List<Transition> getIncomingTransitions() {
+		return incomingTransitions;
+	}
+
+	public List<Transition> getOutgoingTransitions() {
+		return outgoingTransitions;
+	}
+
+	protected Transition getEnabledOutgoingTransitionOfHighestPriority() {
+
+		for (Transition transition : outgoingTransitions) {
+			if (transition.isEnabled()) {
+				return transition;
+			}
+		}
+		return null;
+
+	}
+
+	protected abstract void enter();
+
+	protected abstract void leave();
+
+}

+ 54 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Pseudostate.java

@@ -0,0 +1,54 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+/**
+ * Representation of a Pseudostate.
+ */
+public class Pseudostate extends Node {
+
+	PseudostateKind kind;
+
+	public Pseudostate(String id, Region owningRegion, PseudostateKind kind) {
+		super(id, owningRegion);
+		this.kind = kind;
+	}
+
+	public PseudostateKind getKind() {
+		return kind;
+	}
+
+	protected void enter() {
+
+		if (kind == PseudostateKind.INITIAL) {
+			// go directly into the next state (special transition needs no
+			// event
+			outgoingTransitions.get(0).take();
+		} else if (kind == PseudostateKind.SHALLOWHISTORY
+				|| kind == PseudostateKind.DEEPHISTORY) {
+			// if this is the first time we enter this state, prolong the
+			// default transition, else reenter the region
+			if (owningRegion.getCurrentState() == null) {
+				outgoingTransitions.get(0).take();
+			} else {
+				owningRegion.reenter(kind == PseudostateKind.SHALLOWHISTORY
+						? HistoryMode.SHALLOW
+						: HistoryMode.DEEP);
+			}
+		} else if (kind == PseudostateKind.CHOICE) {
+			// choose the first outgoing transition that can be taken and take it
+			getEnabledOutgoingTransitionOfHighestPriority().take();
+		} else if (kind == PseudostateKind.JUNCTION) {
+			// just take the single outgoing transition to the next state
+			outgoingTransitions.get(0).take();
+		} else {
+			throw new IllegalArgumentException("UNSUPPORTED Pseudostate Kind");
+		}
+
+	}
+
+	protected void leave() {
+
+		// do nothing by default
+
+	}
+
+}

+ 5 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/PseudostateKind.java

@@ -0,0 +1,5 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public enum PseudostateKind {
+	INITIAL, SHALLOWHISTORY, DEEPHISTORY, FINAL, CHOICE, JUNCTION
+}

+ 106 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Region.java

@@ -0,0 +1,106 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Region {
+
+	private String id;
+	private int priority;
+	private AbstractStatechart owningStatechart;
+	private CompoundState owningState;
+
+	private Set<Node> nodes = new HashSet<Node>();
+
+	protected State currentState;
+
+	public Region(String id, int priority, AbstractStatechart owner) {
+		this.id = id;
+		this.priority = priority;
+		this.owningStatechart = owner;
+		this.owningStatechart.getRegions().add(this);
+	}
+
+	public Region(String id, int priority, CompoundState owner) {
+		this.id = id;
+		this.priority = priority;
+		this.owningState = owner;
+		this.owningState.getRegions().add(this);
+	}
+
+	/** Returns the id of the region.
+	 */
+	public String getId() {
+		return id;
+	}
+
+	/** Returns the priority of the region. Regions with lower priority value will be evaluated 
+	 * before regions with higher priority value.
+	 */
+	public int getPriority() {
+		return priority;
+	}
+
+	public AbstractStatechart getStatechart() {
+		if (owningStatechart != null) {
+			return owningStatechart;
+		} else {
+			return owningState.getStatechart();
+		}
+	}
+
+	protected CompoundState getOwningState() {
+		return owningState;
+	}
+
+	protected AbstractStatechart getOwningStatechart() {
+		return owningStatechart;
+	}
+
+	public Set<Node> getNodes() {
+		return nodes;
+	}
+
+	private Node getInitialNode() {
+		for (Node node : nodes) {
+			if (node instanceof Pseudostate
+					&& ((Pseudostate) node).getKind() == PseudostateKind.INITIAL) {
+				return node;
+			}
+		}
+		throw new IllegalStateException("No initial state present");
+	}
+
+	protected void setCurrentState(State state) {
+		this.currentState = state;
+	}
+
+	public State getCurrentState() {
+		return currentState;
+	}
+
+	protected void enter() {
+
+		getInitialNode().enter();
+
+	}
+
+	protected void reenter(HistoryMode history) {
+
+		currentState.reenter(history);
+
+	}
+
+	protected void reactOn(Set<Event> events) {
+
+		currentState.reactOn(events);
+
+	}
+
+	protected void leave() {
+
+		currentState.leave();
+
+	}
+
+}

+ 9 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/SignalEvent.java

@@ -0,0 +1,9 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public class SignalEvent extends Event {
+
+	public SignalEvent(String id) {
+		super(id);
+	}
+
+}

+ 32 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/SimpleState.java

@@ -0,0 +1,32 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.Set;
+
+/**
+ * Representation of a simple state without nested regions. A simple state may
+ * specify a do action, which is executed when the statechart resides "in" this
+ * state.
+ */
+public class SimpleState extends State {
+
+	private Action doAction;
+
+	public SimpleState(String id, String name, Region owningRegion,
+			Action entryAction, Action doAction, Action exitAction) {
+		super(id, name, owningRegion, entryAction, exitAction);
+		this.doAction = doAction;
+	}
+
+	protected void reactLocallyOn(Set<Event> events) {
+
+		if (doAction != null) {
+			doAction.execute();
+		}
+
+	}
+
+	public Action getDoAction() {
+		return doAction;
+	}
+
+}

+ 118 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/State.java

@@ -0,0 +1,118 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.Set;
+
+import org.yakindu.sct.simulation.runtime.sgraph.Statechart;
+
+/**
+ * Representation of a state (i.e. abstract base class for CompoundState, SimpleState,
+ * and FinalState). A state has the unique property, that the system may be "in"
+ * it, i.e. the state will - if being entered - react to incoming events of its
+ * Statechart until it has been left again (although FinalStates will not show any reaction). 
+ * When being entered or left, a state may execute an Action, i.e. its entry or exit action 
+ * respectively.
+ */
+public abstract class State extends Node {
+
+	private Action entryAction;
+	private Action exitAction;
+	private String name;
+
+	public State(String id, String name, Region owningRegion,
+			Action entryAction, Action exitAction) {
+		super(id, owningRegion);
+		this.name = name;
+		this.entryAction = entryAction;
+		this.exitAction = exitAction;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	protected AbstractStatechart getStatechart() {
+		return owningRegion.getStatechart();
+	}
+
+	protected void enter() {
+
+		owningRegion.setCurrentState(this);
+
+		// see if we have transitions that are time-triggered
+		for (Transition transition : outgoingTransitions) {
+			if (transition.isTimeTriggered()) {
+				// register timer with timing service
+				getStatechart().requestTimeEvent(transition.getTimeTrigger());
+			}
+		}
+
+		// execute entry action
+		if (entryAction != null) {
+			entryAction.execute();
+		}
+
+		((Statechart) getStatechart()).stateEntered(this);
+
+	}
+
+	protected void reenter(HistoryMode history) {
+
+		enter();
+
+	}
+
+	protected void reactOn(Set<Event> events) {
+
+		Transition transition = getEnabledOutgoingTransitionOfHighestPriority(events);
+		if (transition != null) {
+			// if there is an enabled transition, take it
+			transition.take();
+		} else {
+			// otherwise this state might react to it (by executing a do action
+			// or by delegating to nested regions)
+			reactLocallyOn(events);
+		}
+
+	}
+
+	private Transition getEnabledOutgoingTransitionOfHighestPriority(
+			Set<Event> events) {
+
+		for (Transition transition : outgoingTransitions /* sorted by priority */) {
+			if (transition.isTriggeredBy(events) && transition.isEnabled()) {
+				return transition;
+			}
+		}
+		return null;
+
+	}
+
+	protected abstract void reactLocallyOn(Set<Event> events);
+
+	protected void leave() {
+
+		// see if we have transitions that are time-triggered
+		for (Transition transition : outgoingTransitions) {
+			if (transition.isTimeTriggered()) {
+				// cancel all time events that could have been requested
+				getStatechart().cancelTimeEvent(transition.getTimeTrigger());
+			}
+		}
+
+		if (exitAction != null) {
+			exitAction.execute();
+		}
+
+		((Statechart) getStatechart()).stateLeft(this);
+
+	}
+
+	public Action getEntryAction() {
+		return entryAction;
+	}
+
+	public Action getExitAction() {
+		return exitAction;
+	}
+
+}

+ 10 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/TimeEvent.java

@@ -0,0 +1,10 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public abstract class TimeEvent extends Event {
+
+	public TimeEvent(String id) {
+		super(id);
+	}
+
+	public abstract long getDuration();
+}

+ 9 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/TimingService.java

@@ -0,0 +1,9 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public interface TimingService {
+
+	public void requestTimeEvent(TimeEvent timeEvent);
+
+	public void cancelTimeEvent(TimeEvent timeEvent);
+
+}

+ 194 - 0
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/Transition.java

@@ -0,0 +1,194 @@
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.yakindu.sct.simulation.runtime.sgraph.Statechart;
+
+/**
+ * Representation of a transition. A transition always connects a source node to
+ * a target node. It may react on a time trigger and/or multiple signal triggers
+ * and may be additionally guarded. In case a transition is taken, its action
+ * will be executed.
+ */
+public class Transition {
+
+	private String id;
+	private int priority;
+
+	private Guard guard;
+	private Set<SignalEvent> signalTriggers = new HashSet<SignalEvent>();
+	private TimeEvent timeTrigger;
+	private Action action;
+
+	private Node sourceNode;
+	private Node targetNode;
+
+	private Region commonAncestorRegion;
+	private List<CompoundState> enclosingStatesToEnter;
+	private List<CompoundState> enclosingStatesToLeave;
+
+	public Transition(String id, int priority, TimeEvent timeTrigger,
+			Set<SignalEvent> signalTriggers, Guard guard, Action action,
+			Node sourceNode, Node targetNode) {
+		this.id = id;
+		this.priority = priority;
+
+		this.timeTrigger = timeTrigger;
+		if (signalTriggers != null) {
+			this.signalTriggers.addAll(signalTriggers);
+		}
+		this.guard = guard;
+		this.action = action;
+
+		this.sourceNode = sourceNode;
+		sourceNode.outgoingTransitions.add(this);
+		this.targetNode = targetNode;
+		targetNode.incomingTransitions.add(this);
+
+		// compute common ancestor region
+		commonAncestorRegion = getCommonAncestorRegion(sourceNode, targetNode);
+		commonAncestorRegion.getStatechart().getTransitions().add(this);
+		// compute which enclosing compound states have to be entered or left, when taking the transition
+		enclosingStatesToEnter = getEnclosingStatesToEnter(targetNode,
+				commonAncestorRegion);
+		enclosingStatesToLeave = getEnclosingStatesToLeave(sourceNode,
+				commonAncestorRegion);
+	}
+
+	protected boolean isTriggeredBy(Set<Event> events) {
+
+		return !Collections.disjoint(this.signalTriggers, events)
+				|| (timeTrigger != null && events.contains(timeTrigger));
+
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public int getPriority() {
+		return priority;
+	}
+
+	protected boolean isEnabled() {
+		if (guard == null) {
+			return true;
+		} else {
+			return guard.evaluate();
+		}
+	}
+
+	public TimeEvent getTimeTrigger() {
+		return timeTrigger;
+	}
+
+	protected boolean isTimeTriggered() {
+		return timeTrigger != null;
+	}
+
+	protected void take() {
+
+		// leave all enclosing states from the souceNode's container up to
+		// the common ancestor region
+		for (CompoundState state : enclosingStatesToLeave) {
+			state.shallowLeave();
+		}
+		sourceNode.leave();
+
+		((Statechart) commonAncestorRegion.getStatechart())
+				.transitionFired(this);
+
+		if (action != null) {
+			action.execute();
+		}
+
+		// enter all enclosing states from the common ancestor region to the
+		// targetNode's container
+		for (CompoundState state : enclosingStatesToEnter) {
+			state.shallowEnter();
+		}
+		targetNode.enter();
+
+	}
+
+	private List<CompoundState> getEnclosingStatesToEnter(Node targetNode,
+			Region commonAncestorRegion) {
+
+		// compute all enclosing state that have to be entered
+		List<CompoundState> enclosingStatesToEnter = new ArrayList<CompoundState>();
+		Region targetRegion = targetNode.getOwningRegion();
+		while (targetRegion != commonAncestorRegion) {
+			CompoundState state = targetRegion.getOwningState();
+			enclosingStatesToEnter.add(state);
+			targetRegion = state.getOwningRegion();
+
+		}
+		Collections.reverse(enclosingStatesToEnter); // ensure entering is done
+														// in reverse order
+		return enclosingStatesToEnter;
+
+	}
+
+	private List<CompoundState> getEnclosingStatesToLeave(Node sourceNode,
+			Region commonAncestorRegion) {
+
+		// compute all enclosing compound states up to the ancestor region
+		List<CompoundState> enclosingStatesToLeave = new ArrayList<CompoundState>();
+		Region sourceRegion = sourceNode.getOwningRegion();
+		while (sourceRegion != commonAncestorRegion) {
+			CompoundState state = sourceRegion.getOwningState();
+			enclosingStatesToLeave.add(state);
+			sourceRegion = state.getOwningRegion();
+		}
+		return enclosingStatesToLeave;
+
+	}
+
+	private Region getCommonAncestorRegion(Node sourceNode, Node targetNode) {
+		Region candidate = sourceNode.getOwningRegion();
+		while (candidate != null
+				&& !isRegionAncestorOfNode(candidate, targetNode)) {
+			candidate = candidate.getOwningState() != null ? candidate
+					.getOwningState().getOwningRegion() : null;
+		}
+		return candidate;
+	}
+
+	private boolean isRegionAncestorOfNode(Region region, Node node) {
+		if (node.getOwningRegion() == region) {
+			return true;
+		} else {
+			if (node.getOwningRegion().getOwningState() == null) {
+				return false;
+			} else {
+				return isRegionAncestorOfNode(region, node.getOwningRegion()
+						.getOwningState());
+			}
+		}
+	}
+
+	public Node getSourceNode() {
+		return sourceNode;
+	}
+
+	public Node getTargetNode() {
+		return targetNode;
+	}
+
+	public Guard getGuard() {
+		return guard;
+	}
+
+	public Action getAction() {
+		return action;
+	}
+
+	public Set<SignalEvent> getSignalTriggers() {
+		return signalTriggers;
+	}
+
+}

+ 32 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/EvaluationException.java

@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime;
+
+public class EvaluationException extends RuntimeException {
+
+	private static final long serialVersionUID = 3452634362782831486L;
+
+	public EvaluationException() {
+	}
+
+	public EvaluationException(String message) {
+		super(message);
+	}
+
+	public EvaluationException(Throwable cause) {
+		super(cause);
+	}
+
+	public EvaluationException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+}

+ 27 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/ExecutionScope.java

@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime;
+
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+
+public interface ExecutionScope {
+
+	public abstract Object getValue(String varName);
+
+	public abstract Variable getVariable(String varName);
+
+	public abstract void addVariable(Variable var);
+
+	public abstract void call(String procedureId);
+
+	public abstract void raise(String signal);
+
+}

+ 18 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/AbstractStatechartAdvice.xpt

@@ -0,0 +1,18 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::AbstractStatechart::getRegionsMethod FOR Object»
+	public List<Region> getRegions() {«
+		EXPAND AbstractStatechart::getRegionsMethodBody -»
+	}
+«ENDAROUND»

+ 18 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/CompoundStateAdvice.xpt

@@ -0,0 +1,18 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::CompoundState::getRegionsMethod FOR Object»
+	public List<Region> getRegions() {«
+		EXPAND CompoundState::getRegionsMethodBody -»
+	}
+«ENDAROUND»

+ 13 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/GeneratorAdvice.ext

@@ -0,0 +1,13 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+
+around  com::yakindu::statechart::codegenerator::java::extensions::Statechart2JavaNamespace::getLibraryPackage() :
+	"com.yakindu.statechart.runtime";

+ 24 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/NodeAdvice.xpt

@@ -0,0 +1,24 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::Node::getIncomingTransitionsMethod FOR Object»
+	public List<Transition> getIncomingTransitions() {«
+		EXPAND Node::getIncomingTransitionsMethodBody -»
+	}
+«ENDAROUND»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::Node::getOutgoingTransitionsMethod FOR Object»
+	public List<Transition> getOutgoingTransitions() {«
+		EXPAND Node::getOutgoingTransitionsMethodBody -»
+	}
+«ENDAROUND»

+ 17 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/RegionAdvice.xpt

@@ -0,0 +1,17 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::Region::getNodesMethod FOR Object»
+	public Set<Node> getNodes() {«
+		EXPAND Region::getNodesMethodBody -»
+	}
+«ENDAROUND»

+ 20 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/SimpleStateAdvice.xpt

@@ -0,0 +1,20 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::SimpleState::SimpleStateClassBody FOR Object»
+	«targetDef.proceed()»	
+
+	public Action getDoAction() {
+		return doAction;
+	}
+
+«ENDAROUND»

+ 36 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/StateAdvice.xpt

@@ -0,0 +1,36 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::State::StateClassBody FOR Object»
+	«targetDef.proceed()»
+
+	public Action getEntryAction() {
+		return entryAction;
+	}
+
+	public Action getExitAction() {
+		return exitAction;
+	}
+
+«ENDAROUND»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::State::leaveMethodBody FOR Object»
+		«targetDef.proceed()»
+		((Statechart) getStatechart()).stateLeft(this);
+«ENDAROUND»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::State::enterMethodBody FOR Object»
+		«targetDef.proceed()»
+		((Statechart) getStatechart()).stateEntered(this);
+«ENDAROUND»

+ 51 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/TransitionAdvice.xpt

@@ -0,0 +1,51 @@
+«REM» Copyright
+> Copyright (c) 2010 committers of YAKINDU and others.
+> All rights reserved. This program and the accompanying materials
+> are made available under the terms of the Eclipse Public License v1.0
+> which accompanies this distribution, and is available at
+> http://www.eclipse.org/legal/epl-v10.html
+>
+> Contributors:
+>     committers of YAKINDU - initial API and implementation
+«ENDREM»
+«IMPORT com::yakindu::statechart::codegenerator::java::templates::generic»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::Transition::getTimeTriggerMethod FOR Object»
+	public TimeEvent getTimeTrigger() {«
+		EXPAND Transition::getTimeTriggerMethodBody -»
+	}
+«ENDAROUND»
+
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::Transition::TransitionClassBody FOR Object»
+	«targetDef.proceed()»
+
+	public Node getSourceNode() {
+		return sourceNode;
+	}
+
+	public Node getTargetNode() {
+		return targetNode;
+	}
+
+	public Guard getGuard() {
+		return guard;
+	}
+
+	public Action getAction() {
+		return action;
+	}
+	
+	public Set<SignalEvent> getSignalTriggers() {
+		return signalTriggers;
+	}
+	
+	
+	
+«ENDAROUND»
+
+«AROUND com::yakindu::statechart::codegenerator::java::templates::generic::Transition::postLeaveSourceNode FOR Object»
+		«targetDef.proceed()»
+		((Statechart) commonAncestorRegion.getStatechart()).transitionFired(this);
+«ENDAROUND»

+ 21 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/generator/generate_Runtime.oaw

@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<workflow>
+	<!-- src-gen point to output folder for generated code --> 
+	<property name="src-gen" value="src-gen" />
+	
+	<!-- Generator call with model-file and output-folder -->
+    <cartridge file='com/yakindu/statechart/codegenerator/java/workflow/generate_java_runtime.oaw' src-gen="${src-gen}"/>
+    
+    <component adviceTarget="runtime_generator" id="NamingAdvice" 
+    	class="org.eclipse.xpand2.GeneratorAdvice"> 
+    	<advice value="com::yakindu::statechart::runtime::generator::AbstractStatechartAdvice"/> 
+    	<advice value="com::yakindu::statechart::runtime::generator::RegionAdvice"/> 
+    	<advice value="com::yakindu::statechart::runtime::generator::NodeAdvice"/> 
+    	<advice value="com::yakindu::statechart::runtime::generator::StateAdvice"/> 
+    	<advice value="com::yakindu::statechart::runtime::generator::SimpleStateAdvice"/> 
+    	<advice value="com::yakindu::statechart::runtime::generator::CompoundStateAdvice"/> 
+    	<advice value="com::yakindu::statechart::runtime::generator::TransitionAdvice"/> 
+    	<extensionAdvice value="com::yakindu::statechart::runtime::generator::GeneratorAdvice"/> 
+   </component> 
+    
+</workflow>

+ 61 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/ActionStatement.java

@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+import org.yakindu.sct.simulation.runtime.sgraph.Action;
+import org.yakindu.sct.simulation.runtime.stext.Statement;
+
+
+public class ActionStatement extends Action {
+
+	protected Statement statement;
+	protected ExecutionScope scope;
+	
+	
+	public ActionStatement(Statement statement, ExecutionScope scope) {
+		super();
+		this.statement = statement;
+		this.scope = scope;
+	}
+	
+	
+
+	public Statement getStatement() {
+		return statement;
+	}
+
+
+
+	public void setStatement(Statement statement) {
+		this.statement = statement;
+	}
+
+
+
+	public ExecutionScope getScope() {
+		return scope;
+	}
+
+
+
+	public void setScope(ExecutionScope scope) {
+		this.scope = scope;
+	}
+
+
+
+	@Override
+	public void execute() {
+		statement.execute(scope);
+	}
+
+}

+ 60 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/GuardExpression.java

@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+import org.yakindu.sct.simulation.runtime.sgraph.Guard;
+import org.yakindu.sct.simulation.runtime.stext.Expression;
+
+
+public class GuardExpression extends Guard {
+
+	private Expression expression;
+	private ExecutionScope scope;
+	
+	public GuardExpression() {
+		super();
+	}
+
+	public GuardExpression(Expression expression, ExecutionScope scope) {
+		super();
+		this.expression = expression;
+		this.scope = scope;
+	}	
+
+
+	
+	public Expression getExpression() {
+		return expression;
+	}
+
+	public void setExpression(Expression expression) {
+		this.expression = expression;
+	}
+
+	public ExecutionScope getScope() {
+		return scope;
+	}
+
+	public void setScope(ExecutionScope scope) {
+		this.scope = scope;
+	}
+
+	public boolean evaluate() {
+		Object result = expression.execute(scope);
+		
+		if (result instanceof Boolean)
+			return ((Boolean) result).booleanValue();
+		
+		throw new StatechartRuntimeException();
+	}
+
+}

+ 224 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/Statechart.java

@@ -0,0 +1,224 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+import org.yakindu.sct.simulation.runtime.sgraph.AbstractStatechart;
+import org.yakindu.sct.simulation.runtime.sgraph.CompoundState;
+import org.yakindu.sct.simulation.runtime.sgraph.Event;
+import org.yakindu.sct.simulation.runtime.sgraph.Node;
+import org.yakindu.sct.simulation.runtime.sgraph.Region;
+import org.yakindu.sct.simulation.runtime.sgraph.SignalEvent;
+import org.yakindu.sct.simulation.runtime.sgraph.State;
+import org.yakindu.sct.simulation.runtime.sgraph.TimingService;
+import org.yakindu.sct.simulation.runtime.sgraph.Transition;
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+
+
+public class Statechart extends AbstractStatechart implements ExecutionScope {
+
+
+	protected Map<Object, Object> aliasToElementMap = new HashMap<Object, Object>();
+	protected Map<Object, Object> elementToAliasMap = new HashMap<Object, Object>();
+
+	protected List<SignalEvent> events = new ArrayList<SignalEvent>(); 
+	protected Map<String, SignalEvent> eventMap = new HashMap<String, SignalEvent>();
+
+	protected List<Variable> variables = new ArrayList<Variable>(); 
+	protected Map<String, Variable> variableMap = new HashMap<String, Variable>();
+		
+	protected Set<State> currentStateConfigurartion = new HashSet<State>();
+	
+	protected StatechartListener listener;
+	
+	
+	public Statechart(String id) {
+		super(id);
+	}
+
+	public Statechart(String id, TimingService timingService) {
+		super(id, timingService);
+	}
+
+	
+	public TimingService getTimingService() {
+		return timingService;
+	}
+	
+	public void setTimingService(TimingService ts) {
+		timingService = ts;
+	}
+	
+	
+	public StatechartListener getListener() {
+		return listener;
+	}
+
+	public void setListener(StatechartListener listener) {
+		this.listener = listener;
+	}
+
+	/**
+	 * Adds a signal event definition to the interface of the statechart. 
+	 * only those events, that are registered should be used during operation.
+	 *  
+	 * @param event
+	 */
+	public void addSignalEvent(SignalEvent event) {
+		events.add(event);
+		eventMap.put(event.getId(), event);
+	}
+	
+	/**
+	 * Gets a signal event by its id.
+	 * 
+	 * @param id
+	 * @return the signal event
+	 */
+	public SignalEvent getSignalEvent(String id) {
+		return eventMap.get(id);
+	}
+	
+	public Set<Event> getRaisedEvents() {
+		return Collections.unmodifiableSet(raisedEvents);
+	}
+
+	/**
+	 * @return The list of all defined signal events of this statechart.
+	 */
+	public List<SignalEvent> getSignalEvents() {
+		return Collections.unmodifiableList(events);
+	}
+	
+	
+	public void addVariable(Variable var) {
+		variables.add(var);
+		variableMap.put(var.getName(), var);
+	}
+
+	
+	public Object getValue(String varName) {
+		Variable var = getVariable(varName);
+		return (var != null) ? var.getValue() : null ;		
+	}
+
+	
+	public Variable getVariable(String varName) {
+		return variableMap.get(varName);
+	}
+	
+	public List<Variable>  getVariables() {
+		return Collections.unmodifiableList(variables);
+	}
+
+	
+	protected void stateLeft(State state) {
+		currentStateConfigurartion.remove(state);
+		if (listener != null) listener.stateLeft(state);
+	}
+	
+	protected void stateEntered(State state) {
+		currentStateConfigurartion.add(state);
+		if (listener != null) listener.stateEntered(state);
+	}
+	
+	protected void transitionFired(Transition trans) {
+		if (listener != null) listener.transitionFired(trans);
+	}
+	
+	public Set<State> getCurrentStateConfiguration() {
+		return Collections.unmodifiableSet(currentStateConfigurartion);
+	}
+	
+	
+	public void raise(String signal) {
+		setEvent(eventMap.get(signal));
+	}
+
+	public void reset(String signal) {
+		raisedEvents.remove(eventMap.get(signal));
+	}
+
+	
+	public void call(String procedureId) {
+		// TODO Auto-generated method stub		
+	}
+
+	
+	/**
+	 * If a node is registered with a key then it can be accessed by the key using this method.
+	 * Before a node can be accessed this way it must be registered using {@link #registerNode}. 
+	 * @param alias
+	 * @return the node object that is registered for the given key.
+	 */
+	public Object getElementByAlias(Object alias) {
+		return aliasToElementMap.get(alias);
+	}
+	
+	/**
+	 * If a node is registered with a key then it can be accessed by the key using this method.
+	 * Before a node can be accessed this way it must be registered using {@link #registerNode}. 
+	 * @param element
+	 * @return the node object that is registered for the given key.
+	 */
+	public Object getAliasByElement(Object element) {
+		return elementToAliasMap.get(element);
+	}
+	
+	/**
+	 * Nodes can optionally be regitered with a key for later lookup.
+	 * 
+	 * @param key the key object
+	 * @param element the node
+	 */
+	public void defineAlias(Object alias, Object element) {
+		aliasToElementMap.put(alias, element);
+		elementToAliasMap.put(element, alias);
+	}
+
+	
+	public List<Region> getAllRegions() {
+		List<Region> allRegions = new ArrayList<Region>();
+		
+		allRegions.addAll(getRegions());
+		for (Region region : getRegions()) {
+			addAllRegions(allRegions, region);
+		}
+
+		
+		return allRegions;
+	}
+
+	
+	protected void addAllRegions(List<Region> regions, Region region) {
+		for (Node node : region.getNodes()) {
+			if (node instanceof CompoundState) addAllRegions(regions, (CompoundState) node);
+		}
+	}
+	
+	protected void addAllRegions(List<Region> regions, CompoundState cState) {
+		regions.addAll(cState.getRegions());
+		
+		for (Region region : cState.getRegions()) {
+			addAllRegions(regions, region);
+		}
+	}
+	
+	
+}

+ 22 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/StatechartListener.java

@@ -0,0 +1,22 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import org.yakindu.sct.simulation.runtime.sgraph.State;
+import org.yakindu.sct.simulation.runtime.sgraph.Transition;
+
+public interface StatechartListener {
+	
+	void stateEntered(State state);
+	void stateLeft(State state);
+	void transitionFired(Transition trans);
+
+}

+ 30 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/StatechartRuntimeException.java

@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+public class StatechartRuntimeException extends RuntimeException {
+
+	public StatechartRuntimeException() {
+	}
+
+	public StatechartRuntimeException(String message) {
+		super(message);
+	}
+
+	public StatechartRuntimeException(Throwable cause) {
+		super(cause);
+	}
+
+	public StatechartRuntimeException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+}

+ 47 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/TimeEventExpression.java

@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+import org.yakindu.sct.simulation.runtime.sgraph.TimeEvent;
+import org.yakindu.sct.simulation.runtime.stext.Trigger;
+
+public class TimeEventExpression extends org.yakindu.sct.simulation.runtime.sgraph.TimeEvent {
+
+	protected Trigger.TimeEvent timeEvent;
+	protected ExecutionScope scope;
+
+	public TimeEventExpression(String id, Trigger.TimeEvent timeEvent, ExecutionScope scope) {
+		super(id);
+		this.timeEvent = timeEvent;
+		this.scope = scope;
+	}
+
+
+		
+	public Trigger.TimeEvent getTimeEvent() {
+			return timeEvent;
+		}
+
+
+
+	public void setTimeEvent(Trigger.TimeEvent timeEvent) {
+			this.timeEvent = timeEvent;
+		}
+
+
+	@Override
+	public long getDuration() {
+		return ((Integer)timeEvent.execute(scope)).longValue();
+	}
+
+	
+}

+ 268 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/builder/StatechartBuilder.java

@@ -0,0 +1,268 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.sgraph.builder;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.yakindu.sct.model.sgraph.impl.EventImpl;
+import org.yakindu.sct.model.sgraph.impl.FinalStateImpl;
+import org.yakindu.sct.model.sgraph.impl.PseudostateImpl;
+import org.yakindu.sct.model.sgraph.impl.RegionImpl;
+import org.yakindu.sct.model.sgraph.impl.StateImpl;
+import org.yakindu.sct.model.sgraph.impl.TransitionImpl;
+import org.yakindu.sct.model.sgraph.impl.VariableImpl;
+import org.yakindu.sct.simulation.runtime.sgraph.Action;
+import org.yakindu.sct.simulation.runtime.sgraph.ActionStatement;
+import org.yakindu.sct.simulation.runtime.sgraph.CompoundState;
+import org.yakindu.sct.simulation.runtime.sgraph.FinalState;
+import org.yakindu.sct.simulation.runtime.sgraph.Guard;
+import org.yakindu.sct.simulation.runtime.sgraph.GuardExpression;
+import org.yakindu.sct.simulation.runtime.sgraph.Node;
+import org.yakindu.sct.simulation.runtime.sgraph.Pseudostate;
+import org.yakindu.sct.simulation.runtime.sgraph.PseudostateKind;
+import org.yakindu.sct.simulation.runtime.sgraph.Region;
+import org.yakindu.sct.simulation.runtime.sgraph.SignalEvent;
+import org.yakindu.sct.simulation.runtime.sgraph.SimpleState;
+import org.yakindu.sct.simulation.runtime.sgraph.State;
+import org.yakindu.sct.simulation.runtime.sgraph.Statechart;
+import org.yakindu.sct.simulation.runtime.sgraph.TimeEvent;
+import org.yakindu.sct.simulation.runtime.sgraph.TimeEventExpression;
+import org.yakindu.sct.simulation.runtime.sgraph.Transition;
+import org.yakindu.sct.simulation.runtime.stext.Expression;
+import org.yakindu.sct.simulation.runtime.stext.Function;
+import org.yakindu.sct.simulation.runtime.stext.FunctionMethod;
+import org.yakindu.sct.simulation.runtime.stext.Trigger;
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+import org.yakindu.sct.simulation.runtime.stext.builder.BuilderException;
+import org.yakindu.sct.simulation.runtime.stext.builder.ExpressionBuilder;
+
+public class StatechartBuilder extends Function {
+	
+	
+	protected static Comparator<Region> regionComparator = new Comparator<Region>(){
+		public int compare(Region o1, Region o2) {
+			return o1.getPriority() - o2.getPriority();
+		}
+	};
+	
+	protected static Map<PseudoTypes, PseudostateKind> pseudotypeMap;
+	
+	static {
+		pseudotypeMap = new HashMap<statemachine.PseudoTypes, PseudostateKind>();
+		pseudotypeMap.put(statemachine.PseudoTypes.CHOICE, PseudostateKind.CHOICE);
+		pseudotypeMap.put(statemachine.PseudoTypes.DEEP_HISTORY, PseudostateKind.DEEPHISTORY);
+		pseudotypeMap.put(statemachine.PseudoTypes.INITIAL, PseudostateKind.INITIAL);
+		pseudotypeMap.put(statemachine.PseudoTypes.JUNCTION, PseudostateKind.JUNCTION);
+		pseudotypeMap.put(statemachine.PseudoTypes.SHALLOW_HISTORY, PseudostateKind.SHALLOWHISTORY);
+	}
+	
+	public Statechart build(org.yakindu.sct.model.sgraph.Statechart source) {
+		Statechart sc = new Statechart(source.getUUID());
+		build(sc, source.eContents());		
+		
+		return sc;
+	}
+
+	
+	@FunctionMethod("")
+	public Object build(Statechart tParent, VariableImpl sChild) {
+		Variable var = new Variable(sChild.getName());
+		tParent.addVariable(var);
+		tParent.defineAlias(sChild, var);
+
+		if (sChild.getgetDataType() == statemachine.DataTypes.BOOLEAN) {
+			var.setType(Boolean.class);
+			var.setValue(false);
+		}
+		else if (sChild.getDataType() == statemachine.DataTypes.INT) {
+			var.setType(Integer.class);
+			var.setValue(0);
+		}
+		else if (sChild.getDataType() == statemachine.DataTypes.DOUBLE) {
+			var.setType(Float.class);
+			var.setValue(0.0f);
+		}
+			
+		return var;
+	}
+	
+	
+	@FunctionMethod("")
+	public Object build(Statechart tParent, EventImpl sChild) {
+		SignalEvent event = new SignalEvent(sChild.getName());
+		tParent.addSignalEvent(event);
+		tParent.defineAlias(sChild, event);
+		return event;
+	}
+	
+	
+	@FunctionMethod("")
+	public Object build(Statechart tParent, RegionImpl sChild) {
+		Region region = new Region("" + sChild.getPriority(), sChild.getPriority(), tParent);
+		Collections.sort(tParent.getRegions(), regionComparator);
+		
+		build(region, sChild.eContents());		
+
+		return region;
+	}
+	
+	
+	@FunctionMethod("")
+	public Object build(Statechart tParent, TransitionImpl sTrans) {
+		
+		Node fromNode = (Node) tParent.getElementByAlias(sTrans.getSourceNode()); 
+		Node toNode = (Node) tParent.getElementByAlias(sTrans.getTargetNode());
+		String expression = sTrans.getExpression();
+
+		String transitionId = "t@" + sTrans.getId();
+		TimeEvent timeTrigger = null;
+		Set<SignalEvent> signalTriggers = new HashSet<SignalEvent>();
+		Guard  guard  = null;
+		Action action = null;
+		
+		
+		if (expression != null && expression.trim().length()>0) {
+			ExpressionBuilder builder = new ExpressionBuilder();
+			
+			String triggerExpression = JavaExtensions.extractTriggerExpressionString(expression);
+			if (triggerExpression != null && triggerExpression.trim().length() >0) {
+				List<Trigger> triggers = builder.buildTriggerExpression(triggerExpression);
+				for (Trigger trigger : triggers) {
+					if (trigger instanceof Trigger.SignalEvent) {
+						SignalEvent event = tParent.getSignalEvent(((Trigger.SignalEvent) trigger).getSignal());
+						if (event != null) signalTriggers.add(event);
+					} else if (trigger instanceof Trigger.TimeEvent) {
+						timeTrigger = new TimeEventExpression(transitionId + ".timer", 
+								(Trigger.TimeEvent)trigger, 
+								tParent);
+					}
+				}
+			}
+			
+			String guardExpression = JavaExtensions.extractGuardExpressionString(expression);
+			guard = (guardExpression != null && guardExpression .trim().length() > 0 ) 
+			? new GuardExpression(builder.buildGuardExpression(guardExpression), tParent) 
+			: null;
+
+			String actionExpresion = JavaExtensions.extractActionExpressionString(expression);
+			action = (actionExpresion != null && actionExpresion.trim().length() > 0 ) 
+					? new ActionStatement(builder.buildActionExpression(actionExpresion), tParent) 
+					: null;
+
+		}
+		
+		Transition tTrans = new Transition(
+				"t@" + sTrans.getId(), 
+				sTrans.getPriority(), 
+				timeTrigger,
+				signalTriggers,
+				guard,
+				action, 
+				fromNode,
+				toNode);
+		
+		tParent.defineAlias(sTrans, tTrans);
+
+		return tTrans;
+	}
+	
+	
+	@FunctionMethod("")
+	public Object build(CompoundState tParent, RegionImpl sChild) {
+		Region region = new Region("" + sChild.getPriority(), sChild.getPriority(), tParent);
+		Collections.sort(tParent.getRegions(), regionComparator);
+		
+		build(region, sChild.eContents());		
+
+		return region;
+	}
+	
+	
+	@FunctionMethod("")
+	public Object build(Region tParent, PseudostateImpl sChild) {
+		Pseudostate pseudoState = new Pseudostate(tParent.getId() + "." + sChild.getId(), tParent, pseudotypeMap.get(sChild.getPseudoType()) );
+		((Statechart)tParent.getStatechart()).defineAlias(sChild, pseudoState);
+		return pseudoState;
+	}
+	
+	
+	@FunctionMethod("")
+	public Object build(Region tParent, StateImpl sChild) {
+		ExpressionBuilder builder = new ExpressionBuilder();
+		
+		ActionStatement entryAction = (sChild.getEntry() != null && sChild.getEntry().trim().length()>0) ? 
+				new ActionStatement(builder.buildActionExpression(sChild.getEntry()), (Statechart) tParent.getStatechart()) : null;
+		ActionStatement doAction = (sChild.getDo() != null && sChild.getDo().trim().length()>0) ? 
+				new ActionStatement(builder.buildActionExpression(sChild.getDo()), (Statechart) tParent.getStatechart()) : null;
+		ActionStatement exitAction = (sChild.getExit() != null && sChild.getExit().trim().length()>0) ? 
+				new ActionStatement(builder.buildActionExpression(sChild.getExit()), (Statechart) tParent.getStatechart()) : null;
+		
+		State state = null;
+		if ( sChild.getRegion().size() > 0 ) {
+			state = new CompoundState(tParent.getId() + "." + sChild.getName(), sChild.getName(), tParent, entryAction, exitAction );
+			build(state, sChild.eContents());
+			
+		} else {
+			state = new SimpleState(tParent.getId() + "." + sChild.getName(), sChild.getName(), tParent, entryAction, doAction, exitAction );
+		}
+		
+		((Statechart)tParent.getStatechart()).defineAlias(sChild, state);
+
+		return state;
+	}
+	
+	
+	
+	@FunctionMethod("")
+	public Object build(Region tParent, FinalStateImpl sChild) {		
+		FinalState state = new FinalState(tParent.getId() + ".<final>", tParent );
+		((Statechart)tParent.getStatechart()).defineAlias(sChild, state);
+		return state;
+	}
+	
+	
+	
+	protected void build(Object targetParent, EList<EObject> sourceChildren) {
+		for (EObject source : sourceChildren) {
+			build(targetParent, source);
+		}
+	}
+	
+	
+	/**
+	 * Internal build method that performs the dynamic dispatch to the appropriate (correctly named) 
+	 * builder function. The parameter is always a EObject and since we have use dynamic EMF we match by 
+	 * naming conventions.
+	 * 
+	 * @param sourceChild
+	 * @return
+	 */
+	protected Object build(Object targetParent, EObject sourceChild) {
+		if ( sourceChild == null ) return null;
+		
+		Object[] params = new Object[]{targetParent, sourceChild};
+		
+		Function f = ExpressionBuilder.lookup(this.getClass(), "build", params);
+		if (f != null) 
+			return f.execute(params);
+		
+		throw new BuilderException("No function  build(" + targetParent.getClass().getName() + ", " + sourceChild.eClass().getName() + ") !");
+	}
+
+}

+ 29 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Assert.java

@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+
+public class Assert {
+	
+	
+	private Assert() {
+		super();
+	}
+
+	
+	public static Boolean filterBoolean(Object value) {
+		if (value instanceof Boolean) return (Boolean) value;
+		
+		throw new EvaluationException("Boolean value expected");
+	}
+
+}

+ 56 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Assign.java

@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+/**
+ * 
+ * @author terfloth@itemis.de
+ *
+ */
+public class Assign implements Statement {
+	
+	protected VariableRef varRef;
+	protected Expression expression;
+	
+	
+	public Assign() {
+		super();
+	}
+
+	public Assign(VariableRef varRef, Expression expression) {
+		this();
+		this.varRef = varRef;
+		this.expression = expression;
+	}
+	
+	public VariableRef getVarRef() {
+		return varRef;
+	}
+	
+	public void setVarRef(VariableRef varRef) {
+		this.varRef = varRef;
+	}
+
+	public Expression getExpression() {
+		return expression;
+	}
+
+	public void setExpression(Expression expression) {
+		this.expression = expression;
+	}
+
+	public void execute(ExecutionScope scope) {
+		varRef.getVariable(scope).setValue(expression.execute(scope));
+	}
+
+}

+ 113 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/BinaryOperation.java

@@ -0,0 +1,113 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class BinaryOperation implements Expression {
+
+	
+	protected Expression expr1;
+	protected Expression expr2;
+	protected Operator   operator;
+	
+	public BinaryOperation() {
+	}
+	
+	public BinaryOperation(Operator operator, Expression expr1, Expression expr2) {
+		super();
+		this.expr1 = expr1;
+		this.expr2 = expr2;
+		this.operator = operator;
+	}
+
+	public BinaryOperation(String operator, Expression expr1, Expression expr2) {
+		this(new Operator(operator), expr1, expr2);
+	}
+
+	public Expression getExpr1() {
+		return expr1;
+	}
+
+	public void setExpr1(Expression expr1) {
+		this.expr1 = expr1;
+	}
+
+	public Expression getExpr2() {
+		return expr2;
+	}
+
+	public void setExpr2(Expression expr2) {
+		this.expr2 = expr2;
+	}
+
+	public Operator getOperator() {
+		return operator;
+	}
+
+	public void setOperator(Operator operator) {
+		this.operator = operator;
+	}
+
+	public Object execute(ExecutionScope scope) {
+		return operator.execute(this, scope);
+	}
+
+		
+	public static class Operator{
+
+		protected String function = null;
+		
+		
+		public Operator() {
+			super();
+		}
+
+		public Operator(String function) {
+			super();
+			this.function = function;
+		}
+
+		public Object execute(BinaryOperation operation, ExecutionScope scope) {
+			Object[] operands = new Object[2];
+			operands[0] = operation.expr1.execute(scope);
+			operands[1] = operation.expr2.execute(scope);
+		
+			Function func = Function.lookup(CoreFunction.class, function, operands);
+			if (func == null) 
+				throw new EvaluationException("Can't resolve function '" + function 
+						+ "' for types (" + operands[0].getClass().getName() + ", " 
+						+  operands[1].getClass().getName() + ") !");
+
+			return func.execute(operands);
+		}		
+	}
+	
+	
+	public static Operator OR = new Operator() {
+		public Object execute(BinaryOperation operation, ExecutionScope scope) {
+			return Assert.filterBoolean( operation.expr1.execute(scope)).booleanValue() 
+					? Boolean.TRUE
+					: Assert.filterBoolean( operation.expr2.execute(scope) ) ; 
+		}
+	};
+
+	public static Operator AND = new Operator() {
+		public Object execute(BinaryOperation operation, ExecutionScope scope) {
+			return Assert.filterBoolean( operation.expr1.execute(scope)).booleanValue() 
+					? Assert.filterBoolean( operation.expr2.execute(scope) )
+					: Boolean.FALSE ; 
+		}
+	};
+
+	
+}

+ 78 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Conditional.java

@@ -0,0 +1,78 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class Conditional implements Expression {
+
+	protected Expression condition;
+	protected Expression trueValue;
+	protected Expression falseValue;
+	
+	
+	public Conditional() {
+	}
+	
+	
+	public Conditional(Expression condition, Expression trueValue, Expression falseValue) {
+		super();
+		this.condition = condition;
+		this.trueValue = trueValue;
+		this.falseValue = falseValue;
+	}
+
+
+	
+	public Expression getCondition() {
+		return condition;
+	}
+
+
+	public void setCondition(Expression condition) {
+		this.condition = condition;
+	}
+
+
+	public Expression getTrueValue() {
+		return trueValue;
+	}
+
+
+	public void setTrueValue(Expression trueValue) {
+		this.trueValue = trueValue;
+	}
+
+
+	public Expression getFalseValue() {
+		return falseValue;
+	}
+
+
+	public void setFalseValue(Expression falseValue) {
+		this.falseValue = falseValue;
+	}
+
+
+	public Object execute(ExecutionScope scope) {
+		
+		Object conditionResult = condition.execute(scope);
+		
+		if (! (conditionResult instanceof Boolean)) {
+			throw new RuntimeException("Evaluation Error: condition must be boolean.");
+		}
+		
+		return ((Boolean) conditionResult).booleanValue() ? 
+				trueValue.execute(scope) : 
+				falseValue.execute(scope);
+	}
+
+}

+ 38 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Constant.java

@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+/**
+ * 
+ * @author terfloth@itemis.de
+ *
+ */
+public class Constant implements Expression {
+	
+	protected Object value;
+	
+	public Constant(Object value) {
+		super();
+		this.value = value;
+	}
+
+	public Object getValue() {
+		return value;
+	}
+
+	public Object execute(ExecutionScope scope) {
+		return value;
+	}
+	
+	
+}

+ 243 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/CoreFunction.java

@@ -0,0 +1,243 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+
+public class CoreFunction extends Function {
+	
+	public static String EQUALS			= "==";
+	public static String NOT_EQUALS		= "!=";
+	public static String SMALLER		= "<";
+	public static String SMALLER_EQUAL	= "<=";
+	public static String GREATER		= ">";
+	public static String GREATER_EQUAL	= ">=";
+
+	public static String BIT_AND		= "&";
+	public static String BIT_OR			= "|";
+	public static String BIT_XOR		= "^";
+	public static String BIT_LSHIFT		= "<<";
+	public static String BIT_RSHIFT		= ">>";
+	public static String BIT_COMPLEMENT = "~";
+	
+	public static String PLUS			= "+";
+	public static String MINUS			= "-";
+	public static String MULTIPLY		= "*";
+	public static String DIVIDE			= "/";
+	public static String MODULO			= "%";
+	
+	public static String POSITIVE		= "+";
+	public static String NEGATIVE		= "-";
+	public static String NOT			= "!";
+
+
+	
+	@FunctionMethod("+")
+	public Integer plus(Integer i1, Integer i2) {
+		return i1 + i2;
+	}
+	
+	@FunctionMethod("+")
+	public Float plus(Float f1, Float f2) {
+		return f1 + f2;
+	}	
+	
+	@FunctionMethod("+")
+	public Integer positive(Integer i) {
+		return i;
+	}	
+	
+	@FunctionMethod("+")
+	public Float positive(Float f) {
+		return f;
+	}	
+	
+	@FunctionMethod("-")
+	public Integer negative(Integer i) {
+		return -i;
+	}	
+	
+	@FunctionMethod("-")
+	public Float negative(Float f) {
+		return -f;
+	}	
+	
+
+	@FunctionMethod("-")
+	public Integer minus(Integer i1, Integer i2) {
+		return i1 - i2;
+	}
+	
+	@FunctionMethod("-")
+	public Float minus(Float i1, Float i2) {
+		return i1 - i2;
+	}
+	
+	@FunctionMethod("*")
+	public Integer mul(Integer i1, Integer i2) {
+		return i1 * i2;
+	}
+	
+	@FunctionMethod("*")
+	public Float mul(Float i1, Float i2) {
+		return i1 * i2;
+	}
+	
+	@FunctionMethod("/")
+	public Integer div(Integer i1, Integer i2) {
+		return i1 / i2;
+	}
+	
+	@FunctionMethod("/")
+	public Float div(Float i1, Float i2) {
+		return i1 / i2;
+	}
+	
+	@FunctionMethod("%")
+	public Integer mod(Integer i1, Integer i2) {
+		return i1 % i2;
+	}
+	
+	@FunctionMethod("%")
+	public Float mod(Float i1, Float i2) {
+		return i1 % i2;
+	}
+	
+	@FunctionMethod("<<")
+	public Integer left(Integer i1, Integer i2) {
+		return i1 << i2;
+	}
+	
+	@FunctionMethod(">>")
+	public Integer right(Integer i1, Integer i2) {
+		return i1 >> i2;
+	}
+	
+	@FunctionMethod("&")
+	public Integer bitwiseAnd(Integer i1, Integer i2) {
+		return i1 & i2;
+	}
+	
+	@FunctionMethod("|")
+	public Integer bitwiseOr(Integer i1, Integer i2) {
+		return i1 | i2;
+	}
+	
+	@FunctionMethod("^")
+	public Integer bitwiseXor(Integer i1, Integer i2) {
+		return i1 ^ i2;
+	}
+	
+	@FunctionMethod("^")
+	public Long bitwiseXor(Long l1, Long l2) {
+		return l1 ^ l2 ;
+	}
+	
+	@FunctionMethod("==")
+	public Boolean equals(Boolean b1, Boolean b2) {
+		return b1.equals(b2);
+	}
+
+	@FunctionMethod("==")
+	public Boolean equals(Integer i1, Integer i2) {
+		return i1.intValue() == i2.intValue();
+	}
+
+	@FunctionMethod("==")
+	public Boolean equals(Float i1, Float i2) {
+		return i1.floatValue() == i2.floatValue();
+	}
+	
+	@FunctionMethod("!=")
+	public Boolean notEquals(Boolean b1, Boolean b2) {
+		return b1.booleanValue() != b2.booleanValue();
+	}
+	
+	@FunctionMethod("!=")
+	public Boolean notEquals(Integer i1, Integer i2) {
+		return i1.intValue() != i2.intValue();
+	}
+	
+	@FunctionMethod("!=")
+	public Boolean notEquals(Float i1, Float i2) {
+		return i1.floatValue() != i2.floatValue();
+	}
+
+	@FunctionMethod(">=")
+	public Boolean greaterEqual(Integer i1, Integer i2) {
+		return i1 >= i2;
+	}
+	
+	@FunctionMethod(">=")
+	public Boolean greaterEqual(Float i1, Float i2) {
+		return i1 >= i2;
+	}
+
+	@FunctionMethod("<=")
+	public Boolean smallerEqual(Integer i1, Integer i2) {
+		return i1 <= i2;
+	}
+	
+	@FunctionMethod("<=")
+	public Boolean smallerEqual(Float i1, Float i2) {
+		return i1 <= i2;
+	}
+
+	@FunctionMethod(">")
+	public Boolean greater(Integer i1, Integer i2) {
+		return i1 > i2;
+	}
+	
+	@FunctionMethod(">")
+	public Boolean greater(Float i1, Float i2) {
+		return i1 > i2;
+	}
+
+	@FunctionMethod("<")
+	public Boolean smaller(Integer i1, Integer i2) {
+		return i1 < i2;
+	}
+	
+	@FunctionMethod("<")
+	public Boolean smaller(Float i1, Float i2) {
+		return i1 < i2;
+	}
+
+	@FunctionMethod("!")
+	public Boolean not(Boolean b) {
+		return !b;
+	}
+
+	@FunctionMethod("+")
+	public Boolean positive(Boolean b) {
+		return b;
+	}
+
+	@FunctionMethod("+")
+	public String positive(String s) {
+		return s;
+	}
+
+	@FunctionMethod("+")
+	public Double positive(Double d) {
+		return d;
+	}
+
+	@FunctionMethod("-")
+	public Double negative(Double d) {
+		return -d;
+	}
+
+	@FunctionMethod("~")
+	public Integer complement(Integer i) {
+		return ~i;
+	}
+	
+}

+ 19 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Expression.java

@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public interface Expression {
+	
+	Object execute(ExecutionScope scope);
+
+}

+ 33 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/ExpressionRuntimeException.java

@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+public class ExpressionRuntimeException extends RuntimeException {
+
+	private static final long serialVersionUID = 1L;
+
+	public ExpressionRuntimeException() {
+		// TODO Auto-generated constructor stub
+	}
+
+	public ExpressionRuntimeException(String message) {
+		super(message);
+	}
+
+	public ExpressionRuntimeException(Throwable cause) {
+		super(cause);
+	}
+
+	public ExpressionRuntimeException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+}

+ 110 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Function.java

@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+
+public class Function {
+
+	protected Method functionMethod;
+
+	/**
+	 * Looks up the appropriate function for the given parameter types. This lookup currently does not perform a polymophic lookup.
+	 * 
+	 * @param name
+	 * @param paramTypes
+	 * @return
+	 */
+	public static Function lookup(Class<?> functionClass, String name, Class<?>[] paramTypes) {
+		Method[] methods = functionClass.getDeclaredMethods();
+		for (int i = 0; i < methods.length; i++) {
+			Method fMethod = methods[i];
+			FunctionMethod fAnno = fMethod.getAnnotation(FunctionMethod.class);
+			if (fAnno != null) {
+				if ((name.equals(fMethod.getName())) || name.equals(fAnno.value())) {
+					if (Arrays.equals(paramTypes, fMethod.getParameterTypes())) {						
+						return createFunction(functionClass, fMethod);
+					}
+				}
+			}
+		}
+		
+		return null;
+	}
+
+	
+	public static Function lookup(Class<?> functionClass, String name, Object[] params) {
+		Class<?>[] paramTypes = new Class<?>[params.length];
+		for (int i = 0; i < params.length; i++) {
+			paramTypes[i] = params[i].getClass();
+		}
+		return lookup(functionClass, name, paramTypes);
+	}
+
+
+	protected static Function createFunction(Class<?> functionClass, Method functionMethod) {
+
+		if ( functionClass == null || functionMethod == null ) return null;
+		
+		try {
+			Constructor<?> constr;
+			try {
+				constr = (Constructor<?>) functionClass.getConstructor(new Class<?>[0]);
+			} catch (NoSuchMethodException e) {
+				throw new ExpressionRuntimeException("Missing default constructor in class " + functionClass.getName() + " while loading function " + functionMethod.getName() + " !");
+			}
+
+			Function func = (Function) constr.newInstance(new Object[0]);
+			func.setFunctionMethod(functionMethod);
+			return func;
+
+		} catch (ExpressionRuntimeException e) {
+			throw e;
+		} catch (Exception e) {
+			throw new ExpressionRuntimeException("Error loading function " + functionMethod.getName() + " from function class " + functionClass.getName() + " !", e);
+		}
+	}
+
+	
+	
+	public Function() {
+		super();
+	}
+	
+	
+	
+	public Method getFunctionMethod() {
+		return functionMethod;
+	}
+
+	public void setFunctionMethod(Method functionMethod) {
+		this.functionMethod = functionMethod;
+	}
+
+	
+	public Object execute(Object[] params) {
+		try {
+			return getFunctionMethod().invoke(this, params);
+		} catch (IllegalArgumentException e) {
+			throw new EvaluationException(e);
+		} catch (IllegalAccessException e) {
+			throw new EvaluationException(e);
+		} catch (InvocationTargetException e) {
+			throw new EvaluationException(e.getCause());
+		}
+	}
+
+}

+ 30 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/FunctionMethod.java

@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * Indicates that a method is a function.
+ * 
+ * @author terfloth@itemis.de 
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface FunctionMethod {
+	String value() ;
+}

+ 42 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/ProcedureCall.java

@@ -0,0 +1,42 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class ProcedureCall implements Statement {
+
+	protected String procedureId;
+	
+	
+	public ProcedureCall() {
+		super();
+	}
+
+	public ProcedureCall(String procedureId) {
+		super();
+		this.procedureId = procedureId;
+	}
+	
+
+	public String getProcedureId() {
+		return procedureId;
+	}
+
+	public void setProcedureId(String procedureId) {
+		this.procedureId = procedureId;
+	}
+
+	public void execute(ExecutionScope scope) {
+		scope.call(procedureId);
+	}
+
+}

+ 45 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Raise.java

@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class Raise implements Statement {
+
+	protected String signal;
+	
+	
+	public Raise() {
+		super();
+	}
+	
+
+	public Raise(String signal) {
+		this();
+		this.signal = signal;
+	}
+
+
+	public String getSignal() {
+		return signal;
+	}
+
+
+	public void setSignal(String signal) {
+		this.signal = signal;
+	}
+
+
+	public void execute(ExecutionScope scope) {
+		scope.raise(signal);
+	}
+
+}

+ 67 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Scope.java

@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+
+/**
+ * 
+ * @author terfloth@itemis.de
+ */
+public class Scope implements ExecutionScope {
+
+	protected Map<String, Variable> variables = new HashMap<String, Variable>();
+	
+	/* (non-Javadoc)
+	 * @see com.yakindu.statechart.model.expressions.runtime.ExecutionScope#getValue(java.lang.String)
+	 */
+	public Object getValue(String varName) {
+		Variable var = getVariable(varName);
+		
+		// TODO : handle not existing variables.
+		return (var != null) ? var.getValue() : null ;
+	}
+
+	/* (non-Javadoc)
+	 * @see com.yakindu.statechart.model.expressions.runtime.ExecutionScope#getVariable(java.lang.String)
+	 */
+	public Variable getVariable(String varName) {
+		return variables.get(varName);
+	}
+		
+	/* (non-Javadoc)
+	 * @see com.yakindu.statechart.model.expressions.runtime.ExecutionScope#addVariable(com.yakindu.statechart.model.expressions.runtime.Variable)
+	 */
+	public void addVariable(Variable var) {
+		// TODO : check for exceptions etc...
+		variables.put(var.getName(), var);
+	}
+
+
+	/* (non-Javadoc)
+	 * @see com.yakindu.statechart.model.expressions.runtime.ExecutionScope#call(java.lang.String)
+	 */
+	public void call(String procedureId) {
+		// TODO Auto-generated method stub
+	}
+
+	/* (non-Javadoc)
+	 * @see com.yakindu.statechart.model.expressions.runtime.ExecutionScope#raise(java.lang.String)
+	 */
+	public void raise(String signal) {
+		// TODO Auto-generated method stub		
+	}
+	
+}

+ 18 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Statement.java

@@ -0,0 +1,18 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public interface Statement {
+
+	void execute(ExecutionScope scope);
+}

+ 32 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/StatementSequence.java

@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import java.util.ArrayList;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+/**
+ * A statement sequence is a statement that executes a list of statements.
+ *  
+ * @author terfloth@itemis.de
+ */
+public class StatementSequence extends ArrayList<Statement> implements Statement {
+
+	private static final long serialVersionUID = -7484316500582800045L;
+
+	public void execute(ExecutionScope scope) {
+		for (Statement stmt : this) {	
+			stmt.execute(scope);
+		}
+	}
+
+}

+ 58 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Trigger.java

@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class Trigger {
+	
+	public static class SignalEvent extends Trigger {
+		protected String signal;
+
+		public SignalEvent(String signal) {
+			super();
+			this.signal = signal;
+		}
+
+		public String getSignal() {
+			return signal;
+		}
+
+		public void setSignal(String signal) {
+			this.signal = signal;
+		}
+		
+	}
+	
+	public static class TimeEvent extends Trigger implements Expression {
+		protected Expression durationExp;
+
+		
+		public TimeEvent(Expression timeValueExp) {
+			super();
+			this.durationExp = timeValueExp;
+		}
+
+		public Expression getDurationExp() {
+			return durationExp;
+		}
+
+		public void setDurationExp(Expression timeValueExp) {
+			this.durationExp = timeValueExp;
+		}
+
+		public Object execute(ExecutionScope scope) {
+			return durationExp.execute(scope);
+		}
+		
+		
+	}
+}

+ 59 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/UnaryOperation.java

@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class UnaryOperation implements Expression {
+
+	
+	protected Expression expression;
+	protected String operator;
+	
+	public UnaryOperation() {
+	}
+	
+	public UnaryOperation(String operator, Expression expr) {
+		super();
+		this.expression = expr;
+		this.operator = operator;
+	}
+
+	public Expression getExpression() {
+		return expression;
+	}
+
+	public void setExpression(Expression expr) {
+		this.expression = expr;
+	}
+
+
+	public String getOperator() {
+		return operator;
+	}
+
+	public void setOperator(String operator) {
+		this.operator = operator;
+	}
+
+	public Object execute(ExecutionScope scope) {
+		Object[] operands = new Object[1];
+		operands[0] = expression.execute(scope);
+	
+		Function func = Function.lookup(CoreFunction.class, operator, operands);
+		
+		if (func == null) throw new EvaluationException("Can't resolve function '" + operator + "' for type " + operands[0].getClass().getName() + " !");
+		
+		return func.execute(operands);
+	}
+	
+}

+ 74 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Variable.java

@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.EvaluationException;
+
+
+/**
+ * 
+ * 
+ * @author terfloth@itemis.de
+ */
+public class Variable {
+
+	protected String name;
+	protected Object value;
+	protected Class<?> type;
+
+	
+	public Variable() {
+		super();
+	}
+
+	public Variable(String name) {
+		this();
+		this.name = name;
+	}
+
+	public Variable(String name, Class<Object> type) {
+		this();
+		this.name = name;
+		this.type = type;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	
+	public Class<?> getType() {
+		return type;
+	}
+
+	public void setType(Class<?> type) {
+		this.type = type;
+	}
+
+	
+	public Object getValue() {
+		return value;
+	}
+
+	public void setValue(Object value) {
+		if(type != null && (! type.isAssignableFrom(value.getClass()))) {
+			throw new EvaluationException(
+					"Variable <" + name + "> of type " + type 
+					+ " is not assignable from " + value.getClass() + " value.");
+		}
+		this.value = value;
+	}
+	
+}

+ 48 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/VariableRef.java

@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext;
+
+import org.yakindu.sct.simulation.runtime.ExecutionScope;
+
+public class VariableRef implements Expression {
+
+	protected String name;
+	
+	
+	public VariableRef() {
+		super();
+	}
+
+	public VariableRef(String name) {
+		this();
+		this.name = name;
+	}
+
+	
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	
+	public Variable getVariable(ExecutionScope scope) {
+		return scope.getVariable(name);
+	}
+	
+	
+	public Object execute(ExecutionScope scope) {
+		return getVariable(scope).getValue();
+	}
+
+}

+ 32 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/BuilderException.java

@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext.builder;
+
+public class BuilderException extends RuntimeException {
+
+	private static final long serialVersionUID = 1L;
+
+	public BuilderException() {
+	}
+
+	public BuilderException(String message) {
+		super(message);
+	}
+
+	public BuilderException(Throwable cause) {
+		super(cause);
+	}
+
+	public BuilderException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+}

+ 497 - 0
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/ExpressionBuilder.java

@@ -0,0 +1,497 @@
+/**
+ * Copyright (c) 2010-2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.runtime.stext.builder;
+
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+import org.yakindu.sct.simulation.runtime.stext.*;
+
+/**
+ * The ExpressionBuilder creates an executable structure from the textual expression definition 
+ * or the corresponding EMF based abstract syntax tree. This AST is defined by the expression grammer 
+ * of this plugin.<br>
+ * <br>
+ * Expression builder instances are state-less so a single instance can be used to build 
+ * expression runtime structures multiple times and in parallel.<br>
+ * <br>
+ * The current implementation mainly consist of a set of builder functions with a name prefix 'build'. 
+ * This class defines a build function for each grammar rule. So when changing the grammer it will be necessary
+ * to change, add or remove build methods for the affected grammar rules. The implementation strongly relies on dynamic dispatch of build function calls and therefore
+ * makes use of the 'pluggable adapter' pattern and Java reflection. <br>
+ * <br>
+ * Example:
+ * <code>
+ * (new ExpressionBuilder()).build("a = 2*b; a <<= 2;");
+ * </code>
+ * 
+ * @author terfloth@itemis.de
+ *
+ */
+public class ExpressionBuilder extends Function {
+
+	/** Builder functions always*/
+	protected static Class<?>[] paramTypes = new Class[]{EObject.class};
+
+	protected static Map<String, String> assignFunctionMap = new HashMap<String, String>();
+
+	static {
+		assignFunctionMap.put("multAssign", "*"); 
+		assignFunctionMap.put("divAssign", "/"); 
+		assignFunctionMap.put("modAssign", "%");
+		assignFunctionMap.put("addAssign", "+"); 
+		assignFunctionMap.put("subAssign", "-"); 
+		assignFunctionMap.put("leftShiftAssign", "<<"); 
+		assignFunctionMap.put("rightShiftAssign", ">>"); 
+		assignFunctionMap.put("andAssign", "&"); 
+		assignFunctionMap.put("xorAssign", "^"); 
+		assignFunctionMap.put("orAssign", "|");
+	}
+	
+	
+	
+	/**
+	 * Static helper method that creates a executable expression structure from a expression string.
+	 * 
+	 * @param actionExpression
+	 * @return an executable statement object.
+	 */
+	public static Statement buildAction(String actionExpression) {
+		ExpressionBuilder builder = new ExpressionBuilder();
+		return builder.buildActionExpression(actionExpression);
+	}
+
+	
+	/**
+	 * Static helper method that creates a executable expression structure from a expression string.
+	 * 
+	 * @param guardExpression
+	 * @return an executable statement object.
+	 */
+	public static Expression buildGuard(String guardExpression) {
+		ExpressionBuilder builder = new ExpressionBuilder();
+		return builder.buildGuardExpression(guardExpression);
+	}
+
+	
+	/**
+	 * Static helper method that creates a executable expression structure from a expression string.
+	 * 
+	 * @param guardExpression
+	 * @return an executable statement object.
+	 */
+	public static List<Trigger> buildTriggers(String guardExpression) {
+		ExpressionBuilder builder = new ExpressionBuilder();
+		return builder.buildTriggerExpression(guardExpression);
+	}
+
+
+	
+	/**
+	 * The primary builder method that creates a executable statement structure from a expression string.
+	 * 
+	 * @param actionExpression
+	 * @return an executable statement object.
+	 */
+	public Statement buildActionExpression(String expr) {
+		EObject root = JavaExtensions.parseActionExpressionObject(expr);
+		return (Statement) build(root);		
+	}
+	
+	
+	
+	
+	/**
+	 * The primary builder method that creates a executable guard expression structure from an expression string.
+	 * 
+	 * @param actionExpression
+	 * @return an executable statement object.
+	 */
+	public Expression buildGuardExpression(String expr) {
+		EObject root = JavaExtensions.parseGuardExpressionObject(expr);
+		return (Expression) build(root);		
+	}
+
+	
+	/**
+	 * The primary builder method that creates a executable guard expression structure from an expression string.
+	 * 
+	 * @param actionExpression
+	 * @return an executable statement object.
+	 */
+	public List<Trigger> buildTriggerExpression(String expr) {
+		EObject root = JavaExtensions.parseTriggerExpressionObject(expr);
+		return (List<Trigger>) build(root);		
+	}
+	
+	
+	@FunctionMethod("build")
+	public List<Trigger> buildTriggerExpression(EObject obj) {
+		List<Trigger> triggers = new ArrayList<Trigger>();
+
+		for (EObject child : obj.eContents()) {
+			Trigger trigger = (Trigger) build(child);
+			if(trigger != null) triggers.add(trigger);
+		}
+
+		return triggers;
+	}
+	
+	
+	@FunctionMethod("build")
+	public Trigger buildTrigger(EObject obj) {
+		return (Trigger) build(getToOne(obj, "event"));
+	}
+	
+	@FunctionMethod("build")
+	public Trigger buildSignalEvent(EObject obj) {
+		return new Trigger.SignalEvent(getString(obj, "identifier"));
+	}
+	
+	@FunctionMethod("build")
+	public Trigger buildTimeEvent(EObject obj) {
+		return new Trigger.TimeEvent(buildRefExpression(obj, "duration"));
+	}
+	
+	@FunctionMethod("build")
+	public Expression buildTimeConstant(EObject obj) {
+		int duration = getInteger(obj, "value");
+		String unit = getLiteral(obj, "unit");
+		
+		if (unit != null) {
+			if ("second".equals(unit)) duration *= 1000;
+			else if ("nanosecond".equals(unit)) duration /= 1000;
+		}
+		
+		return new Constant(duration);
+	}
+	
+	
+	@FunctionMethod("build")
+	public Expression buildGuardExpression(EObject obj) {
+		return buildRefExpression(obj, "expression");
+	}
+	
+	
+	@FunctionMethod("build")
+	public Statement buildActionExpression(EObject obj) {
+		StatementSequence seq = new StatementSequence();
+		
+		for (EObject child : obj.eContents()) {
+			Statement stmt = (Statement) build(child);
+			if(stmt != null) seq.add(stmt);
+		}
+		
+		return seq;
+	}
+	
+	
+	@FunctionMethod("build")
+	public Statement buildEventRaising(EObject obj) {
+		
+		EObject event = getToOne(obj, "event");		
+		return new Raise(getString(event, "identifier"));
+	}
+	
+
+	@FunctionMethod("build")
+	public Statement buildProcedureCall(EObject obj) {
+		
+		EObject event = getToOne(obj, "procedure");	
+		return new ProcedureCall(getString(event, "identifier"));
+	}
+	
+
+	@FunctionMethod("build")
+	public Statement buildVariableAssignment(EObject obj) {
+		
+		VariableRef var = (VariableRef) build(getToOne(obj, "variableReference"));
+		String operator = getLiteral(obj, "operator");
+		Expression exp = (Expression) build(getToOne(obj, "value"));
+
+		if (! "assign".equals(operator)) {
+			String mappedOperator = assignFunctionMap.get(operator);
+			if (mappedOperator == null) 
+				throw new BuilderException("Assignment operator '" + operator + "' can not be resolved to a function.");
+			
+			exp = new BinaryOperation(mappedOperator, var, exp);
+		}
+		
+		return new Assign(var, exp);
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildConditionalExpression(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+		Expression op3 = buildRefExpression(obj, "operand3");
+
+		if (op1 != null && op2 != null && op3 != null)
+			return new Conditional(op1, op2, op3);
+		
+		return op1;
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildBooleanOrExpression(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BinaryOperation.OR, op1, op2);
+		
+		return op1;
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildBooleanAndExpression(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BinaryOperation.AND, op1, op2);
+		
+		return op1;
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildBitwiseXorExpression(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BIT_XOR, op1, op2);
+		
+		return op1;
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildBitwiseOrExpression(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BIT_OR, op1, op2);
+		
+		return op1;
+	}
+	
+	
+	@FunctionMethod("build")
+	public Expression buildBitwiseAndExpression(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BIT_AND, op1, op2);
+		
+		return op1;
+	}
+	
+
+	public Expression buildBinaryOperation(EObject obj) {
+		
+		Expression op1 = buildRefExpression(obj, "operand1");
+		Expression op2 = buildRefExpression(obj, "operand2");
+		String operator = getLiteral(obj, "operator");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(operator, op1, op2);
+		
+		return op1;
+	}
+
+	
+	@FunctionMethod("build")
+	public Expression buildEqualityExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+	
+	
+	@FunctionMethod("build")
+	public Expression buildRelationalExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+	
+	@FunctionMethod("build")
+	public Expression buildShiftExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+	
+	@FunctionMethod("build")
+	public Expression buildAdditiveExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+	
+	
+	@FunctionMethod("build")
+	public Expression buildMultiplicativeExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildUnaryExpression(EObject obj) {
+		
+		Expression operand = buildRefExpression(obj, "operand");
+		String operator = getLiteral(obj, "operator");
+
+		if (operand != null && operator != null)
+			return new UnaryOperation(operator, operand);
+		
+		return operand;
+	}
+	
+	
+	@FunctionMethod("build")
+	public Expression buildNestedExpression(EObject obj) {
+		return buildRefExpression(obj, "expression");
+	}
+	
+
+	@FunctionMethod("build")
+	public Expression buildLiteralValue(EObject obj) {
+		
+		String value = getString(obj, "value");	
+		
+		// TODO: nur provisrisch - Grammatik muss noch ge�ndert werden,
+		// um unterschiedliche Literaltypen unterscheiden zu koennen
+		if (value != null) {
+			
+			if ("true".equals(value)) return new Constant(Boolean.TRUE);
+			
+			if ("false".equals(value)) return new Constant(Boolean.FALSE);
+
+			try { // flaot
+				if (value.contains("."))
+					return new Constant(Float.parseFloat(value));
+			} catch (NumberFormatException e1) { /* need to be quite */ }
+
+			try { // hex int
+				if (value.startsWith("0x"))
+					return new Constant(new Integer(Integer.parseInt(value.substring(2), 16)));
+			} catch (NumberFormatException e1) { /* need to be quite */ }
+						
+			try { // int
+				return new Constant(new Integer(Integer.parseInt(value)));
+			} catch (NumberFormatException e1) { /* need to be quite */ }
+			
+			if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith("\"") && value.endsWith("\"")) )
+				return new Constant(value.substring(1, value.length()-1));
+		}
+		
+		return new Constant(value);
+	}
+	
+
+	
+	@FunctionMethod("build")
+	public Expression buildVariableReference(EObject obj) {
+		
+		EObject var = getToOne(obj, "variable");	
+		return new VariableRef(getString(var, "identifier"));
+	}
+	
+
+	/**
+	 * Internal build method that performs the dynamic dispatch to the appropriate (correctly named) 
+	 * builder function. The parameter is always a EObject and since we have use dynamic EMF we match by 
+	 * naming conventions.
+	 * 
+	 * @param obj
+	 * @return
+	 */
+	protected Object build(EObject obj) {
+		if ( obj == null ) return null;
+		
+		Object[] params = new Object[]{obj};
+		
+		Function f = ExpressionBuilder.lookup(this.getClass(), "build" + obj.eClass().getName(), paramTypes);
+		if (f != null) 
+			return f.execute(params);
+		
+		throw new BuilderException("No builder function for: " + obj.eClass().getName());
+	}
+	
+	
+	protected Expression buildRefExpression(EObject obj, String refName) {
+		return (Expression) build(getToOne(obj, refName));
+	}
+	
+
+	
+	protected EObject getToOne(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if ( feature instanceof EReference ) {
+			EReference ref = (EReference) feature;
+			return (EObject) obj.eGet(ref);
+		}
+		throw new BuilderException();
+	}
+	
+	
+	protected String getString(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if ( feature instanceof EAttribute ) {
+			EAttribute attr = (EAttribute) feature;
+			return (String) obj.eGet(attr);
+		}
+		throw new BuilderException();
+	}
+
+
+	protected Integer getInteger(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if ( feature instanceof EAttribute ) {
+			EAttribute attr = (EAttribute) feature;
+			return (Integer) obj.eGet(attr);
+		}
+		throw new BuilderException();
+	}
+
+	
+	protected String getLiteral(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if ( feature instanceof EAttribute ) {
+			EAttribute attr = (EAttribute) feature;
+			String literalValue = ((Enumerator) obj.eGet(attr)).getName();
+		
+			return ("NULL".equals(literalValue)) ? null : literalValue;
+		}
+		throw new BuilderException();
+	}
+	
+	
+
+}
+