Переглянути джерело

Add feature to generate statemachine factory support

markus.muehlbrandt@itemis.de 13 роки тому
батько
коміт
fbd28f9d27

+ 1 - 0
plugins/org.yakindu.sct.generator.java/library/FeatureTypeLibrary.xmi

@@ -10,5 +10,6 @@
     <parameters name="RuntimeService" optional="true" parameterType="BOOLEAN"/>
     <parameters name="TimerService" optional="true" parameterType="BOOLEAN"/>
     <parameters name="GenericInterfaceSupport" optional="true" parameterType="BOOLEAN"/>
+    <parameters name="StatemachineFactorySupport" optional="true" parameterType="BOOLEAN"/>
   </types>
 </sgen:FeatureTypeLibrary>

+ 3 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/features/IJavaFeatureConstants.java

@@ -37,12 +37,14 @@ public interface IJavaFeatureConstants {
 	
 	public static final String GENERIC_INTERFACE_SUPPORT = "GenericInterfaceSupport";
 	
+	public static final String STATEMACHINE_FACTORY_SUPPORT = "StatemachineFactorySupport";
+	
 	public static final String[] JAVA_KEYWORDS = { "abstract", "assert",
 		"boolean", "break", "byte", "case", "catch", "char", "class",
 		"const", "continue", "default", "do", "double", "else", "enum",
 		"extends", "false", "final", "finally", "float", "for", "goto", "if",
 		"implements", "import", "instanceof", "int", "interface", "long",
-		"native", "new","null", "package", "private", "protected", "public",
+		"native", "new", "null", "package", "private", "protected", "public",
 		"return", "short", "static", "strictfp", "super", "switch",
 		"synchronized", "this", "throw", "throws", "transient", "true" , "try",
 		"void", "volatile", "while" };

+ 4 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/features/JavaFeatureConstants.java

@@ -66,6 +66,10 @@ public final class JavaFeatureConstants implements IJavaFeatureConstants {
 		return GENERIC_INTERFACE_SUPPORT;
 	}
 	
+	public static final String getStatemachineFactorySupport() {
+		return STATEMACHINE_FACTORY_SUPPORT;
+	}
+	
 	public static final String getValidStatemachineName(String name) {
 		//remove whitespaces;
 		String newName = name.replace(" ", "").toLowerCase();

+ 46 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CustomStatemachineCreationFactory.xpt

@@ -0,0 +1,46 @@
+«REM»
+Copyright (c) 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:
+	Markus Muehlbrandt - Initial contribution and API
+«ENDREM»
+«IMPORT sexec»
+
+«EXTENSION org::yakindu::sct::generator::java::templates::GenmodelEntries»
+«EXTENSION org::yakindu::sct::generator::java::templates::Naming»
+
+«DEFINE file(sgen::GeneratorEntry entry) FOR ExecutionFlow-»
+«FILE getImplementationPackagePath(entry)+'/'+getStatemachineFactoryName()+'.java'-»
+«getLicenseHeader(entry)»
+package «getImplementationPackageName(entry)»;
+
+import «entry.getBasePackageName()».IStatemachine;
+import «entry.getBasePackageName()».IStatemachineCreationFactory;
+
+public class «getStatemachineFactoryName()» implements IStatemachineCreationFactory {
+	
+	public final static IStatemachineCreationFactory INSTANCE = new «getStatemachineFactoryName()»();
+	
+	public IStatemachine createCycleBasedStatemachine() {
+		return new «getCycleBasedStatemachineName()»();
+	}
+	
+	public IStatemachine createActiveEventBasedStatemachine() {
+		«IF entry.createEventBasedStatemachine()-»
+		return new «getEventBasedStatemachineName()»();
+		«ELSE-»
+		throw new UnsupportedOperationException(
+				"Creating active event based statemachine of type \"«getStatemachineFactoryName()»\" is not supported by this factory");
+		«ENDIF-»
+	}
+	
+	public IStatemachine createPassiveEventBasedStatemachine() {
+		throw new UnsupportedOperationException(
+				"Creating passive event based statemachine of type \"«getStatemachineFactoryName()»\" is not supported by this factory");
+	}
+}
+«ENDFILE-»
+«ENDDEFINE»

+ 11 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/GenmodelEntries.ext

@@ -45,7 +45,10 @@ String getInterfaceObserverSupport() :
  
 String getGenericInterfaceSupport() :
  JAVA org.yakindu.sct.generator.java.features.JavaFeatureConstants.getGenericInterfaceSupport();
-		
+
+String getStatemachineFactorySupport() :
+ JAVA org.yakindu.sct.generator.java.features.JavaFeatureConstants.getStatemachineFactorySupport();
+
 String getBasePackageName(GeneratorEntry entry):
 	if entry.getFeatureConfiguration(getNamingFeature())!=null 
 		&& entry.getFeatureConfiguration(getNamingFeature()).getParameterValue(getBasePackage())!=null then
@@ -114,5 +117,12 @@ boolean createGenericInterfaceSupport(GeneratorEntry entry) :
 	if entry.getFeatureConfiguration(getGeneralFeature())!=null
 		&& entry.getFeatureConfiguration(getGeneralFeature()).getParameterValue(getGenericInterfaceSupport()) != null then
 		entry.getFeatureConfiguration(getGeneralFeature()).getParameterValue(getGenericInterfaceSupport()).getBooleanValue()
+	else
+		false;
+		
+boolean createStatemachineFactory(GeneratorEntry entry) :
+	if entry.getFeatureConfiguration(getGeneralFeature())!=null
+		&& entry.getFeatureConfiguration(getGeneralFeature()).getParameterValue(getStatemachineFactorySupport()) != null then
+		entry.getFeatureConfiguration(getGeneralFeature()).getParameterValue(getStatemachineFactorySupport()).getBooleanValue()
 	else
 		false;

+ 28 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/IStatemachineCreationFactory.xpt

@@ -0,0 +1,28 @@
+«REM»
+Copyright (c) 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:
+	Markus Muehlbrandt - Initial contribution and API
+«ENDREM»
+«IMPORT sexec»
+
+«EXTENSION org::yakindu::sct::generator::java::templates::GenmodelEntries»
+
+«DEFINE file(sgen::GeneratorEntry entry) FOR ExecutionFlow-»
+«FILE entry.getBasePackagePath()+'/IStatemachineCreationFactory.java'-»
+«getLicenseHeader(entry)»
+package «entry.getBasePackageName()»;
+
+public interface IStatemachineCreationFactory {
+		
+	public IStatemachine createCycleBasedStatemachine();
+	
+	public IStatemachine createActiveEventBasedStatemachine();
+	
+	public IStatemachine createPassiveEventBasedStatemachine();
+}
+«ENDFILE-»
+«ENDDEFINE»

+ 5 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/Main.xpt

@@ -27,6 +27,11 @@ Contributors:
 		«EXPAND TimerService::file(entry) FOR this»
 	«ENDIF»
 	
+	«IF entry.createStatemachineFactory()»
+		«EXPAND IStatemachineCreationFactory::file(entry) FOR this»
+		«EXPAND CustomStatemachineCreationFactory::file(entry) FOR this»
+	«ENDIF»
+	
 	«IF entry.createGenericInterfaceSupport()»
 		«EXPAND IGenericAccessInterface::file(entry) FOR this»
 		«EXPAND IGenericAccessStatemachine::file(entry) FOR this»

+ 2 - 2
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/Naming.ext

@@ -23,11 +23,11 @@ String getStatemachineName(String name) :
 
 String getStatemachineName(ExecutionFlow this) : 
 	 name.getStatemachineName();
-String getBaseStatemachineName(ExecutionFlow this) : name.toFirstUpper() + "AbstractBaseStatemachine";
-String getBaseStatemachineName(InterfaceScope this) : ((ExecutionFlow)eContainer).getBaseStatemachineName();
+
 String getEventBasedStatemachineName(ExecutionFlow this) : name.toFirstUpper() + "EventBasedStatemachine";
 String getCycleBasedStatemachineName(ExecutionFlow this) : name.toFirstUpper() + "CycleBasedStatemachine";
 String getCycleBasedStatemachineName(InterfaceScope this) : ((ExecutionFlow)eContainer).getCycleBasedStatemachineName();
+String getStatemachineFactoryName(ExecutionFlow this) : name.getStatemachineName().toFirstUpper() + "StatemachineFactory";
 
 String getStatemachineInterfaceTypes(ExecutionFlow this, GeneratorEntry entry):
 	JAVA org.yakindu.sct.generator.java.extensions.JavaExtensions.getStatemachineInterfaceTypes(org.yakindu.sct.model.sexec.ExecutionFlow, org.yakindu.sct.model.sgen.GeneratorEntry);