]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
VariableOrResource SCL type 26/3126/3
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 20 Aug 2019 13:24:48 +0000 (16:24 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 22 Aug 2019 06:03:37 +0000 (06:03 +0000)
gitlab #351

Change-Id: I9106238d1bd2e8e07024a2bd21e0dd371ab8c091

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java [new file with mode: 0644]
bundles/org.simantics.scl.db/scl/Simantics/Variables.scl

diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java
new file mode 100644 (file)
index 0000000..7f0c8a9
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.variable;
+
+import org.simantics.db.Resource;
+
+public class ResourceX implements VariableOrResource {
+    
+    public final Resource value;
+
+    public ResourceX(Resource value) {
+        this.value = value;
+    }
+    
+    @Override
+    public String toString() {
+        return "ResourceX " + value;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if(this == obj)
+            return true;
+        if(obj == null || obj.getClass() != getClass())
+            return false;
+        ResourceX other = (ResourceX)obj;
+        return value == null ? other.value == null : value.equals(other.value);
+    }
+    
+    @Override
+    public int hashCode() {
+        return 31 * (value == null ? 0 : value.hashCode()) + 13532;
+    }
+    
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java
new file mode 100644 (file)
index 0000000..1c35049
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.variable;
+
+import org.simantics.db.Resource;
+
+/**
+ * An interface to match the VariableOrResource SCL data type
+ * which represents either a Resource or a Variable. Allows
+ * defining SCL classes with either of the two as a input.
+ *
+ * @author Antti Villberg
+ * @since 1.40.0
+ */
+public interface VariableOrResource {
+
+    public static VariableOrResource make(Resource value) {
+        return new ResourceX(value);
+    }
+    
+    public static VariableOrResource make(Variable value) {
+        return new VariableX(value);
+    }
+
+    public static VariableOrResource make(Object value) {
+        if(value instanceof Resource)
+            return make((Resource)value);
+        if(value instanceof Variable)
+            return make((Variable)value);
+        throw new IllegalArgumentException("VariableOrResource acccepts only Variable or Resource, got " + value + " with class " + value.getClass().getName());
+    }
+
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java
new file mode 100644 (file)
index 0000000..8286abb
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.variable;
+
+public class VariableX implements VariableOrResource {
+    
+    public final Variable value;
+
+    public VariableX(Variable value) {
+        this.value = value;
+    }
+    
+    @Override
+    public String toString() {
+        return "VariableX " + value;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if(this == obj)
+            return true;
+        if(obj == null || obj.getClass() != getClass())
+            return false;
+        VariableX other = (VariableX)obj;
+        return value == null ? other.value == null : value.equals(other.value);
+    }
+    
+    @Override
+    public int hashCode() {
+        return 31 * (value == null ? 0 : value.hashCode()) + 13532;
+    }
+    
+}
index 436e0a17357f32072ec80c2cea18f8f97d3bb734..47bf1a944cb92cdf824cce774e4fc6b385791f17 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
 include "Simantics/Model"
 include "Simantics/DB"
 import "Simantics/DB" as DB
@@ -437,4 +448,15 @@ importJava "org.simantics.db.layer0.variable.RVI" where
 instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
 instantiateUnder container typeToInstantiate = do
     fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource  
-    fn container typeToInstantiate
\ No newline at end of file
+    fn container typeToInstantiate
+
+@JavaType "org.simantics.db.layer0.variable.VariableOrResource"
+data VariableOrResource =
+    @JavaType "org.simantics.db.layer0.variable.ResourceX"
+    @FieldNames [value]
+    ResourceX Resource
+  | @JavaType "org.simantics.db.layer0.variable.VariableX"
+    @FieldNames [value]
+    VariableX Variable
+    
+    
\ No newline at end of file