]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Cherry-picked changes to org.simantics.objmap2 from master. 19/3219/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 14 Aug 2019 08:34:15 +0000 (11:34 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Fri, 6 Sep 2019 10:31:53 +0000 (13:31 +0300)
Added missing creation of RelatedElementRuleFactory.

Also checks for missing rule factories.

gitlab #341

Change-Id: Ieb9799910c3c32a7c49dfd9be496bb9afbca0ab5

Switch from org.apache.log4j to org.slf4j.

gitlab #342

Change-Id: I764df2ecf1e58a1529c0a4e46653054ff15a2de7

Use type reflection tools from databoard in objmap2.

gitlab #344

Change-Id: I489f462a0f1785bc52a7a7f94ff38f7cec612055

Support for linked lists in objmap2.

gitlab #345

Change-Id: I7107ac75961602e74ed44b2c3d9867aefe7d29d8

Fixed some issues in objmap2

gitlab #346

Change-Id: I37ca3edb171f5c88f9deac5f03ff29ecf8c28518

Fix binding instance for CompoundRelatedGetValue method.

gitlab #344

Change-Id: I899d10258c429e215c7c02f717e34631925ebc01

Use trace level debug messages with ObjMap

gitlab #342

Change-Id: Ice0dc7d7891ee672515ad8bf11ccd50d7c3a5758

41 files changed:
bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java
bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java
bundles/org.simantics.objmap2/META-INF/MANIFEST.MF
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedList.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListAdd.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListGet.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListRem.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/UpdateMethod.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/CompoundRelatedGetSetValueRuleFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/DataTypeUtils.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedGetSetValueRuleFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedValueRuleFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/UpdateMethodFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementRule.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementsRule.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/ValueRule.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/CompoundValueAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/LinkedListAccessor.java [new file with mode: 0644]
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedValueAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/FieldAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DynamicSimpleLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/MappingSchemas.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/OrderedSetSimpleLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/UpdateMethodFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedOrderedSetElementsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedValueAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/StructuralRelatedObjectAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/StructuralRelatedObjectsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/AdaptedLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/SimpleLinkType.java

index ac2d9cf1b7246f6be353c8a15aea887ce3b8d45b..55f809f5138dc2a02bd7b6a57bee7189a7d0101d 100644 (file)
@@ -14,6 +14,7 @@ package org.simantics.databoard.binding.reflection;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -44,6 +45,13 @@ public class BindingRequest {
        return new BindingRequest(fieldClass, annotations);
        }
        
+    public static BindingRequest create( Method method )
+    {
+        Annotation[] annotations = ClassBindingFactory.getMethodAnnotations(method);
+        Class<?> valueClass = method.getReturnType(); 
+        return new BindingRequest(valueClass, annotations);
+    }
+       
        /** Requested class */
     private Class<?> clazz;
     private ClassLoader cl;
index 1295c1099ac0c8731b3be597dd967370e0b52afc..ac860d3923d4661e3ef79a8bddbb88498cf4c94a 100644 (file)
@@ -18,6 +18,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -729,7 +730,23 @@ public class ClassBindingFactory {
        Class<?> fieldClass = list.remove(0);
        Class<?>[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES );
        
-       if (Set.class.isAssignableFrom(fieldClass) && parameterClasses!=null &&parameterClasses.length==1) {
+       return getTypeAnnotations(annotations, fieldClass, parameterClasses);
+    }
+
+    public static Annotation[] getMethodAnnotations(Method method) 
+    {
+        Annotation[] annotations = method.getAnnotations().clone();
+        ArrayList<Class<?>> list = new ArrayList<Class<?>>();
+        getTypes( method.getGenericReturnType(), list );
+        Class<?> valueClass = list.remove(0);
+        Class<?>[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES );
+        
+        return getTypeAnnotations(annotations, valueClass, parameterClasses);
+    }
+
+    private static Annotation[] getTypeAnnotations(Annotation[] annotations, Class<?> fieldClass,
+            Class<?>[] parameterClasses) {
+        if (Set.class.isAssignableFrom(fieldClass) && parameterClasses!=null &&parameterClasses.length==1) {
                Annotation[] a2 = new Annotation[annotations.length+1];
                System.arraycopy(annotations, 0, a2, 0, annotations.length);
                
index 59ec5b1e7f9e2eecf4370d7f678a09e538777a46..9038f91c57a1186dc00afaa30f2c306e5d32d3f2 100644 (file)
@@ -8,9 +8,10 @@ Require-Bundle: org.simantics.db;bundle-version="1.1.0",
  gnu.trove3;bundle-version="3.0.0",
  org.eclipse.core.runtime;bundle-version="3.7.0",
  org.simantics.layer0;bundle-version="1.0.0",
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.db.common;bundle-version="1.1.0",
- org.simantics.structural.ontology;bundle-version="1.1.0"
+ org.simantics.structural.ontology;bundle-version="1.1.0",
+ org.slf4j.api,
+ org.simantics.db.layer0
 Export-Package: org.simantics.objmap.backward,
  org.simantics.objmap.bidirectional,
  org.simantics.objmap.exceptions,
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedList.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedList.java
new file mode 100644 (file)
index 0000000..7018a39
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.objmap.graph.annotations;
+
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.simantics.layer0.Layer0;
+import org.simantics.objmap.graph.annotations.meta.IsFieldRule;
+
+/**
+ * This field is a java.util.List or an array type that represents the contents
+ * of a Layer0.List entity that is the single object of the given relation. 
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@IsFieldRule
+public @interface LinkedList {
+       /**
+        * URI of a relation that has a Layer0.List as its object.
+        */
+       String value();
+       /**
+        * URI of the type of the list resource to create. 
+        */
+       String type() default Layer0.URIs.List;
+       boolean composition() default false;
+}
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListAdd.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListAdd.java
new file mode 100644 (file)
index 0000000..197579f
--- /dev/null
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.objmap.graph.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An add method add(int index, T value) for a linked list mapped to the single object
+ * of a given relation.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface LinkedListAdd {
+       String value();
+}
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListGet.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListGet.java
new file mode 100644 (file)
index 0000000..a474499
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.objmap.graph.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.simantics.layer0.Layer0;
+import org.simantics.objmap.graph.annotations.meta.IsCollectionRule;
+
+/**
+ * A get method that returns the contents of a linked list mapped to the single object of
+ * a given relation.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@IsCollectionRule
+@HasCollectionAdder(LinkedListAdd.class)
+@HasCollectionRemover(LinkedListRem.class)
+public @interface LinkedListGet {
+       String value();
+       String type() default Layer0.URIs.List;
+       boolean composition() default false;
+}
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListRem.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListRem.java
new file mode 100644 (file)
index 0000000..afc834e
--- /dev/null
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.objmap.graph.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Remove method for a list of objects represented by a Layer0.List as the
+ * single object of a given relation.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface LinkedListRem {
+       String value();
+}
index 1e2ff4f2d8c753c5fa11e1291705d376b7395611..d26b565b9c39d1f0a2246dc86797a7472663e784 100644 (file)
@@ -16,7 +16,7 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import org.simantics.objmap.graph.annotations.meta.IsFieldRule;
+import org.simantics.objmap.graph.annotations.meta.IsMethodRule;
 
 
 
@@ -27,6 +27,6 @@ import org.simantics.objmap.graph.annotations.meta.IsFieldRule;
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.METHOD)
-@IsFieldRule
+@IsMethodRule
 public @interface UpdateMethod {
 }
index ab5b1c7a9f5943c5f2e180cd6ab9eaba97a16cb0..b98961154ca4cddec50b5a2ddd8efbcc62a1f17a 100644 (file)
@@ -14,10 +14,12 @@ package org.simantics.objmap.graph.annotations.factories;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 
+import org.simantics.databoard.binding.Binding;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.layer0.Layer0;
+import org.simantics.db.layer0.request.PropertyInfo;
+import org.simantics.db.layer0.request.PropertyInfoRequest;
 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
 import org.simantics.objmap.graph.annotations.CompoundRelatedGetValue;
 import org.simantics.objmap.graph.annotations.CompoundRelatedSetValue;
@@ -43,6 +45,8 @@ public class CompoundRelatedGetSetValueRuleFactory<Range> implements IGetSetRule
                
 //             Class<? extends ValueAdapter> adapterClass = getterAnn.adapter();
                IRangeAccessor<Range,Object> rangeAccessor = new CompoundGetSetValueAccessor<Range,Object>(getter, setter);
+               PropertyInfo propInfo = g.syncRequest(new PropertyInfoRequest(g.getResource(getterAnn.valRelation())));
+               Binding valueBinding = propInfo.defaultBinding;
 //        Resource valueType;
 //        if (adapterClass == IdentityAdapter.class) {
 //            valueType = dataTypeOfClass(g, getter.getReturnType());
@@ -59,7 +63,8 @@ public class CompoundRelatedGetSetValueRuleFactory<Range> implements IGetSetRule
 //        }
                return new ValueRule<Resource,Range>(new CompoundValueAccessor(g.getResource(getterAnn.objRelation()),
                                                                                                                                           g.getResource(getterAnn.objType()),
-                                                                                                                                          g.getResource(getterAnn.valRelation())),
+                                                                                                                                          g.getResource(getterAnn.valRelation()),
+                                                                                                                                          valueBinding),
                                        rangeAccessor);
        }
        
@@ -69,42 +74,5 @@ public class CompoundRelatedGetSetValueRuleFactory<Range> implements IGetSetRule
                CompoundRelatedSetValue setterAnn = (CompoundRelatedSetValue)annotation;
                return getterAnn.objRelation().equals(setterAnn.value());
        }
-       
-       public static Resource dataTypeOfClass(ReadGraph g, Class<?> clazz) {
-        Layer0 b = Layer0.getInstance(g);
-        if(clazz.equals(Double.class) || clazz.equals(double.class))
-            return b.Double;
-        else if(clazz.equals(String.class))
-            return b.String;
-        else if(clazz.equals(Integer.class) || clazz.equals(int.class))
-            return b.Integer;
-        else if(clazz.equals(Float.class) || clazz.equals(float.class))
-            return b.Float;
-        else if(clazz.equals(Boolean.class) || clazz.equals(boolean.class))
-            return b.Boolean;
-        else if(clazz.equals(Long.class) || clazz.equals(long.class))
-            return b.Long;
-        else if(clazz.equals(Byte.class) || clazz.equals(byte.class))
-            return b.Byte;
-        
-        else if(clazz.equals(double[].class))
-            return b.DoubleArray;
-        else if(clazz.equals(int[].class))
-            return b.IntegerArray;
-        else if(clazz.equals(byte[].class))
-            return b.ByteArray;
-        else if(clazz.equals(float[].class))
-            return b.FloatArray;
-        else if(clazz.equals(boolean[].class))
-            return b.BooleanArray;
-        else if(clazz.equals(String[].class))
-            return b.StringArray;
-        else if(clazz.equals(long[].class))
-            return b.LongArray;
-        else {
-               System.out.println("Couldn't find a data type for " + clazz);
-            return null;
-        }
-    }
 
 }
index cd745a5230bd97b0c7bec4631dee01d4d822a61b..6d3f33a1b23e98c1932f1a167b004b3ead6d73c2 100644 (file)
  *******************************************************************************/
 package org.simantics.objmap.graph.annotations.factories;
 
+import org.simantics.databoard.Datatypes;
+import org.simantics.databoard.binding.error.DatatypeConstructionException;
+import org.simantics.databoard.type.ArrayType;
+import org.simantics.databoard.type.BooleanType;
+import org.simantics.databoard.type.ByteType;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.type.DoubleType;
+import org.simantics.databoard.type.FloatType;
+import org.simantics.databoard.type.IntegerType;
+import org.simantics.databoard.type.LongType;
+import org.simantics.databoard.type.OptionalType;
+import org.simantics.databoard.type.StringType;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.layer0.Layer0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DataTypeUtils {
     
+    private static final Logger LOGGER = LoggerFactory.getLogger(DataTypeUtils.class);
+
     public static Resource dataTypeOfClass(ReadGraph g, Class<?> clazz) {
         Layer0 b = Layer0.getInstance(g);
         if(clazz.equals(Double.class) || clazz.equals(double.class))
@@ -49,9 +65,59 @@ public class DataTypeUtils {
         else if(clazz.equals(long[].class))
             return b.LongArray;
         else {
-               System.out.println("Couldn't find a data type for " + clazz);
+            try {
+                Datatype type = Datatypes.getDatatype(clazz);
+                final Resource result = dataTypeOfDatatype(g, type);
+                if (result != null)
+                    return result;
+            } catch (DatatypeConstructionException e) {
+            }
+            
+            LOGGER.error("No literal type found for class {}", clazz);
             return null;
         }
     }
-    
+
+    public static Resource dataTypeOfDatatype(ReadGraph g, Datatype type) {
+        if (type instanceof OptionalType)
+            return dataTypeOfDatatype(g, ((OptionalType) type).getComponentType());
+        
+        Layer0 b = Layer0.getInstance(g);
+        if (type instanceof DoubleType)
+            return b.Double;
+        else if(type instanceof StringType)
+            return b.String;
+        else if(type instanceof IntegerType)
+            return b.Integer;
+        else if(type instanceof FloatType)
+            return b.Float;
+        else if(type instanceof BooleanType)
+            return b.Boolean;
+        else if(type instanceof LongType)
+            return b.Long;
+        else if(type instanceof ByteType)
+            return b.Byte;
+        
+        else if (type instanceof ArrayType) {
+            type = ((ArrayType) type).componentType();
+            
+            if (type instanceof DoubleType)
+                return b.DoubleArray;
+            else if(type instanceof IntegerType)
+                return b.IntegerArray;
+            else if(type instanceof ByteType)
+                return b.ByteArray;
+            else if(type instanceof FloatType)
+                return b.FloatArray;
+            else if(type instanceof BooleanType)
+                return b.BooleanArray;
+            else if(type instanceof StringType)
+                return b.StringArray;
+            else if(type instanceof LongType)
+                return b.LongArray;
+        }
+        
+        LOGGER.error("No literal type found for data type {}", type);
+        return null;
+    }
 }
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory.java
new file mode 100644 (file)
index 0000000..072a6a2
--- /dev/null
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.objmap.graph.annotations.factories;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.exception.ServiceException;
+import org.simantics.db.exception.ValidationException;
+import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
+import org.simantics.objmap.graph.annotations.LinkedList;
+import org.simantics.objmap.graph.rules.MappedElementsRule;
+import org.simantics.objmap.graph.rules.domain.LinkedListAccessor;
+import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;
+import org.simantics.objmap.graph.rules.range.FieldAccessor;
+
+public class LinkedListRuleFactory<Range> implements IFieldRuleFactory<Resource, Range> {
+
+    @Override
+    public IBidirectionalMappingRule<Resource, Range> create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {
+        LinkedList annotation = (LinkedList)_annotation;
+        return new MappedElementsRule<Resource,Range>(
+                new LinkedListAccessor(g.getResource(annotation.value()), g.getResource(annotation.type()), annotation.composition()),
+                new FieldAccessor<Range,Collection<Range>>(field)
+            );
+    }
+
+}
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java
new file mode 100644 (file)
index 0000000..3ef69d9
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.objmap.graph.annotations.factories;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
+import org.simantics.objmap.graph.annotations.LinkedListAdd;
+import org.simantics.objmap.graph.annotations.LinkedListGet;
+import org.simantics.objmap.graph.annotations.LinkedListRem;
+import org.simantics.objmap.graph.rules.MappedElementsRule;
+import org.simantics.objmap.graph.rules.domain.LinkedListAccessor;
+import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
+import org.simantics.objmap.graph.rules.range.CollectionAccessor;
+
+public class LinkedListRuleFactory2<Range> implements ICollectionRuleFactory<Resource,Range> {
+       
+       @Override
+       public IBidirectionalMappingRule<Resource, Range> create(ReadGraph g, Annotation annotation,
+                       Method getter, Method adder, Method remover)
+                       throws DatabaseException {
+               LinkedListGet getterAnn = (LinkedListGet)annotation;
+               return new MappedElementsRule<Resource,Range>(new LinkedListAccessor(g.getResource(getterAnn.value()), g.getResource(getterAnn.type()), getterAnn.composition()),
+                                       new CollectionAccessor<Range,Range>(getter, adder, remover));
+       }
+       
+       @Override
+       public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
+               LinkedListGet getterAnn = (LinkedListGet)getterAnnotation;
+               LinkedListAdd adderAnn = (LinkedListAdd)annotation;
+               return getterAnn.value().equals(adderAnn.value());
+       }
+       
+       @Override
+       public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
+               LinkedListGet getterAnn = (LinkedListGet)getterAnnotation;
+               LinkedListRem adderAnn = (LinkedListRem)annotation;
+               return getterAnn.value().equals(adderAnn.value());
+       }
+
+}
index 994811feef05cc85385ccce8e0d504cad3035b79..5c57a75c3c2d3279281209ffa1dfe786d33a59c9 100644 (file)
@@ -14,6 +14,10 @@ package org.simantics.objmap.graph.annotations.factories;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.reflection.BindingRequest;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
@@ -47,8 +51,14 @@ public class RelatedGetSetValueRuleFactory<Range> implements IGetSetRuleFactory<
                Class<? extends ValueAdapter> adapterClass = getterAnn.adapter();
                 IRangeAccessor<Range,Object> rangeAccessor = new GetSetValueAccessor<Range,Object>(getter, setter);
         Resource valueType;
+        Binding valueBinding = null;
         if (adapterClass == IdentityAdapter.class) {
-            valueType = dataTypeOfClass(g, getter.getReturnType());
+            try {
+                valueBinding = Bindings.getBinding(BindingRequest.create(getter));
+            } catch (BindingConstructionException e) {
+                return null;
+            }
+            valueType = DataTypeUtils.dataTypeOfDatatype(g, valueBinding.type());
         } else {
                try{
                         ValueAdapter adapter = adapterClass.newInstance();
@@ -60,7 +70,7 @@ public class RelatedGetSetValueRuleFactory<Range> implements IGetSetRuleFactory<
                  throw new RuntimeException(e);
              }
         }
-               return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(getterAnn.value()), valueType),
+               return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(getterAnn.value()), valueType, valueBinding),
                                        rangeAccessor);
        }
        
index ca226c60554edc91a625dffa889b492acbd06dc0..adb2f6215e3a76c8d45f76a9122f5feef2ec7ec6 100644 (file)
@@ -14,12 +14,15 @@ package org.simantics.objmap.graph.annotations.factories;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.reflection.BindingRequest;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.ResourceNotFoundException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.exception.ValidationException;
-
 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
 import org.simantics.objmap.graph.annotations.RelatedValue;
 import org.simantics.objmap.graph.rules.ValueRule;
@@ -41,8 +44,14 @@ public class RelatedValueRuleFactory<Range> implements IFieldRuleFactory<Resourc
         Class<? extends ValueAdapter> adapterClass = annotation.adapter();
         IRangeAccessor<Range,Object> rangeAccessor = new FieldAccessor<Range,Object>(field);
         Resource valueType;
+        Binding valueBinding = null;
         if (adapterClass == IdentityAdapter.class) {
-            valueType = DataTypeUtils.dataTypeOfClass(g, field.getType());
+            try {
+                valueBinding = Bindings.getBinding(BindingRequest.create(field));
+                valueType = DataTypeUtils.dataTypeOfDatatype(g, valueBinding.type());
+            } catch (BindingConstructionException e) {
+                return null;
+            }
         } else {
             try {
                 ValueAdapter adapter = adapterClass.newInstance();
@@ -54,7 +63,7 @@ public class RelatedValueRuleFactory<Range> implements IFieldRuleFactory<Resourc
                 throw new RuntimeException(e);
             }
         }
-        return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(annotation.value()), valueType), rangeAccessor);
+        return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(annotation.value()), valueType, valueBinding), rangeAccessor);
     }
 
 }
index 10f64be78d5eef552a2c3a7f7fc69cb41894ceb6..e1de9f20c20c0983a4ea4c2fe15d40c0db872e04 100644 (file)
@@ -14,7 +14,8 @@ package org.simantics.objmap.graph.annotations.factories;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
@@ -26,7 +27,7 @@ import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;
 
 public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Domain, Range> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(UpdateMethodFactory.class);
     
     @Override
     public IBidirectionalMappingRule<Domain, Range> create(ReadGraph g, 
@@ -40,7 +41,7 @@ public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Do
             public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                     Domain domainElement, Range rangeElement)
                     throws MappingException {
-                LOGGER.info("    UpdateMethodFactory.updateRange");      
+                LOGGER.trace("    UpdateMethodFactory.updateRange");      
                 try {
                     return (Boolean)method.invoke(rangeElement, g, domainElement);
                 } catch (Exception e) {
index f105a2894c42866f6ccca0cf6d8650c2dc36b406..c2ecdf1b1679fe7f9fd5bd21ed9a0cef090ea63d 100644 (file)
@@ -21,7 +21,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
@@ -42,7 +43,7 @@ import org.simantics.objmap.graph.schema.IMappingSchema;
  */
 public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
 
-       static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+       static final Logger LOGGER = LoggerFactory.getLogger(Mapping.class);
        
        
        IMappingSchema<Domain, Range> schema;
@@ -72,7 +73,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        }
        
        private void createDomain(WriteGraph g, Link<Domain,Range> link) throws MappingException {
-           LOGGER.info("        createDomain for " + link.rangeElement);
+           LOGGER.trace("        createDomain for " + link.rangeElement);
                ILinkType<Domain,Range> type = schema.linkTypeOfRangeElement(link.rangeElement);
                Domain domainElement = type.createDomainElement(g, link.rangeElement);
                link.type = type;
@@ -263,11 +264,11 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        
        @Override
        public synchronized Collection<Domain> updateDomain(WriteGraph g) throws MappingException {
-           LOGGER.info("Mapping.updateDomain");
+           LOGGER.trace("Mapping.updateDomain");
                RangeToDomain map = new RangeToDomain(g);
                ArrayList<Domain> updated = new ArrayList<Domain>();
                while(!modifiedRangeLinks.isEmpty()) {
-                   LOGGER.info("    modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
+                   LOGGER.trace("    modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
                    
                        Link<Domain,Range> link = modifiedRangeLinks.remove(modifiedRangeLinks.size()-1);
                        link.rangeModified = false;
@@ -279,9 +280,10 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
                        if(link.type == null) {
                                createDomain(g, link);
                        }
-                       
-                       if(link.type.updateDomain(g, map, link.domainElement, link.rangeElement))
-                               updated.add(link.domainElement);
+                       else {
+                               if(link.type.updateDomain(g, map, link.domainElement, link.rangeElement))
+                                       updated.add(link.domainElement);
+                       }
                }       
                if (listensDomain)
                        updateRange(g); //FIXME: without this listening would stop. 
@@ -290,11 +292,11 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        
        @Override
        public synchronized Collection<Range> updateRange(ReadGraph g) throws MappingException {
-           LOGGER.info("Mapping.updateRange");
+           LOGGER.trace("Mapping.updateRange");
                DomainToRange map = new DomainToRange(g);
                ArrayList<Range> updated = new ArrayList<Range>();
                while(!modifiedDomainLinks.isEmpty()) {             
-                   LOGGER.info("    modifiedDomainLinks.size() = " + modifiedDomainLinks.size());
+                   LOGGER.trace("    modifiedDomainLinks.size() = " + modifiedDomainLinks.size());
                    
                        Link<Domain,Range> link = modifiedDomainLinks.remove(modifiedDomainLinks.size()-1);
                        link.domainModified = false;
@@ -357,7 +359,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        void domainModified(Link<Domain,Range> link) {
            if(!link.domainModified) {          
                synchronized(modifiedDomainLinks) {
-                   LOGGER.info("        domainModified for " + link.rangeElement);
+                   LOGGER.trace("        domainModified for " + link.rangeElement);
                 link.domainModified = true;
                 modifiedDomainLinks.add(link);
                 if(modifiedDomainLinks.size() == 1) {
index 3b6fac31d4299f9d75efb5d41a2f2391aa137b75..9761f555568fbc6b3827eaa2d6cd7ee77e9ad884 100644 (file)
@@ -11,7 +11,6 @@
  *******************************************************************************/
 package org.simantics.objmap.graph.rules;
 
-import org.apache.log4j.Logger;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.objmap.backward.IBackwardMapping;
@@ -20,9 +19,8 @@ import org.simantics.objmap.exceptions.MappingException;
 import org.simantics.objmap.forward.IForwardMapping;
 import org.simantics.objmap.graph.rules.domain.IDomainAccessor;
 import org.simantics.objmap.graph.rules.range.IRangeAccessor;
-
-
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A rule that synchronizes collection of elements between
@@ -32,7 +30,7 @@ import org.simantics.objmap.graph.rules.range.IRangeAccessor;
  */
 public class MappedElementRule<Domain, Range> implements IBidirectionalMappingRule<Domain, Range> {
     
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static final Logger LOGGER = LoggerFactory.getLogger(MappedElementRule.class);
     
        IDomainAccessor<Domain,Domain> domainAccessor;
        IRangeAccessor<Range,Range> rangeAccessor;
@@ -47,7 +45,7 @@ public class MappedElementRule<Domain, Range> implements IBidirectionalMappingRu
        public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    MappedElementRule.updateDomain");
+        LOGGER.trace("    MappedElementRule.updateDomain");
            Range value = rangeAccessor.get(rangeElement);
            Domain mappedValue = value == null ? null : map.inverseMap(g, value);//map.inverseGet(value);
                return domainAccessor.set(g, domainElement, mappedValue);
@@ -57,7 +55,7 @@ public class MappedElementRule<Domain, Range> implements IBidirectionalMappingRu
        public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    MappedElementRule.updateRange");   
+        LOGGER.trace("    MappedElementRule.updateRange");   
            Domain value = domainAccessor.get(g, domainElement);
         Range mappedValue = value == null ? null : map.map(g, value);////map.get(value);
         return rangeAccessor.set(rangeElement, mappedValue);
index cd295e583d426b08f5fd9d163bf6b0f9c17b6564..7f3c13a106e956989fc4185353de667adad5f6e1 100644 (file)
@@ -14,7 +14,6 @@ package org.simantics.objmap.graph.rules;
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.apache.log4j.Logger;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.objmap.backward.IBackwardMapping;
@@ -23,6 +22,8 @@ import org.simantics.objmap.exceptions.MappingException;
 import org.simantics.objmap.forward.IForwardMapping;
 import org.simantics.objmap.graph.rules.domain.IDomainAccessor;
 import org.simantics.objmap.graph.rules.range.IRangeAccessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -33,7 +34,7 @@ import org.simantics.objmap.graph.rules.range.IRangeAccessor;
  */
 public class MappedElementsRule<Domain, Range> implements IBidirectionalMappingRule<Domain, Range> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static final Logger LOGGER = LoggerFactory.getLogger(MappedElementsRule.class);
 
     IDomainAccessor<Domain,Collection<Domain>> domainAccessor;
     IRangeAccessor<Range,Collection<Range>> rangeAccessor;
@@ -48,7 +49,7 @@ public class MappedElementsRule<Domain, Range> implements IBidirectionalMappingR
     public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
             Domain domainElement, Range rangeElement)
     throws MappingException {
-        LOGGER.info("    MappedElementsRule.updateDomain");
+        LOGGER.trace("    MappedElementsRule.updateDomain");
         // Snapshot the accessed range value for concurrency safety.
         // NOTE: still assumes that the accessed collection is concurrent or
         // synchronized for toArray to be atomic.
@@ -64,7 +65,7 @@ public class MappedElementsRule<Domain, Range> implements IBidirectionalMappingR
     public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
             Domain domainElement, Range rangeElement)
     throws MappingException {
-        LOGGER.info("    MappedElementsRule.updateRange");
+        LOGGER.trace("    MappedElementsRule.updateRange");
         Collection<Domain> value = domainAccessor.get(g, domainElement);
         ArrayList<Range> mappedValue = new ArrayList<Range>(value.size());
         for(Domain r : value)
index 718bc7c2d780ec46ded879a5416cf37d6051a7a1..9ba9dba11274291b0dadb6664492542bd853951e 100644 (file)
@@ -11,7 +11,8 @@
  *******************************************************************************/
 package org.simantics.objmap.graph.rules;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.objmap.backward.IBackwardMapping;
@@ -29,7 +30,7 @@ import org.simantics.objmap.graph.rules.range.IRangeAccessor;
  */
 public class ValueRule<Domain, Range> implements IBidirectionalMappingRule<Domain, Range> {
     
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(ValueRule.class);
     
        IDomainAccessor<Domain,Object> domainAccessor;
        IRangeAccessor<Range,Object> rangeAccessor;
@@ -44,7 +45,7 @@ public class ValueRule<Domain, Range> implements IBidirectionalMappingRule<Domai
        public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    ValueRule.updateDomain");         
+        LOGGER.trace("    ValueRule.updateDomain");        
                Object value = rangeAccessor.get(rangeElement);
                return domainAccessor.set(g, domainElement, value);
        }
@@ -53,7 +54,7 @@ public class ValueRule<Domain, Range> implements IBidirectionalMappingRule<Domai
        public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    ValueRule.updateRange");
+        LOGGER.trace("    ValueRule.updateRange");
                Object value = domainAccessor.get(g, domainElement);
                return rangeAccessor.set(rangeElement, value);
        }       
index 78b48430310356fd0c4f0561aaefb0736f8f907d..39df524b270943022478f51669f2a6627cbbe03e 100644 (file)
  *******************************************************************************/
 package org.simantics.objmap.graph.rules.domain;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.log4j.Logger;
+import org.simantics.databoard.binding.Binding;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ServiceException;
 import org.simantics.layer0.Layer0;
 import org.simantics.objmap.exceptions.MappingException;
-import org.simantics.objmap.graph.annotations.factories.CompoundRelatedGetSetValueRuleFactory;
+import org.simantics.objmap.graph.annotations.factories.DataTypeUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * 
@@ -32,42 +34,46 @@ import org.simantics.objmap.graph.annotations.factories.CompoundRelatedGetSetVal
  */
 public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static final Logger LOGGER = LoggerFactory.getLogger(CompoundValueAccessor.class);
     
        Resource objRelation;
        Resource objType;
        Resource valRelation;
+       Binding valueBinding;
 
-       public CompoundValueAccessor(Resource objRelation, Resource objType, Resource valRelation) {
+       public CompoundValueAccessor(Resource objRelation, Resource objType, Resource valRelation, Binding valueBinding) {
                this.objRelation = objRelation;
                this.objType = objType;
                this.valRelation = valRelation;
+               this.valueBinding = valueBinding;
        }
 
        @Override
        public Object get(ReadGraph g, Resource element) throws MappingException {
                try {
                        Layer0 l0 = Layer0.getInstance(g);
-                   LOGGER.info("        CompoundValueAccessor.get");
+                   LOGGER.trace("        CompoundValueAccessor.get");
                    Collection<Statement> coll = g.getStatements(element, objRelation);
                    Map<String,Object> map = new HashMap<String, Object>();
                    for (Statement c : coll) {
                        String name = g.getRelatedValue(c.getObject(), l0.HasName);
-                       if (!map.containsKey(name) || !c.isAsserted(element))
-                               map.put(name, g.getRelatedValue(c.getObject(), valRelation));
+                       if (!map.containsKey(name) || !c.isAsserted(element)) {
+                                       final Object value = getValue(g, c.getObject());
+                                       map.put(name, value);
+                               }
                    }
                        return map;
                } catch (DatabaseException e) {
                        throw new MappingException(e);
                }
        }
-       
+
        @Override
        public boolean set(WriteGraph g, Resource element, Object v)
                        throws MappingException {
                try {
                        Layer0 l0 = Layer0.getInstance(g);
-                   LOGGER.info("        CompoundValueAccessor.set");
+                   LOGGER.trace("        CompoundValueAccessor.set");
                    @SuppressWarnings("unchecked")
                    Map<String,Object> values = (Map<String, Object>)v;
                    
@@ -81,6 +87,7 @@ public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
                                valueMap.put(name, g.getRelatedValue(c.getObject(), valRelation));
                        }
                    }
+                   
                    boolean changed = false;
                    for (String key : values.keySet()) {
                        Object value = values.get(key);
@@ -97,34 +104,40 @@ public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
                        }
                        
                        Statement valueStatement = g.getPossibleStatement(stm.getObject(), valRelation);
-                       Resource valueType = CompoundRelatedGetSetValueRuleFactory.dataTypeOfClass(g, value.getClass());
+                       Resource valueType = valueBinding != null ?
+                                       DataTypeUtils.dataTypeOfDatatype(g, valueBinding.type()) :
+                                       DataTypeUtils.dataTypeOfClass(g, value.getClass());
+                                       
                                if(valueStatement == null) {
-                                       
                                        Resource valueResource = g.newResource();
-                                       g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null,  valueType);
+                                       g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null, valueType);
                                        g.claim(stm.getObject(), valRelation, valueResource);
-                                       g.claimValue(valueResource, value);                             
+                                       claimValue(g, valueResource, value);
                                } else {
-                                                                       
-                                       
                                        if (!valueStatement.isAsserted(stm.getObject()))
                                                g.claimValue(valueStatement.getObject(), value);
                                        else {
                                                Resource valueResource = g.newResource();
-                                               g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null,
-                                                               valueType);
+                                               g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null, valueType);
                                                g.claim(stm.getObject(), valRelation, valueResource);
-                                               g.claimValue(valueResource, value);
+                                               claimValue(g, valueResource, value);
                                        }
                                }
                    }
-                   return changed;
                    
+                   return changed;
                } catch (DatabaseException e) {
                        throw new MappingException(e);
                }
                
        }
+
+       private void claimValue(WriteGraph g, Resource valueResource, Object value) throws ServiceException {
+               if (valueBinding != null)
+                       g.claimValue(valueResource, value, valueBinding);
+               else
+                       g.claimValue(valueResource, value);
+       }
        
        private Statement getStatement(ReadGraph g, Resource s, Resource p, Resource o) throws DatabaseException{
                for (Statement stm : g.getStatements(s, p)) {
@@ -134,19 +147,8 @@ public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
                return null;
        }
        
-       private boolean equals(Object o1, Object o2) {
-               if (o1 instanceof boolean[])
-                       Arrays.equals((boolean[])o1,(boolean[])o2);
-               if (o1 instanceof int[])
-                       Arrays.equals((int[])o1,(int[])o2);
-               if (o1 instanceof float[])
-                       Arrays.equals((float[])o1,(float[])o2);
-               if (o1 instanceof double[])
-                       Arrays.equals((double[])o1,(double[])o2);
-               if (o1 instanceof byte[])
-                       Arrays.equals((byte[])o1,(byte[])o2);
-               return o1.equals(o2);
-               
+       private Object getValue(ReadGraph g, final Resource object) throws DatabaseException {
+               return valueBinding != null ? g.getRelatedValue(object, valRelation, valueBinding) : g.getRelatedValue(object, valRelation);
        }
 
 }
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/LinkedListAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/LinkedListAccessor.java
new file mode 100644 (file)
index 0000000..e9104c3
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.objmap.graph.rules.domain;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.ListUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.objmap.exceptions.MappingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Accesses the set of objects attached to the element by the given relation.
+ * @author Hannu Niemistö
+ */
+public class LinkedListAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
+
+       static Logger LOGGER = LoggerFactory.getLogger(LinkedListAccessor.class);
+
+       Resource relation;
+       Resource listType;
+       boolean deleteExtraObjects;
+
+       public LinkedListAccessor(Resource relation, Resource listType, boolean deleteExtraObjects) {
+               super();
+               this.relation = relation;
+               this.listType = listType;
+               this.deleteExtraObjects = deleteExtraObjects;
+       }
+
+       @Override
+       public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
+               try {
+                       LOGGER.trace("        LinkdedListAccessor.get");
+                       return ListUtils.toList(g, g.getPossibleObject(element, relation));
+               } catch (DatabaseException e) {
+                       throw new MappingException(e);
+               }
+       }
+
+       @Override
+       public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
+                       throws MappingException {
+               try {
+                       LOGGER.trace("        LinkdedListAccessor.set");
+                       return MappingUtils.synchronizeList(g, element, relation, listType, new ArrayList<Resource>(value), deleteExtraObjects);
+               } catch (DatabaseException e) {
+                       throw new MappingException(e);
+               }
+
+       }
+
+}
index a0d0d4dac2df176cc881fb9759f4173a911a1db1..0bb50ff5726c270d92e69cb1be1074a71e3030bd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2013 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2013, 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
@@ -8,16 +8,24 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum oy - linked list utilities
  *******************************************************************************/
 package org.simantics.objmap.graph.rules.domain;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.ListUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.exception.NoSingleResultException;
+import org.simantics.db.exception.ServiceException;
+import org.simantics.layer0.Layer0;
 
 /**
  * Static utility methods for rule implementations.
@@ -25,7 +33,7 @@ import org.simantics.db.exception.DatabaseException;
  */
 public class MappingUtils {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static final Logger LOGGER = LoggerFactory.getLogger(MappingUtils.class);
     
     /**
      * Adds and removes statements to/from the database so that <code>objects</code>
@@ -47,7 +55,7 @@ public class MappingUtils {
                while(true) {
                        int cmp = currentObjects[i].compareTo(objects[j]);
                        if(cmp < 0) {
-                           LOGGER.info("            remove statement");
+                           LOGGER.trace("            remove statement");
                            if(deleteExtraObjects)
                                g.deny(currentObjects[i]);
                            else
@@ -58,7 +66,7 @@ public class MappingUtils {
                                        break;
                        }
                        else if(cmp > 0) {
-                           LOGGER.info("            add statement");
+                           LOGGER.trace("            add statement");
                                g.claim(subject, predicate, objects[j]);
                                modified = true;
                                ++j;
@@ -89,4 +97,75 @@ public class MappingUtils {
                return modified;
        }
 
+       public static boolean synchronizeList(WriteGraph g, Resource element, Resource relation, Resource listType, List<Resource> value, boolean deleteExtraObjects) throws DatabaseException {
+               final Layer0 L0 = Layer0.getInstance(g);
+               
+               // Return value
+               boolean modified = false;
+               
+               // Get the list - create a new one, if necessary
+               Resource currentList = g.getPossibleObject(element, relation);
+               if (currentList == null) {
+                       currentList = ListUtils.create(g, listType);
+                       g.claim(element, relation, currentList);
+                       modified = true;
+               }
+
+               // Synchronize elements
+               List<Resource> currentNodes = ListUtils.getListNodes(g, currentList);
+               int i = 0, j = 0;
+               while (i < currentNodes.size()) {
+                       Resource node = currentNodes.get(i);
+                       Resource v = g.getSingleObject(node, L0.List_Element);
+                       if (j < value.size() && v.equals(value.get(j))) {
+                               i++;
+                               j++;
+                       }
+                       else if (value.indexOf(v) > j) {
+                               // Insert new element in the middle
+                               insertElementBefore(g, L0, node, value.get(j));
+                               modified = true;
+                               j++;
+                       }
+                       else {
+                               // Remove deleted element
+                               if (deleteExtraObjects) g.deny(v);
+                               removeNode(g, L0, node);
+                               modified = true;
+                               i++;
+                       }
+               }
+
+               // Add new elements at end
+               while (j < value.size()) {
+                       // Add tailing elements
+                       insertElementBefore(g, L0, currentList, value.get(j));
+                       modified = true;
+                       j++;
+               }
+               
+               return modified;
+       }
+
+       private static Resource insertElementBefore(WriteGraph g, final Layer0 L0, Resource node, final Resource val)
+                       throws NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException {
+               Resource prev = g.getSingleObject(node, L0.List_Previous);
+               g.deny(prev, L0.List_Next, L0.List_Previous, node);
+               
+               Resource newNode = g.newResource();
+               g.claim(newNode, L0.InstanceOf, L0.List_Entry);
+               g.claim(prev, L0.List_Next, L0.List_Previous, newNode);
+               g.claim(newNode, L0.List_Next, L0.List_Previous, node);
+               g.claim(newNode, L0.List_Element, val);
+               return newNode;
+       }
+
+       private static void removeNode(WriteGraph g, final Layer0 L0, Resource node)
+                       throws NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException {
+               Resource prev = g.getSingleObject(node, L0.List_Previous);
+               Resource next = g.getSingleObject(node, L0.List_Next);
+               g.claim(prev, L0.List_Next, L0.List_Previous, next);
+               g.deny(node);
+       }
+
 }
index 99253790cf0e0f0611eadcf06c9f297189882892..28000a99e7412688f7544ac392bbafa8fd868c67 100644 (file)
@@ -11,7 +11,8 @@
  *******************************************************************************/
 package org.simantics.objmap.graph.rules.domain;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -24,7 +25,7 @@ import org.simantics.objmap.exceptions.MappingException;
  */
 public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectAccessor.class);
     
        Resource relation;
        
@@ -35,7 +36,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource>
        @Override
        public Resource get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.get");
+                   LOGGER.trace("        RelatedObjectAccessor.get");
                        return g.getPossibleObject(element, relation);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -46,7 +47,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource>
        public boolean set(WriteGraph g, Resource element, Resource value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.set");
+                   LOGGER.trace("        RelatedObjectAccessor.set");
                    Resource resource = g.getPossibleObject(element, relation);
                        if(resource == null) {
                            if(value == null)
index 9653ab370c28f5dc058b6be7e09edd6074c02743..d2d1db99a7d78e6cc06f1d93483e3523ae376e93 100644 (file)
@@ -13,7 +13,8 @@ package org.simantics.objmap.graph.rules.domain;
 
 import java.util.Collection;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -26,7 +27,7 @@ import org.simantics.objmap.exceptions.MappingException;
  */
 public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectsAccessor.class);
     
        Resource relation;
        boolean deleteExtraObjects;
@@ -40,7 +41,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collecti
     @Override
        public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.get");
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
                        return g.getObjects(element, relation);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -51,7 +52,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collecti
        public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.set");
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
                        return MappingUtils.synchronizeStatements(g, element, relation, 
                                value.toArray(new Resource[value.size()]), deleteExtraObjects);
                } catch (DatabaseException e) {
index c033751e506eb7797e92918257520b8463203d6d..4d78956756a7db91ef392c6cdb1999465f2c4c0b 100644 (file)
@@ -13,7 +13,8 @@ package org.simantics.objmap.graph.rules.domain;
 
 import java.util.Collection;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -27,7 +28,7 @@ import org.simantics.objmap.exceptions.MappingException;
  */
 public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resource, Collection<Resource>> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedOrderedSetElementsAccessor.class);
     
        boolean deleteExtraObjects;
 
@@ -39,7 +40,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resour
     @Override
        public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.get");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.get");
                        return OrderedSetUtils.toList(g, element);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -50,7 +51,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resour
        public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.set");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.set");
                    return OrderedSetUtils.set(g, element, value);
                    // FIXME Implement deleteExtraObjects
                } catch (DatabaseException e) {
index d5ad40b77cd8f82f2369978872c7e967e24aac7d..9aa96d8e89ed64a1379b77d39ec762b2f83ac706 100644 (file)
@@ -13,14 +13,20 @@ package org.simantics.objmap.graph.rules.domain;
 
 import java.util.Arrays;
 
-import org.apache.log4j.Logger;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.OptionalBinding;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.BindingException;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.DoesNotContainValueException;
+import org.simantics.db.exception.ServiceException;
 import org.simantics.layer0.Layer0;
 import org.simantics.objmap.exceptions.MappingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Accesses a value attached to the element by given functional relation.
@@ -28,34 +34,36 @@ import org.simantics.objmap.exceptions.MappingException;
  */
 public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedValueAccessor.class);
     
        Resource relation;
        Resource valueType;
+       Binding valueBinding;
 
-       public RelatedValueAccessor(Resource relation, Resource valueType) {
+       public RelatedValueAccessor(Resource relation, Resource valueType, Binding valueBinding) {
                this.relation = relation;
                this.valueType = valueType;
+               this.valueBinding = valueBinding;
        }
 
        @Override
        public Object get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.get");
+                   LOGGER.trace("        RelatedValueAccessor.get");
                        Resource valueResource = g.getPossibleObject(element, relation);
                        if(valueResource == null)
                                return null;
-                       return g.getValue(valueResource);
+                       return getValue(g, valueResource);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
                }
        }
-       
+
        @Override
        public boolean set(WriteGraph g, Resource element, Object value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.set");
+                   LOGGER.trace("        RelatedValueAccessor.set");
                    Statement valueStatement = g.getPossibleStatement(element, relation);
                        if(valueStatement == null) {
                                if(value == null)
@@ -64,7 +72,8 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
                                g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null,
                                                valueType);
                                g.claim(element, relation, valueResource);
-                               g.claimValue(valueResource, value);                             
+                               claimValue(g, valueResource, value);
+                               
                                return true;
                        }
                        else {
@@ -76,7 +85,7 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
                                                return false;
                                        }
                                }                               
-                               Object currentValue = g.getValue(valueStatement.getObject());
+                               Object currentValue = getValue(g, valueStatement.getObject());
                                if(equals(currentValue,value))
                                        return false;
                                if (!valueStatement.isAsserted(element))
@@ -86,7 +95,7 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
                                        g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null,
                                                        valueType);
                                        g.claim(element, relation, valueResource);
-                                       g.claimValue(valueResource, value);
+                                       claimValue(g, valueResource, value);
                                }
                                return true;
                        }
@@ -95,8 +104,32 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
                }
                
        }
+
+       private Object getValue(ReadGraph g, Resource valueResource)
+                       throws DoesNotContainValueException, BindingException, ServiceException {
+               if (valueBinding != null) {
+                       return g.getValue(valueResource, getBaseBinding(valueBinding));
+               }
+               else {
+                       return g.getValue(valueResource);
+               }
+       }
+       
+       private void claimValue(WriteGraph g, Resource valueResource, Object value) throws ServiceException {
+               if (valueBinding != null)
+                       g.claimValue(valueResource, value, getBaseBinding(valueBinding));
+               else
+                       g.claimValue(valueResource, value);
+       }
+
+       private static Binding getBaseBinding(Binding binding) {
+               return binding instanceof OptionalBinding ? ((OptionalBinding)binding).getComponentBinding() : binding;
+       }
        
        private boolean equals(Object o1, Object o2) {
+               if (valueBinding != null)
+                       return valueBinding.equals(o1, o2);
+               
                if (o1 instanceof boolean[])
                        Arrays.equals((boolean[])o1,(boolean[])o2);
                if (o1 instanceof int[])
@@ -108,7 +141,6 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
                if (o1 instanceof byte[])
                        Arrays.equals((byte[])o1,(byte[])o2);
                return o1.equals(o2);
-               
        }
 
 }
index 6615e94fb41edf507f55e646cbb9b539bca679c0..c5a35613cd07ade3454c45f76b720096ace63d4f 100644 (file)
@@ -13,8 +13,9 @@ package org.simantics.objmap.graph.rules.range;
 
 import java.lang.reflect.Field;
 
-import org.apache.log4j.Logger;
 import org.simantics.objmap.exceptions.MappingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -23,7 +24,7 @@ import org.simantics.objmap.exceptions.MappingException;
  */
 public class FieldAccessor<Range,T> implements IRangeAccessor<Range,T> {
     
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static final Logger LOGGER = LoggerFactory.getLogger(FieldAccessor.class);
     
        Field field;
 
@@ -37,8 +38,8 @@ public class FieldAccessor<Range,T> implements IRangeAccessor<Range,T> {
                    @SuppressWarnings("unchecked")
                        T result = (T)field.get(element);
                    
-               if(LOGGER.isInfoEnabled())
-                   LOGGER.info("        FieldAccessor.get " +
+               if(LOGGER.isTraceEnabled())
+                   LOGGER.trace("        FieldAccessor.get " +
                            field.getName() + " -> " + result
                    );
                
@@ -55,8 +56,8 @@ public class FieldAccessor<Range,T> implements IRangeAccessor<Range,T> {
                try {
                        Object currentValue = field.get(element);
                        
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("        FieldAccessor.set " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("        FieldAccessor.set " +
                         field.getName() + " " + currentValue +  
                         " -> " + value
                 );
index 046a744cf4d332cac824bd03b2429ad959d20fc7..9b02d5d50c9bec9d4bcb77ed9a1277fd6c015267 100644 (file)
@@ -11,7 +11,7 @@
  *******************************************************************************/
 package org.simantics.objmap.graph.schema;
 
-//import org.apache.log4j.Logger;
+//import org.slf4j.Logger;
 import org.eclipse.core.runtime.IAdaptable;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
index 792813bb1020b8a524723dea76ba7bf1f7aac46d..4f44844dbbaa034afbc9d84dcf702c3cb2965ece 100644 (file)
@@ -70,8 +70,8 @@ public class DynamicSimpleLinkType<Range> extends SimpleLinkType<Range>{
             throws MappingException {
         try {
                String typeUri = (String)typeGetter.invoke(rangeElement, (Object[]) null);
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             Resource actualDomainType = g.getResource(typeUri);
@@ -95,9 +95,9 @@ public class DynamicSimpleLinkType<Range> extends SimpleLinkType<Range>{
            public Range createRangeElement(ReadGraph g, Resource domainElement)
                    throws MappingException {
                try {
-                   if(LOGGER.isInfoEnabled())
+                   if(LOGGER.isTraceEnabled())
                        try { 
-                           LOGGER.info("SimpleLinkType.createRangeElement " +
+                           LOGGER.trace("SimpleLinkType.createRangeElement " +
                                        NameUtils.getSafeName(g, domainElement)
                                    );
                        } catch(DatabaseException e) {
index 871d46bdaebce02c458098fa1b690717fc9ed741..cf2f3bf45065c5bee4951da094d67b8e94686767 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Copyright (c) 2012, 2013, 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
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum oy - linked list mapping API and implementation
  *******************************************************************************/
 package org.simantics.objmap.graph.schema;
 
@@ -27,9 +28,12 @@ import org.simantics.objmap.graph.annotations.GraphType;
 import org.simantics.objmap.graph.annotations.HasCollectionAdder;
 import org.simantics.objmap.graph.annotations.HasCollectionRemover;
 import org.simantics.objmap.graph.annotations.HasSetter;
+import org.simantics.objmap.graph.annotations.LinkedListGet;
+import org.simantics.objmap.graph.annotations.LinkedList;
 import org.simantics.objmap.graph.annotations.OptionalRelatedElements;
 import org.simantics.objmap.graph.annotations.OrderedElementsGet;
 import org.simantics.objmap.graph.annotations.OrderedSetType;
+import org.simantics.objmap.graph.annotations.RelatedElement;
 import org.simantics.objmap.graph.annotations.RelatedElements;
 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
 import org.simantics.objmap.graph.annotations.RelatedGetObj;
@@ -38,8 +42,11 @@ import org.simantics.objmap.graph.annotations.RelatedOrderedSetElements;
 import org.simantics.objmap.graph.annotations.RelatedValue;
 import org.simantics.objmap.graph.annotations.UpdateMethod;
 import org.simantics.objmap.graph.annotations.factories.CompoundRelatedGetSetValueRuleFactory;
+import org.simantics.objmap.graph.annotations.factories.LinkedListRuleFactory;
+import org.simantics.objmap.graph.annotations.factories.LinkedListRuleFactory2;
 import org.simantics.objmap.graph.annotations.factories.OptionalRelatedElementsRuleFactory;
 import org.simantics.objmap.graph.annotations.factories.OrderedElementsRuleFactory;
+import org.simantics.objmap.graph.annotations.factories.RelatedElementRuleFactory;
 import org.simantics.objmap.graph.annotations.factories.RelatedElementsRuleFactory;
 import org.simantics.objmap.graph.annotations.factories.RelatedElementsRuleFactory2;
 import org.simantics.objmap.graph.annotations.factories.RelatedGetSetObjRuleFactory;
@@ -57,52 +64,60 @@ import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
 import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;
 import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;
 import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 public class MappingSchemas {
-       /**
+    private static final Logger LOGGER = LoggerFactory.getLogger(MappingSchemas.class);
+
+    /**
      * Creates a new SimpleLinkType based on the annotations in the given class.
      * @throws IllegalAccessException 
      * @throws InstantiationException 
      * @see GraphType
      * @see RelatedValue
      */
-       public static SimpleLinkType<Object> fromAnnotations(ReadGraph g, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
-           GraphType graphType = clazz.getAnnotation(GraphType.class);
-           
-           if (graphType != null) {
-                   ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
-                   collectRulesFromAnnotations(g, clazz, rules);
-                   
-                   return new SimpleLinkType<Object>(g.getResource(graphType.value()), clazz, rules);  
-           }
-           DynamicGraphType dynamicType = clazz.getAnnotation(DynamicGraphType.class);
-           if (dynamicType != null) {
-               ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
-                   collectRulesFromAnnotations(g, clazz, rules);
-                   
-                   return new DynamicSimpleLinkType<Object>(g.getResource(dynamicType.value()), clazz, rules);
-           }
-           OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class);
-           if (orderedSetType != null) {
-               ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
-                   collectRulesFromAnnotations(g, clazz, rules);
-                   
-                   return new OrderedSetSimpleLinkType<Object>(g.getResource(orderedSetType.value()), clazz, rules);
-           }
-           throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations.");
-       }
-       
-       public static void collectRulesFromAnnotations(ReadGraph g, Class<?> clazz, Collection<IBidirectionalMappingRule<Resource, Object>> rules) throws DatabaseException, InstantiationException, IllegalAccessException {
-           Class<?> superclass = clazz.getSuperclass();
-           if(superclass != null)
-               collectRulesFromAnnotations(g, superclass, rules);
-               
+    public static SimpleLinkType<Object> fromAnnotations(ReadGraph g, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
+        GraphType graphType = clazz.getAnnotation(GraphType.class);
+
+        if (graphType != null) {
+            ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
+            collectRulesFromAnnotations(g, clazz, rules);
+
+            return new SimpleLinkType<Object>(g.getResource(graphType.value()), clazz, rules);  
+        }
+        DynamicGraphType dynamicType = clazz.getAnnotation(DynamicGraphType.class);
+        if (dynamicType != null) {
+            ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
+            collectRulesFromAnnotations(g, clazz, rules);
+
+            return new DynamicSimpleLinkType<Object>(g.getResource(dynamicType.value()), clazz, rules);
+        }
+        OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class);
+        if (orderedSetType != null) {
+            ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
+            collectRulesFromAnnotations(g, clazz, rules);
+
+            return new OrderedSetSimpleLinkType<Object>(g.getResource(orderedSetType.value()), clazz, rules);
+        }
+        throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations.");
+    }
+
+    public static void collectRulesFromAnnotations(ReadGraph g, Class<?> clazz, Collection<IBidirectionalMappingRule<Resource, Object>> rules) throws DatabaseException, InstantiationException, IllegalAccessException {
+        Class<?> superclass = clazz.getSuperclass();
+        if(superclass != null)
+            collectRulesFromAnnotations(g, superclass, rules);
+
         for(Annotation annotation : clazz.getAnnotations()) {
 
-               IsClassRule tag = annotation.annotationType().getAnnotation(IsClassRule.class);
+            IsClassRule tag = annotation.annotationType().getAnnotation(IsClassRule.class);
             if(tag!= null) {
-               rules.add(createClassRule(g, annotation, clazz).create(g, annotation, clazz));
+                final IClassRuleFactory<Resource, Object> ruleFactory = createClassRule(g, annotation, clazz);
+                if (ruleFactory != null)
+                    rules.add(ruleFactory.create(g, annotation, clazz));
+                else
+                    LOGGER.warn("No rule factory found for {}", annotation);
             }
         }
 
@@ -111,9 +126,13 @@ public class MappingSchemas {
 
             for(Annotation annotation : f.getAnnotations()) {
 
-               IsFieldRule tag = annotation.annotationType().getAnnotation(IsFieldRule.class);
+                IsFieldRule tag = annotation.annotationType().getAnnotation(IsFieldRule.class);
                 if(tag != null) {
-                    rules.add(createFieldRule(g, annotation, f).create(g, annotation, f));
+                    final IFieldRuleFactory<Resource, Object> ruleFactory = createFieldRule(g, annotation, f);
+                    if (ruleFactory != null)
+                        rules.add(ruleFactory.create(g, annotation, f));
+                    else
+                        LOGGER.warn("No rule factory found for {}", annotation);
                 }
             }
         }
@@ -122,140 +141,154 @@ public class MappingSchemas {
             m.setAccessible(true);
 
             for(Annotation annotation : m.getAnnotations()) {
-               IsMethodRule tag = 
+                IsMethodRule tag = 
                         annotation.annotationType().getAnnotation(IsMethodRule.class);
                 if(tag != null) {
-                       rules.add(createMethodRule(g, annotation, m).create(g, annotation, m));
+                    final IMethodRuleFactory<Resource, Object> ruleFactory = createMethodRule(g, annotation, m);
+                    if (ruleFactory != null)
+                        rules.add(ruleFactory.create(g, annotation, m));
+                    else
+                        LOGGER.warn("No rule factory found for {}", annotation);
                 }
             }
         }
-        
+
         for (Method m : clazz.getDeclaredMethods()) {
-               m.setAccessible(true);
-               for (Annotation annotation : m.getAnnotations()) {
-                       Class<? extends Annotation> annotationType = annotation.annotationType();
-
-                        IsGetSetRule tag = 
-                         annotationType.getAnnotation(IsGetSetRule.class);
-                        if (tag != null) {
-                                
-                                HasSetter setterAnnType = annotationType.getAnnotation(HasSetter.class);
-                                
-                                Class<? extends Annotation> setterAnn = setterAnnType.value();
-                                
-                                Method getter = m;
-                                
-                                IGetSetRuleFactory<Resource,Object> ruleFactory = createGetSetRuleFactory(g, annotation, getter);
-                                
-                                
-                                Method setter = null;
-                                
-                                for (Method m2 : clazz.getDeclaredMethods()) {
-                                        Annotation set = m2.getAnnotation(setterAnn);
-                                        if (set != null && ruleFactory.isSetter(annotation, set))
-                                                setter = m2;
-                                }
-
-                                rules.add(ruleFactory.create(g, annotation, getter, setter));
-                        }
-                
-               }
+            m.setAccessible(true);
+            for (Annotation annotation : m.getAnnotations()) {
+                Class<? extends Annotation> annotationType = annotation.annotationType();
+
+                IsGetSetRule tag = 
+                        annotationType.getAnnotation(IsGetSetRule.class);
+                if (tag != null) {
+
+                    HasSetter setterAnnType = annotationType.getAnnotation(HasSetter.class);
+
+                    Class<? extends Annotation> setterAnn = setterAnnType.value();
+
+                    Method getter = m;
+
+                    IGetSetRuleFactory<Resource,Object> ruleFactory = createGetSetRuleFactory(g, annotation, getter);
+                    if (ruleFactory != null) {
+                        Method setter = null;
+    
+                        for (Method m2 : clazz.getDeclaredMethods()) {
+                            Annotation set = m2.getAnnotation(setterAnn);
+                            if (set != null && ruleFactory.isSetter(annotation, set))
+                                setter = m2;
+                        }
+    
+                        rules.add(ruleFactory.create(g, annotation, getter, setter));
+                    }
+                    else {
+                        LOGGER.warn("No rule factory found for {}", annotation);
+                    }
+                }
+
+            }
         }
-        
+
         for (Method m : clazz.getDeclaredMethods()) {
-               m.setAccessible(true);
-               for (Annotation annotation : m.getAnnotations()) {
-                       Class<? extends Annotation> annotationType = annotation.annotationType();
-
-                        IsCollectionRule tag = 
-                         annotationType.getAnnotation(IsCollectionRule.class);
-                        if (tag != null) {
-                                
-                                HasCollectionAdder adderAnnType = annotationType.getAnnotation(HasCollectionAdder.class);
-                                HasCollectionRemover removerAnnType = annotationType.getAnnotation(HasCollectionRemover.class);
-                
-                                Class<? extends Annotation> adderAnn = adderAnnType.value();
-                                Class<? extends Annotation> removerAnn = removerAnnType.value();
-                                
-                                Method getter = m;
-                                
-                                ICollectionRuleFactory<Resource,Object> ruleFactory = createCollectionRuleFactory(g, annotation, getter);
-                                
-                                
-                                Method adder = null;
-                                Method remover = null;
-                                
-                                for (Method m2 : clazz.getDeclaredMethods()) {
-                                        Annotation add = m2.getAnnotation(adderAnn);
-                                        Annotation rem = m2.getAnnotation(removerAnn);
-                                        if (add != null && ruleFactory.isAdder(annotation, add))
-                                                adder = m2;
-                                        if (rem != null && ruleFactory.isRemover(annotation, rem))
-                                                remover = m2;
-                                }
-                                
-                                
-                                
-                                rules.add(ruleFactory.create(g, annotation, getter,adder,remover));
-                        }
-                
-               }
+            m.setAccessible(true);
+            for (Annotation annotation : m.getAnnotations()) {
+                Class<? extends Annotation> annotationType = annotation.annotationType();
+
+                IsCollectionRule tag = 
+                        annotationType.getAnnotation(IsCollectionRule.class);
+                if (tag != null) {
+
+                    HasCollectionAdder adderAnnType = annotationType.getAnnotation(HasCollectionAdder.class);
+                    HasCollectionRemover removerAnnType = annotationType.getAnnotation(HasCollectionRemover.class);
+
+                    Class<? extends Annotation> adderAnn = adderAnnType.value();
+                    Class<? extends Annotation> removerAnn = removerAnnType.value();
+
+                    Method getter = m;
+
+                    ICollectionRuleFactory<Resource,Object> ruleFactory = createCollectionRuleFactory(g, annotation, getter);
+                    if (ruleFactory != null) {
+                        Method adder = null;
+                        Method remover = null;
+    
+                        for (Method m2 : clazz.getDeclaredMethods()) {
+                            Annotation add = m2.getAnnotation(adderAnn);
+                            Annotation rem = m2.getAnnotation(removerAnn);
+                            if (add != null && ruleFactory.isAdder(annotation, add))
+                                adder = m2;
+                            if (rem != null && ruleFactory.isRemover(annotation, rem))
+                                remover = m2;
+                        }
+    
+                        rules.add(ruleFactory.create(g, annotation, getter,adder,remover));
+                    }
+                    else {
+                        LOGGER.warn("No rule factory found for {}", annotation);
+                    }
+                }
+
+            }
         }
     }
-       
-       public static IClassRuleFactory<Resource, Object> createClassRule(ReadGraph g, Annotation annotation, Class<?> clazz) {
-               return null;
-       }
-       
-       public static IFieldRuleFactory<Resource,Object> createFieldRule(ReadGraph g, Annotation annotation, Field field) {
-               if (annotation.annotationType().equals(RelatedElements.class))
-                       return new RelatedElementsRuleFactory<Object>();
-               if (annotation.annotationType().equals(RelatedValue.class))
-                       return new RelatedValueRuleFactory<Object>();
-               if (annotation.annotationType().equals(OptionalRelatedElements.class))
-                       return new OptionalRelatedElementsRuleFactory<Object>();
-               if (annotation.annotationType().equals(RelatedOrderedSetElements.class))
-                       return new RelatedOrderedSetElementsRuleFactory<Object>();
-               return null;
-       }
-       
-       public static IMethodRuleFactory<Resource, Object> createMethodRule(ReadGraph g, Annotation annotation, Method m) {
-               if (annotation.annotationType().equals(UpdateMethod.class))
-                       return new UpdateMethodFactory<Resource,Object>();
-               return null;
-       }
-       
-       public static IGetSetRuleFactory<Resource,Object> createGetSetRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
-               if (annotation.annotationType().equals(RelatedGetValue.class))
-                       return new RelatedGetSetValueRuleFactory<Object>();
-               if (annotation.annotationType().equals(RelatedGetObj.class))
-                       return new RelatedGetSetObjRuleFactory<Object>();
-               if (annotation.annotationType().equals(CompoundRelatedGetValue.class))
-                       return new CompoundRelatedGetSetValueRuleFactory<Object>();
-               return null;
-       }
-       
-       public static ICollectionRuleFactory<Resource,Object> createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
-               if (annotation.annotationType().equals(RelatedElementsGet.class))
-                       return new RelatedElementsRuleFactory2<Object>();
-               if (annotation.annotationType().equals(OrderedElementsGet.class))
-                       return new OrderedElementsRuleFactory<Object>();
-               return null;
-       }
-       
-       /**
+
+    public static IClassRuleFactory<Resource, Object> createClassRule(ReadGraph g, Annotation annotation, Class<?> clazz) {
+        return null;
+    }
+
+    public static IFieldRuleFactory<Resource,Object> createFieldRule(ReadGraph g, Annotation annotation, Field field) {
+        if (annotation.annotationType().equals(RelatedElement.class))
+            return new RelatedElementRuleFactory<Object>();
+        if (annotation.annotationType().equals(RelatedElements.class))
+            return new RelatedElementsRuleFactory<Object>();
+        if (annotation.annotationType().equals(RelatedValue.class))
+            return new RelatedValueRuleFactory<Object>();
+        if (annotation.annotationType().equals(OptionalRelatedElements.class))
+            return new OptionalRelatedElementsRuleFactory<Object>();
+        if (annotation.annotationType().equals(RelatedOrderedSetElements.class))
+            return new RelatedOrderedSetElementsRuleFactory<Object>();
+        if (annotation.annotationType().equals(LinkedList.class))
+            return new LinkedListRuleFactory<Object>();
+        return null;
+    }
+
+    public static IMethodRuleFactory<Resource, Object> createMethodRule(ReadGraph g, Annotation annotation, Method m) {
+        if (annotation.annotationType().equals(UpdateMethod.class))
+            return new UpdateMethodFactory<Resource,Object>();
+        return null;
+    }
+
+    public static IGetSetRuleFactory<Resource,Object> createGetSetRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
+        if (annotation.annotationType().equals(RelatedGetValue.class))
+            return new RelatedGetSetValueRuleFactory<Object>();
+        if (annotation.annotationType().equals(RelatedGetObj.class))
+            return new RelatedGetSetObjRuleFactory<Object>();
+        if (annotation.annotationType().equals(CompoundRelatedGetValue.class))
+            return new CompoundRelatedGetSetValueRuleFactory<Object>();
+        return null;
+    }
+
+    public static ICollectionRuleFactory<Resource,Object> createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
+        if (annotation.annotationType().equals(RelatedElementsGet.class))
+            return new RelatedElementsRuleFactory2<Object>();
+        if (annotation.annotationType().equals(OrderedElementsGet.class))
+            return new OrderedElementsRuleFactory<Object>();
+        if (annotation.annotationType().equals(LinkedListGet.class))
+            return new LinkedListRuleFactory2<>();
+        return null;
+    }
+
+    /**
      * Creates a new SimpleLinkType based on the annotations in the given class.
      * @throws IllegalAccessException 
      * @throws InstantiationException 
      * @see GraphType
      * @see RelatedValue
      */
-       
-       public static AdaptedLinkType<Object> fromAdaptable(ReadGraph g, String type, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
-           
-           
-           return new AdaptedLinkType<Object>(g.getResource(type), clazz);    
-       }
-       
-       
+
+    public static AdaptedLinkType<Object> fromAdaptable(ReadGraph g, String type, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
+
+
+        return new AdaptedLinkType<Object>(g.getResource(type), clazz);    
+    }
+
+
 }
index bd87c074f0f4ecbe14ecddcce0b05fc4d13369d2..748422df2a5f51deebe85d421c1c4e78fdbe242d 100644 (file)
@@ -20,8 +20,8 @@ public class OrderedSetSimpleLinkType<Range> extends SimpleLinkType<Range> {
        
        public Resource createDomainElement(org.simantics.db.WriteGraph g, Range rangeElement) throws org.simantics.objmap.exceptions.MappingException {
                 try {
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             Resource result = OrderedSetUtils.create(g, domainType);
index fcfb3b012a802439398bc6d020325e9875494f38..9ddc437162e12a32720c5faefa6544ddc7e8a246 100644 (file)
@@ -13,7 +13,8 @@ package org.simantics.objmap.graph.schema;
 
 import java.util.ArrayList;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -34,7 +35,7 @@ import org.simantics.objmap.forward.IForwardMapping;
  */
 public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(SimpleLinkType.class);
     
     public Resource domainType;
     public Class<?> rangeType;
@@ -63,8 +64,8 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     public Resource createDomainElement(WriteGraph g, Range rangeElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             Resource result = g.newResource();
@@ -79,9 +80,9 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     public Range createRangeElement(ReadGraph g, Resource domainElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
+            if(LOGGER.isTraceEnabled())
                 try { 
-                    LOGGER.info("SimpleLinkType.createRangeElement " +
+                    LOGGER.trace("SimpleLinkType.createRangeElement " +
                                NameUtils.getSafeName(g, domainElement)
                             );
                 } catch(DatabaseException e) {
@@ -104,9 +105,9 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     };
     
     public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateDomain " +
+                LOGGER.trace("SimpleLinkType.updateDomain " +
                         NameUtils.getSafeName(g, domainElement) + " " +
                         rangeElement.toString()
                         );
@@ -122,11 +123,11 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     
     public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
     
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateRange " +
+                LOGGER.trace("SimpleLinkType.updateRange " +
                                NameUtils.getSafeName(g, domainElement) + " " +
-                        rangeElement.toString()
+                        (rangeElement.getClass().getName() + "@" + Integer.toHexString(rangeElement.hashCode()))
                         );
             } catch(DatabaseException e) {
                 throw new MappingException(e);
index a5dc78f9120196e76dca9432ad3514f7d0799085..a2be5fa42bf978083642deb38b68807e46dc3329 100644 (file)
@@ -14,7 +14,8 @@ package org.simantics.objmap.structural.annotations.factories;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
@@ -26,7 +27,7 @@ import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;
 
 public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Domain, Range> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(UpdateMethodFactory.class);
     
     @Override
     public IBidirectionalMappingRule<Domain, Range> create(ReadGraph g, 
@@ -40,7 +41,7 @@ public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Do
             public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                     Domain domainElement, Range rangeElement)
                     throws MappingException {
-                LOGGER.info("    UpdateMethodFactory.updateRange");      
+                LOGGER.trace("    UpdateMethodFactory.updateRange");      
                 try {
                     return (Boolean)method.invoke(rangeElement, g, domainElement);
                 } catch (Exception e) {
index 295e60e2f29796eb96ea7ce88a90c2610018efd0..de80a9a95fdacd3ff4af5fb72166fe7e3df91ae4 100644 (file)
@@ -11,7 +11,8 @@
  *******************************************************************************/
 package org.simantics.objmap.structural.rules.domain;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -23,7 +24,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class RelatedObjectAccessor implements IDomainAccessor<StructuralResource,StructuralResource> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectAccessor.class);
     
        Resource relation;
        boolean useTypeResource;
@@ -50,7 +51,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<StructuralResource
        @Override
        public StructuralResource get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.get");
+                   LOGGER.trace("        RelatedObjectAccessor.get");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return null;
@@ -71,7 +72,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<StructuralResource
        public boolean set(WriteGraph g, StructuralResource selement, StructuralResource value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.set");
+                   LOGGER.trace("        RelatedObjectAccessor.set");
                    Resource element = getServiceResource(g, selement);
                    if (element == null)
                        return false;
index cbd4ef3b40c9e5f1fae6b5e0159eb98e3f2e68cd..b09de09b83551a1c9d7427c6e11441d4544b0504 100644 (file)
@@ -16,7 +16,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -29,7 +30,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResource,Collection<StructuralResource>> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectsAccessor.class);
     
        Resource relation;
        boolean deleteExtraObjects;
@@ -57,7 +58,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResourc
     @Override
        public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.get");
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
                        
                   
                    Resource res = getServiceResource(g, element);
@@ -86,7 +87,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResourc
        public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.set");
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return false;
index 6c1ed3aa2777038fbfa958ee7735c7c3441313ac..35f98994d23dd9ccb638fb493939c3b8523bdded 100644 (file)
@@ -16,7 +16,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -28,7 +29,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<StructuralResource, Collection<StructuralResource>> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedOrderedSetElementsAccessor.class);
     
        boolean deleteExtraObjects;
        boolean useTypeResource;
@@ -42,7 +43,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Struct
     @Override
        public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.get");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.get");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return Collections.emptyList();
@@ -61,7 +62,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Struct
        public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.set");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.set");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return false;
index 2d3a24230e88c3b6d0edd51377c75c52f1fc0903..21a6733a4b3e4938def7029fbbafa810ca6b9084 100644 (file)
@@ -13,7 +13,8 @@ package org.simantics.objmap.structural.rules.domain;
 
 import java.util.Arrays;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Statement;
@@ -27,7 +28,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class RelatedValueAccessor implements IDomainAccessor<StructuralResource,Object> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedValueAccessor.class);
     
        Resource relation;
        Resource valueType;
@@ -57,7 +58,7 @@ public class RelatedValueAccessor implements IDomainAccessor<StructuralResource,
        @Override
        public Object get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.get");
+                   LOGGER.trace("        RelatedValueAccessor.get");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return null;
@@ -74,7 +75,7 @@ public class RelatedValueAccessor implements IDomainAccessor<StructuralResource,
        public boolean set(WriteGraph g, StructuralResource relement, Object value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.set");
+                   LOGGER.trace("        RelatedValueAccessor.set");
                    
                    Resource element = getServiceResource(g, relement);
                    if (element == null)
index 32b8fd38ce0125b44b946ea29a75ce7d4c7ef75c..1b088754327511cff225e40ae690ec5c926cdec5 100644 (file)
@@ -14,7 +14,8 @@ package org.simantics.objmap.structural.rules.domain;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -26,7 +27,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class StructuralRelatedObjectAccessor implements IDomainAccessor<StructuralResource,StructuralResource> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(StructuralRelatedObjectAccessor.class);
     
        Resource relation;
        boolean useTypeResource;
@@ -54,7 +55,7 @@ public class StructuralRelatedObjectAccessor implements IDomainAccessor<Structur
        public StructuralResource get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
                        
-                       LOGGER.info("        RelatedObjectAccessor.get");
+                       LOGGER.trace("        RelatedObjectAccessor.get");
                        
                        if (!element.isStructural())
                                return null;
@@ -84,7 +85,7 @@ public class StructuralRelatedObjectAccessor implements IDomainAccessor<Structur
        public boolean set(WriteGraph g, StructuralResource element, StructuralResource value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.set");
+                   LOGGER.trace("        RelatedObjectAccessor.set");
                    Resource instance = StructuralUtils.getContainingInstance(element);
                    Resource publicRelation = null;
                    if (instance == null)
index 730edc2696cec373b64643d8c8e632634073ec4e..aa3fdcad247a9f8e46ae0f9ef28f2bf4502aefab 100644 (file)
@@ -16,7 +16,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -29,7 +30,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class StructuralRelatedObjectsAccessor implements IDomainAccessor<StructuralResource,Collection<StructuralResource>> {
 
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(StructuralRelatedObjectsAccessor.class);
     
        Resource relation;
        boolean deleteExtraObjects;
@@ -43,7 +44,7 @@ public class StructuralRelatedObjectsAccessor implements IDomainAccessor<Structu
     @Override
        public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.get");
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
                        
                    if (!element.isStructural())
                        return Collections.emptyList();
@@ -78,7 +79,7 @@ public class StructuralRelatedObjectsAccessor implements IDomainAccessor<Structu
        public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.set");
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
                    
                    if (!element.isStructural())
                        return false;
index 4f55084861ef9413a548a9a6181b1ec9608893de..203863a6c74c61606d26e71d9c9dabf5964d675f 100644 (file)
@@ -11,7 +11,7 @@
  *******************************************************************************/
 package org.simantics.objmap.structural.schema;
 
-//import org.apache.log4j.Logger;
+//import org.slf4j.Logger;
 import org.eclipse.core.runtime.IAdaptable;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
index 8a7091fd46e828ff2774df30265d7ff719bee8e4..77b2ab094a50b6baf05c6853b3b10a7da6d91242 100644 (file)
@@ -15,7 +15,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -34,7 +35,7 @@ import org.simantics.objmap.structural.StructuralResource;
 
 public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralObject> {
     
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    static Logger LOGGER = LoggerFactory.getLogger(SimpleLinkType.class);
     
     public Resource domainType;
     public Class<?> rangeType;
@@ -63,8 +64,8 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     public StructuralResource createDomainElement(WriteGraph g, IStructuralObject rangeElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             if (rangeElement.getContext().size() == 0) {
@@ -97,9 +98,9 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     public IStructuralObject createRangeElement(ReadGraph g, StructuralResource domainElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
+            if(LOGGER.isTraceEnabled())
                 try { 
-                    LOGGER.info("SimpleLinkType.createRangeElement " + NameUtils.getSafeName(g, domainElement.getResource()));
+                    LOGGER.trace("SimpleLinkType.createRangeElement " + NameUtils.getSafeName(g, domainElement.getResource()));
                 } catch(DatabaseException e) {
                     throw new MappingException(e);
                 }
@@ -154,9 +155,9 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     }
     
     public boolean updateDomain(WriteGraph g, IBackwardMapping<StructuralResource,IStructuralObject> map, StructuralResource domainElement, IStructuralObject rangeElement) throws MappingException {
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateDomain " +
+                LOGGER.trace("SimpleLinkType.updateDomain " +
                         NameUtils.getSafeName(g, domainElement.getResource()) + " " +
                         rangeElement.toString()
                         );
@@ -172,9 +173,9 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     
     public boolean updateRange(ReadGraph g, IForwardMapping<StructuralResource, IStructuralObject> map, StructuralResource domainElement, IStructuralObject rangeElement) throws MappingException {
     
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateRange " +
+                LOGGER.trace("SimpleLinkType.updateRange " +
                                NameUtils.getSafeName(g, domainElement.getResource()) + " " +
                         rangeElement.toString()
                         );