Jelajahi Sumber

fixed datatype conversion for serialized simulation context (#2085)

Andreas Mülder 7 tahun lalu
induk
melakukan
af29fbf030

+ 1 - 1
plugins/org.yakindu.sct.model.sruntime/model/SRuntime.xcore

@@ -1,7 +1,7 @@
 @GenModel(copyrightText="Copyright (c) 2018 committers of YAKINDU and others.\r\nAll rights reserved. This program and the accompanying materials\r\nare made available under the terms of the Eclipse Public License v1.0\r\nwhich accompanies this distribution, and is available at\r\nhttp://www.eclipse.org/legal/epl-v10.html\r\nContributors:\r\ncommitters of YAKINDU - initial API and implementation\r\n",
 	operationReflection="false", prefix="SRuntime", modelDirectory="/org.yakindu.sct.model.sruntime/emf-gen",
 	suppressEMFTypes="true", importerID="org.eclipse.emf.importer.ecore", publicConstructors="true",
-	interfaceNamePattern="")
+	interfaceNamePattern="", dataTypeConverters="true")
 @Ecore(nsURI="http://www.yakindu.org/sct/sruntime/2.0.0")
 package org.yakindu.sct.model.sruntime
 

+ 7 - 0
plugins/org.yakindu.sct.model.sruntime/plugin.xml

@@ -21,5 +21,12 @@
             class="org.yakindu.sct.model.sruntime.SRuntimePackage"
             genModel="model/SRuntime.xcore"/>
    </extension>
+   <extension
+         point="org.eclipse.emf.ecore.factory_override">
+      <factory
+            class="org.yakindu.sct.model.sruntime.SRuntimeFactoryImplOverride"
+            uri="http://www.yakindu.org/sct/sruntime/2.0.0">
+      </factory>
+   </extension>
 
 </plugin>

+ 47 - 0
plugins/org.yakindu.sct.model.sruntime/src/org/yakindu/sct/model/sruntime/SRuntimeFactoryImplOverride.java

@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2018 itemis AG - All rights Reserved
+ * Unauthorized copying of this file, via any medium is strictly prohibited
+ * 
+ * Contributors:
+ * 	Andreas Muelder - itemis AG
+ * 
+ */
+package org.yakindu.sct.model.sruntime;
+
+import org.eclipse.emf.ecore.EDataType;
+import org.yakindu.sct.model.sruntime.impl.SRuntimeFactoryImpl;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class SRuntimeFactoryImplOverride extends SRuntimeFactoryImpl implements SRuntimeFactory {
+
+	@Override
+	public Object createJavaObjectFromString(EDataType eDataType, String initialValue) {
+		int indexOf = initialValue.indexOf(":");
+		String className = initialValue.substring(0, indexOf);
+		String value = initialValue.substring(indexOf + 1);
+		if (Boolean.class.getName().equals(className))
+			return Boolean.parseBoolean(value);
+		if (String.class.getName().equals(className))
+			return value;
+		if (Long.class.getName().equals(className))
+			return Long.parseLong(value);
+		if (Double.class.getName().equals(className))
+			return Double.parseDouble(value);
+		if (Integer.class.getName().equals(className))
+			return Integer.parseInt(value);
+		return super.createFromString(eDataType, initialValue);
+	}
+
+	@Override
+	public String convertJavaObjectToString(EDataType eDataType, Object instanceValue) {
+		StringBuilder builder = new StringBuilder();
+		builder.append(instanceValue.getClass().getName());
+		builder.append(":");
+		builder.append(instanceValue);
+		return builder.toString();
+	}
+}