소스 검색

added concept of statechart languages and module providers to the simulation core

terfloth@itemis.de 11 년 전
부모
커밋
56aa4e9136
14개의 변경된 파일521개의 추가작업 그리고 6개의 파일을 삭제
  1. 8 1
      plugins/org.yakindu.sct.simulation.core.sexec/plugin.xml
  2. 29 0
      plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/SCTLanguageProvider.java
  3. 9 3
      plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/launch/SexecLaunchConfigurationDelegate.java
  4. 4 1
      plugins/org.yakindu.sct.simulation.core/META-INF/MANIFEST.MF
  5. 4 0
      plugins/org.yakindu.sct.simulation.core/plugin.xml
  6. 116 0
      plugins/org.yakindu.sct.simulation.core/schema/languageprovider.exsd
  7. 56 0
      plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/extensions/SCLanguageProviderExtensions.java
  8. 37 0
      plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/ISCLanguage.java
  9. 45 0
      plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/ISCLanguageProvider.java
  10. 72 0
      plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/SCLanguageProviders.java
  11. 41 0
      plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/SCLanguages.java
  12. 83 0
      plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/SimpleSCLanguage.java
  13. 2 1
      plugins/org.yakindu.sct.simulation.ui.sexec/plugin.xml
  14. 15 0
      plugins/org.yakindu.sct.simulation.ui.sexec/src/org/yakindu/sct/simulation/ui/sexec/launch/tabs/StatechartLaunchConfigurationTab.java

+ 8 - 1
plugins/org.yakindu.sct.simulation.core.sexec/plugin.xml

@@ -7,7 +7,14 @@
           delegate="org.yakindu.sct.simulation.core.sexec.launch.SexecLaunchConfigurationDelegate"
           id="org.yakindu.sct.simulation.core.launch.statechart"
           modes="run"
-          name="YAKINDU Statechart">
+          name="Statechart Simulation">
     	</launchConfigurationType>
 	</extension>
+ 
+ <extension
+       point="org.yakindu.sct.simulation.core.languageprovider">
+    <SCLanguageProvider
+          class="org.yakindu.sct.simulation.core.sexec.SCTLanguageProvider">
+    </SCLanguageProvider>
+ </extension>
 </plugin>

+ 29 - 0
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/SCTLanguageProvider.java

@@ -0,0 +1,29 @@
+package org.yakindu.sct.simulation.core.sexec;
+
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.simulation.core.language.ISCLanguage;
+import org.yakindu.sct.simulation.core.language.ISCLanguageProvider;
+import org.yakindu.sct.simulation.core.language.SimpleSCLanguage;
+
+import com.google.inject.Module;
+
+public class SCTLanguageProvider implements ISCLanguageProvider {
+
+	public static final String SCT_LANGUAGE_ID = "org.yakindu.language.sct";
+
+	@Override
+	public ISCLanguage getLanguage() {
+		return new SimpleSCLanguage(SCT_LANGUAGE_ID, "sct", null);
+	}
+
+	@Override
+	public boolean isInstanceOfLanguage(Statechart sc) {
+		return sc.eResource().getURI().toString().endsWith("sct");
+	}
+
+	@Override
+	public Module getSimulationModule() {
+		return new SimulationModule();
+	}
+
+}

+ 9 - 3
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/launch/SexecLaunchConfigurationDelegate.java

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2011 committers of YAKINDU and others.
+ * Copyright (c) 2011-2013 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
@@ -15,8 +15,9 @@ import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
+import org.yakindu.sct.simulation.core.extensions.SCLanguageProviderExtensions;
+import org.yakindu.sct.simulation.core.language.SCLanguageProviders;
 import org.yakindu.sct.simulation.core.launch.AbstractSCTLaunchConfigurationDelegate;
-import org.yakindu.sct.simulation.core.sexec.SimulationModule;
 import org.yakindu.sct.simulation.core.sexec.container.ISimulationEngineFactory;
 
 import com.google.inject.Binder;
@@ -28,6 +29,7 @@ import com.google.inject.util.Modules;
 /**
  * 
  * @author andreas muelder - Initial contribution and API
+ * @author terfloth - added dynamic module configuration based on statechart language type and language providers
  * 
  */
 public class SexecLaunchConfigurationDelegate extends AbstractSCTLaunchConfigurationDelegate implements
@@ -38,7 +40,11 @@ public class SexecLaunchConfigurationDelegate extends AbstractSCTLaunchConfigura
 
 	@Override
 	protected ISimulationEngine createExecutionContainer(final ILaunch launch, Statechart statechart) {
-		Module module = Modules.override(new SimulationModule()).with(new Module() {
+		
+		SCLanguageProviders providers = SCLanguageProviderExtensions.getLanguageProviders();
+		Module simulationModule = providers.getSimulationModuleFor(statechart); 
+		
+		Module module = Modules.override(simulationModule).with(new Module() {
 			@Override
 			public void configure(Binder binder) {
 				binder.bind(ILaunch.class).toInstance(launch);

+ 4 - 1
plugins/org.yakindu.sct.simulation.core/META-INF/MANIFEST.MF

@@ -15,13 +15,16 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.jdt.debug,
  com.google.guava;bundle-version="10.0.1",
  org.eclipse.emf.workspace;bundle-version="1.5.1",
- org.yakindu.sct.commons;bundle-version="1.0.0"
+ org.yakindu.sct.commons;bundle-version="1.0.0",
+ com.google.inject;bundle-version="3.0.0"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Export-Package: org.yakindu.sct.simulation.core,
  org.yakindu.sct.simulation.core.debugmodel,
  org.yakindu.sct.simulation.core.engine,
+ org.yakindu.sct.simulation.core.extensions,
  org.yakindu.sct.simulation.core.hmr,
+ org.yakindu.sct.simulation.core.language,
  org.yakindu.sct.simulation.core.launch,
  org.yakindu.sct.simulation.core.sruntime,
  org.yakindu.sct.simulation.core.sruntime.impl,

+ 4 - 0
plugins/org.yakindu.sct.simulation.core/plugin.xml

@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
+   <extension-point id="org.yakindu.sct.simulation.core.languageprovider" name="SCLanguageProvider" schema="schema/languageprovider.exsd"/>
+
    <extension point="org.eclipse.emf.ecore.generated_package">
       <!-- @generated sruntime -->
       <package
@@ -8,4 +10,6 @@
             class="org.yakindu.sct.simulation.core.sruntime.SRuntimePackage"
             genModel="model/sruntime.genmodel"/>
    </extension>
+   
+   
 </plugin>

+ 116 - 0
plugins/org.yakindu.sct.simulation.core/schema/languageprovider.exsd

@@ -0,0 +1,116 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.yakindu.sct.simulation.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.yakindu.sct.simulation.core" id="org.yakindu.sct.simulation.core.languageprovider" name="SCLanguageProvider"/>
+      </appinfo>
+      <documentation>
+         This extension point allows the register language providers for specific statechart languages. 
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="SCLanguageProvider"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="SCLanguageProvider">
+      <complexType>
+         <attribute name="class" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.yakindu.sct.simulation.core.language.ISCLanguageProvider"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         2.1.3
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="copyright"/>
+      </appinfo>
+      <documentation>
+         Copyright (c) 2013 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
+      </documentation>
+   </annotation>
+
+</schema>

+ 56 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/extensions/SCLanguageProviderExtensions.java

@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2013 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.core.extensions;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.yakindu.sct.simulation.core.language.ISCLanguageProvider;
+import org.yakindu.sct.simulation.core.language.SCLanguageProviders;
+
+/**
+ * Utility class that handles the languageprovider extension point.
+ * 
+ * @author terfloth - Initial contribution and API
+ * 
+ */
+public class SCLanguageProviderExtensions {
+
+	private static final String EXTENSION_POINT_ID = "org.yakindu.sct.simulation.core.languageprovider";
+	private static final String ATTRIBUTE_CLASS = "class";
+
+	/**
+	 * Creates a new {@link SCLanguageProviders} instance from the registered extensions.
+	 * 
+	 * @return {@link SCLanguageProviders} instance
+	 */
+	public static SCLanguageProviders getLanguageProviders() {
+		SCLanguageProviders providers = new SCLanguageProviders();
+		
+		IConfigurationElement[] configurationElements = Platform
+				.getExtensionRegistry().getConfigurationElementsFor(
+						EXTENSION_POINT_ID);
+
+		for (int i = 0; i < configurationElements.length; i++) {
+			try {
+				ISCLanguageProvider provider = (ISCLanguageProvider) configurationElements[i]
+						.createExecutableExtension(ATTRIBUTE_CLASS);
+				providers.addLanguageProvider(provider);
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+			
+		}
+		
+		return providers;
+	}
+
+}

+ 37 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/ISCLanguage.java

@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2013 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.core.language;
+
+/**
+ * Instances of this interface provide meta information about statechart languages and their dependencies.
+ * 
+ * @author axel terfloth
+ */
+public interface ISCLanguage {
+
+	/** 
+	 * Each statechart language has it's unique id. It is proposed to use fully qualified names.
+	 * 
+	 * @return
+	 */
+	String getId();
+	
+	/**
+	 * A language also has a simple name.
+	 */
+	String gertName();
+	
+	/** 
+	 * A statechart language can inherit from another language.
+	 * @return
+	 */
+	String getBaseLanguageId();
+}

+ 45 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/ISCLanguageProvider.java

@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2013 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.core.language;
+
+import org.yakindu.sct.model.sgraph.Statechart;
+
+import com.google.inject.Module;
+
+/**
+ * Instances provide meta information about statechart languages as well as implementation in form of (guice) modules.
+ * 
+ * Current usage is restricted to simulation modules.
+ * 
+ * @author terfloth
+ *
+ */
+public interface ISCLanguageProvider {
+
+	/** 
+	 * @return  meta information about the language
+	 */
+	ISCLanguage getLanguage();
+	
+	/** 
+	 * Determins if a statechart is instance of the statechart language.
+	 * @param sc
+	 * @return
+	 */
+	boolean isInstanceOfLanguage(Statechart sc);
+	
+	/**
+	 * Provides the guice module that contains the implementation.
+	 * @return a module
+	 */
+	Module getSimulationModule();
+	
+}

+ 72 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/SCLanguageProviders.java

@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2013 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.core.language;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.yakindu.sct.model.sgraph.Statechart;
+
+import com.google.inject.Module;
+import com.google.inject.util.Modules;
+
+/**
+ * Handles a set of language providers and provides language dependencies resolving features.
+ * 
+ * @author terfloth - Initial contribution
+ *
+ */
+public class SCLanguageProviders {
+
+	protected SCLanguages languages = new SCLanguages();
+	protected Map<ISCLanguage, ISCLanguageProvider> providerMap = new HashMap<ISCLanguage, ISCLanguageProvider>();
+	
+	public void addLanguageProvider(ISCLanguageProvider provider) {
+		if (! languages.contains(provider.getLanguage()) ) {
+			languages.addLanguage(provider.getLanguage());
+			providerMap.put(provider.getLanguage(), provider);
+		}
+	}
+	
+	public List<ISCLanguageProvider> getLanguageProviders() {
+		return new ArrayList<ISCLanguageProvider>(providerMap.values());
+	}
+	
+	
+	public ISCLanguageProvider getProviderFor(Statechart sc) {
+		for (Iterator<ISCLanguageProvider> iterator = providerMap.values().iterator(); iterator.hasNext();) {
+			ISCLanguageProvider provider = (ISCLanguageProvider) iterator.next();
+			if (provider.isInstanceOfLanguage(sc)) return provider;	
+		}		
+		return null;
+	}
+	
+	
+	public Module getSimulationModuleFor(Statechart sc){
+		return getSimulationModuleForLanguage(getProviderFor(sc).getLanguage());
+	}
+	
+	
+	public Module getSimulationModuleForLanguage(ISCLanguage language) {
+		ISCLanguageProvider provider = providerMap.get(language);
+		Module module = provider.getSimulationModule();
+		
+		ISCLanguage baseLanguage = languages.getBaseLanguage(language);
+		if (baseLanguage != null) {
+			Module baseModule = getSimulationModuleForLanguage(baseLanguage);
+			return Modules.override(baseModule).with(module);
+		}
+		return module;
+	}
+}

+ 41 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/SCLanguages.java

@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2013 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.core.language;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Handles a set of statechart meta information objects and allows resolving dependencies.
+ * 
+ * @author axel terfloth - Initial contribution
+ *
+ */
+public class SCLanguages {
+
+	protected Map< String, ISCLanguage> languageMap = new HashMap<String, ISCLanguage>();
+	
+	public void addLanguage(ISCLanguage language) {
+		languageMap.put(language.getId(), language);
+	}
+	
+	public boolean contains(ISCLanguage language) {
+		return languageMap.containsKey(language.getId());
+	}
+	
+	public ISCLanguage getLanguage(String id) {
+		return languageMap.get(id);
+	}
+	
+	ISCLanguage getBaseLanguage(ISCLanguage language) {
+		return getLanguage(language.getBaseLanguageId());
+	}
+}

+ 83 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/language/SimpleSCLanguage.java

@@ -0,0 +1,83 @@
+/**
+ * Copyright (c) 2013 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.core.language;
+
+/**
+ * Simple default implementation of the {@link ISCLanguage} interface.
+ * 
+ * @author terfloth
+ *
+ */
+public class SimpleSCLanguage implements ISCLanguage {
+
+	protected String id;
+	protected String name;
+	protected String baseLanguageId;
+	
+	public SimpleSCLanguage(String id, String name, String baseLanguageId) {
+		super();
+		this.id = id;
+		this.name = name;
+		this.baseLanguageId = baseLanguageId;
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public String gertName() {
+		return name;
+	}
+
+	public String getBaseLanguageId() {
+		return baseLanguageId;
+	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result
+				+ ((baseLanguageId == null) ? 0 : baseLanguageId.hashCode());
+		result = prime * result + ((id == null) ? 0 : id.hashCode());
+		result = prime * result + ((name == null) ? 0 : name.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		SimpleSCLanguage other = (SimpleSCLanguage) obj;
+		if (baseLanguageId == null) {
+			if (other.baseLanguageId != null)
+				return false;
+		} else if (!baseLanguageId.equals(other.baseLanguageId))
+			return false;
+		if (id == null) {
+			if (other.id != null)
+				return false;
+		} else if (!id.equals(other.id))
+			return false;
+		if (name == null) {
+			if (other.name != null)
+				return false;
+		} else if (!name.equals(other.name))
+			return false;
+		return true;
+	}
+
+	
+}

+ 2 - 1
plugins/org.yakindu.sct.simulation.ui.sexec/plugin.xml

@@ -23,12 +23,13 @@
    	 </launchConfigurationTabGroup>
 	</extension>
 	
+	
 	<!-- launch shortcuts -->
 	<extension point="org.eclipse.debug.ui.launchShortcuts">
 	    <shortcut
 	        id="org.yakindu.sct.core.simulation.launch.shortcut"
 	        class="org.yakindu.sct.simulation.ui.sexec.launch.StatechartLaunchShortcut"
-	        label="YAKINDU Statechart"
+	        label="Statechart Simulation"
 	        icon="icons/Statechart-Launcher-16.png"
 	        modes="run">
 	         <contextualLaunch>

+ 15 - 0
plugins/org.yakindu.sct.simulation.ui.sexec/src/org/yakindu/sct/simulation/ui/sexec/launch/tabs/StatechartLaunchConfigurationTab.java

@@ -48,6 +48,10 @@ import org.yakindu.sct.simulation.ui.SimulationImages;
  */
 public class StatechartLaunchConfigurationTab extends JavaLaunchTab implements ISCTLaunchParameters {
 
+
+	public static final String LAUNCH_TAB_ID = "org.yakindu.sct.simulation.sexec.launchTab";
+	
+	
 	private Text modelfile;
 	private Text cyclePeriod;
 	private Text operationClass;
@@ -269,6 +273,17 @@ public class StatechartLaunchConfigurationTab extends JavaLaunchTab implements I
 		}
 		return true;
 	}
+	
+	
+	
+
+	@Override
+	public String getId() {
+		return LAUNCH_TAB_ID;
+	}
+
+
+
 
 	private class EnableStateListener implements Listener {
 		public void handleEvent(Event event) {