From: Reino Ruusu Date: Wed, 14 Aug 2019 08:34:15 +0000 (+0300) Subject: Cherry-picked changes to org.simantics.objmap2 from master. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F3219%2F1;p=simantics%2Fplatform.git Cherry-picked changes to org.simantics.objmap2 from master. 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 --- diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java index ac2d9cf1b..55f809f51 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java @@ -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; diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java index 1295c1099..ac860d392 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java @@ -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 &¶meterClasses.length==1) { + return getTypeAnnotations(annotations, fieldClass, parameterClasses); + } + + public static Annotation[] getMethodAnnotations(Method method) + { + Annotation[] annotations = method.getAnnotations().clone(); + ArrayList> list = new ArrayList>(); + 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 &¶meterClasses.length==1) { Annotation[] a2 = new Annotation[annotations.length+1]; System.arraycopy(annotations, 0, a2, 0, annotations.length); diff --git a/bundles/org.simantics.objmap2/META-INF/MANIFEST.MF b/bundles/org.simantics.objmap2/META-INF/MANIFEST.MF index 59ec5b1e7..9038f91c5 100644 --- a/bundles/org.simantics.objmap2/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.objmap2/META-INF/MANIFEST.MF @@ -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 index 000000000..7018a3915 --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedList.java @@ -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 index 000000000..197579f71 --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListAdd.java @@ -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 index 000000000..a4744994b --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListGet.java @@ -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 index 000000000..afc834ea8 --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/LinkedListRem.java @@ -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(); +} diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/UpdateMethod.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/UpdateMethod.java index 1e2ff4f2d..d26b565b9 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/UpdateMethod.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/UpdateMethod.java @@ -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 { } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/CompoundRelatedGetSetValueRuleFactory.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/CompoundRelatedGetSetValueRuleFactory.java index ab5b1c7a9..b98961154 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/CompoundRelatedGetSetValueRuleFactory.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/CompoundRelatedGetSetValueRuleFactory.java @@ -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 implements IGetSetRule // Class adapterClass = getterAnn.adapter(); IRangeAccessor rangeAccessor = new CompoundGetSetValueAccessor(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 implements IGetSetRule // } return new ValueRule(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 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; - } - } } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/DataTypeUtils.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/DataTypeUtils.java index cd745a523..6d3f33a1b 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/DataTypeUtils.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/DataTypeUtils.java @@ -11,12 +11,28 @@ *******************************************************************************/ 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 index 000000000..072a6a2df --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory.java @@ -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 implements IFieldRuleFactory { + + @Override + public IBidirectionalMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException { + LinkedList annotation = (LinkedList)_annotation; + return new MappedElementsRule( + new LinkedListAccessor(g.getResource(annotation.value()), g.getResource(annotation.type()), annotation.composition()), + new FieldAccessor>(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 index 000000000..3ef69d989 --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java @@ -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 implements ICollectionRuleFactory { + + @Override + public IBidirectionalMappingRule create(ReadGraph g, Annotation annotation, + Method getter, Method adder, Method remover) + throws DatabaseException { + LinkedListGet getterAnn = (LinkedListGet)annotation; + return new MappedElementsRule(new LinkedListAccessor(g.getResource(getterAnn.value()), g.getResource(getterAnn.type()), getterAnn.composition()), + new CollectionAccessor(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()); + } + +} diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedGetSetValueRuleFactory.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedGetSetValueRuleFactory.java index 994811fee..5c57a75c3 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedGetSetValueRuleFactory.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedGetSetValueRuleFactory.java @@ -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 implements IGetSetRuleFactory< Class adapterClass = getterAnn.adapter(); IRangeAccessor rangeAccessor = new GetSetValueAccessor(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 implements IGetSetRuleFactory< throw new RuntimeException(e); } } - return new ValueRule(new RelatedValueAccessor(g.getResource(getterAnn.value()), valueType), + return new ValueRule(new RelatedValueAccessor(g.getResource(getterAnn.value()), valueType, valueBinding), rangeAccessor); } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedValueRuleFactory.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedValueRuleFactory.java index ca226c605..adb2f6215 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedValueRuleFactory.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedValueRuleFactory.java @@ -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 implements IFieldRuleFactory adapterClass = annotation.adapter(); IRangeAccessor rangeAccessor = new FieldAccessor(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 implements IFieldRuleFactory(new RelatedValueAccessor(g.getResource(annotation.value()), valueType), rangeAccessor); + return new ValueRule(new RelatedValueAccessor(g.getResource(annotation.value()), valueType, valueBinding), rangeAccessor); } } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/UpdateMethodFactory.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/UpdateMethodFactory.java index 10f64be78..e1de9f20c 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/UpdateMethodFactory.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/UpdateMethodFactory.java @@ -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 implements IMethodRuleFactory { - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + static Logger LOGGER = LoggerFactory.getLogger(UpdateMethodFactory.class); @Override public IBidirectionalMappingRule create(ReadGraph g, @@ -40,7 +41,7 @@ public class UpdateMethodFactory implements IMethodRuleFactory 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) { diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java index f105a2894..c2ecdf1b1 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java @@ -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 implements IMapping { - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + static final Logger LOGGER = LoggerFactory.getLogger(Mapping.class); IMappingSchema schema; @@ -72,7 +73,7 @@ public class Mapping implements IMapping { } private void createDomain(WriteGraph g, Link link) throws MappingException { - LOGGER.info(" createDomain for " + link.rangeElement); + LOGGER.trace(" createDomain for " + link.rangeElement); ILinkType type = schema.linkTypeOfRangeElement(link.rangeElement); Domain domainElement = type.createDomainElement(g, link.rangeElement); link.type = type; @@ -263,11 +264,11 @@ public class Mapping implements IMapping { @Override public synchronized Collection updateDomain(WriteGraph g) throws MappingException { - LOGGER.info("Mapping.updateDomain"); + LOGGER.trace("Mapping.updateDomain"); RangeToDomain map = new RangeToDomain(g); ArrayList updated = new ArrayList(); while(!modifiedRangeLinks.isEmpty()) { - LOGGER.info(" modifiedRangeLinks.size() = " + modifiedRangeLinks.size()); + LOGGER.trace(" modifiedRangeLinks.size() = " + modifiedRangeLinks.size()); Link link = modifiedRangeLinks.remove(modifiedRangeLinks.size()-1); link.rangeModified = false; @@ -279,9 +280,10 @@ public class Mapping implements IMapping { 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 implements IMapping { @Override public synchronized Collection updateRange(ReadGraph g) throws MappingException { - LOGGER.info("Mapping.updateRange"); + LOGGER.trace("Mapping.updateRange"); DomainToRange map = new DomainToRange(g); ArrayList updated = new ArrayList(); while(!modifiedDomainLinks.isEmpty()) { - LOGGER.info(" modifiedDomainLinks.size() = " + modifiedDomainLinks.size()); + LOGGER.trace(" modifiedDomainLinks.size() = " + modifiedDomainLinks.size()); Link link = modifiedDomainLinks.remove(modifiedDomainLinks.size()-1); link.domainModified = false; @@ -357,7 +359,7 @@ public class Mapping implements IMapping { void domainModified(Link 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) { diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementRule.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementRule.java index 3b6fac31d..9761f5555 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementRule.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementRule.java @@ -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 implements IBidirectionalMappingRule { - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + static final Logger LOGGER = LoggerFactory.getLogger(MappedElementRule.class); IDomainAccessor domainAccessor; IRangeAccessor rangeAccessor; @@ -47,7 +45,7 @@ public class MappedElementRule implements IBidirectionalMappingRu public boolean updateDomain(WriteGraph g, IBackwardMapping 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 implements IBidirectionalMappingRu public boolean updateRange(ReadGraph g, IForwardMapping 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); diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementsRule.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementsRule.java index cd295e583..7f3c13a10 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementsRule.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementsRule.java @@ -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 implements IBidirectionalMappingRule { - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + static final Logger LOGGER = LoggerFactory.getLogger(MappedElementsRule.class); IDomainAccessor> domainAccessor; IRangeAccessor> rangeAccessor; @@ -48,7 +49,7 @@ public class MappedElementsRule implements IBidirectionalMappingR public boolean updateDomain(WriteGraph g, IBackwardMapping 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 implements IBidirectionalMappingR public boolean updateRange(ReadGraph g, IForwardMapping map, Domain domainElement, Range rangeElement) throws MappingException { - LOGGER.info(" MappedElementsRule.updateRange"); + LOGGER.trace(" MappedElementsRule.updateRange"); Collection value = domainAccessor.get(g, domainElement); ArrayList mappedValue = new ArrayList(value.size()); for(Domain r : value) diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/ValueRule.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/ValueRule.java index 718bc7c2d..9ba9dba11 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/ValueRule.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/ValueRule.java @@ -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 implements IBidirectionalMappingRule { - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + static Logger LOGGER = LoggerFactory.getLogger(ValueRule.class); IDomainAccessor domainAccessor; IRangeAccessor rangeAccessor; @@ -44,7 +45,7 @@ public class ValueRule implements IBidirectionalMappingRule 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 implements IBidirectionalMappingRule 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); } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/CompoundValueAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/CompoundValueAccessor.java index 78b484303..39df524b2 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/CompoundValueAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/CompoundValueAccessor.java @@ -11,20 +11,22 @@ *******************************************************************************/ 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 { - 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 coll = g.getStatements(element, objRelation); Map map = new HashMap(); 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 values = (Map)v; @@ -81,6 +87,7 @@ public class CompoundValueAccessor implements IDomainAccessor { 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 { } 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 { 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 index 000000000..e9104c3d9 --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/LinkedListAccessor.java @@ -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> { + + 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 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 value) + throws MappingException { + try { + LOGGER.trace(" LinkdedListAccessor.set"); + return MappingUtils.synchronizeList(g, element, relation, listType, new ArrayList(value), deleteExtraObjects); + } catch (DatabaseException e) { + throw new MappingException(e); + } + + } + +} diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java index a0d0d4dac..0bb50ff57 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java @@ -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 objects @@ -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 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 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); + } + } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java index 99253790c..28000a99e 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java @@ -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 { - 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 @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 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) diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectsAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectsAccessor.java index 9653ab370..d2d1db99a 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectsAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectsAccessor.java @@ -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> { - 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 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 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) { diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java index c033751e5..4d7895675 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java @@ -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> { - 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 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 value) throws MappingException { try { - LOGGER.info(" RelatedOrderedSetElementsAccessor.set"); + LOGGER.trace(" RelatedOrderedSetElementsAccessor.set"); return OrderedSetUtils.set(g, element, value); // FIXME Implement deleteExtraObjects } catch (DatabaseException e) { diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedValueAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedValueAccessor.java index d5ad40b77..9aa96d8e8 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedValueAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedValueAccessor.java @@ -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 { - 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 { 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 { 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 { 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 { } } + + 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 { if (o1 instanceof byte[]) Arrays.equals((byte[])o1,(byte[])o2); return o1.equals(o2); - } } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/FieldAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/FieldAccessor.java index 6615e94fb..c5a35613c 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/FieldAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/FieldAccessor.java @@ -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 implements IRangeAccessor { - 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 implements IRangeAccessor { @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 implements IRangeAccessor { try { Object currentValue = field.get(element); - if(LOGGER.isInfoEnabled()) - LOGGER.info(" FieldAccessor.set " + + if(LOGGER.isTraceEnabled()) + LOGGER.trace(" FieldAccessor.set " + field.getName() + " " + currentValue + " -> " + value ); diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java index 046a744cf..9b02d5d50 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java @@ -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; diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DynamicSimpleLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DynamicSimpleLinkType.java index 792813bb1..4f44844db 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DynamicSimpleLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DynamicSimpleLinkType.java @@ -70,8 +70,8 @@ public class DynamicSimpleLinkType extends SimpleLinkType{ 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 extends SimpleLinkType{ 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) { diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/MappingSchemas.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/MappingSchemas.java index 871d46bda..cf2f3bf45 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/MappingSchemas.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/MappingSchemas.java @@ -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 fromAnnotations(ReadGraph g, Class clazz) throws DatabaseException, InstantiationException, IllegalAccessException { - GraphType graphType = clazz.getAnnotation(GraphType.class); - - if (graphType != null) { - ArrayList> rules = new ArrayList>(); - collectRulesFromAnnotations(g, clazz, rules); - - return new SimpleLinkType(g.getResource(graphType.value()), clazz, rules); - } - DynamicGraphType dynamicType = clazz.getAnnotation(DynamicGraphType.class); - if (dynamicType != null) { - ArrayList> rules = new ArrayList>(); - collectRulesFromAnnotations(g, clazz, rules); - - return new DynamicSimpleLinkType(g.getResource(dynamicType.value()), clazz, rules); - } - OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class); - if (orderedSetType != null) { - ArrayList> rules = new ArrayList>(); - collectRulesFromAnnotations(g, clazz, rules); - - return new OrderedSetSimpleLinkType(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> rules) throws DatabaseException, InstantiationException, IllegalAccessException { - Class superclass = clazz.getSuperclass(); - if(superclass != null) - collectRulesFromAnnotations(g, superclass, rules); - + public static SimpleLinkType fromAnnotations(ReadGraph g, Class clazz) throws DatabaseException, InstantiationException, IllegalAccessException { + GraphType graphType = clazz.getAnnotation(GraphType.class); + + if (graphType != null) { + ArrayList> rules = new ArrayList>(); + collectRulesFromAnnotations(g, clazz, rules); + + return new SimpleLinkType(g.getResource(graphType.value()), clazz, rules); + } + DynamicGraphType dynamicType = clazz.getAnnotation(DynamicGraphType.class); + if (dynamicType != null) { + ArrayList> rules = new ArrayList>(); + collectRulesFromAnnotations(g, clazz, rules); + + return new DynamicSimpleLinkType(g.getResource(dynamicType.value()), clazz, rules); + } + OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class); + if (orderedSetType != null) { + ArrayList> rules = new ArrayList>(); + collectRulesFromAnnotations(g, clazz, rules); + + return new OrderedSetSimpleLinkType(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> 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 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 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 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 annotationType = annotation.annotationType(); - - IsGetSetRule tag = - annotationType.getAnnotation(IsGetSetRule.class); - if (tag != null) { - - HasSetter setterAnnType = annotationType.getAnnotation(HasSetter.class); - - Class setterAnn = setterAnnType.value(); - - Method getter = m; - - IGetSetRuleFactory 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 annotationType = annotation.annotationType(); + + IsGetSetRule tag = + annotationType.getAnnotation(IsGetSetRule.class); + if (tag != null) { + + HasSetter setterAnnType = annotationType.getAnnotation(HasSetter.class); + + Class setterAnn = setterAnnType.value(); + + Method getter = m; + + IGetSetRuleFactory 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 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 adderAnn = adderAnnType.value(); - Class removerAnn = removerAnnType.value(); - - Method getter = m; - - ICollectionRuleFactory 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 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 adderAnn = adderAnnType.value(); + Class removerAnn = removerAnnType.value(); + + Method getter = m; + + ICollectionRuleFactory 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 createClassRule(ReadGraph g, Annotation annotation, Class clazz) { - return null; - } - - public static IFieldRuleFactory createFieldRule(ReadGraph g, Annotation annotation, Field field) { - if (annotation.annotationType().equals(RelatedElements.class)) - return new RelatedElementsRuleFactory(); - if (annotation.annotationType().equals(RelatedValue.class)) - return new RelatedValueRuleFactory(); - if (annotation.annotationType().equals(OptionalRelatedElements.class)) - return new OptionalRelatedElementsRuleFactory(); - if (annotation.annotationType().equals(RelatedOrderedSetElements.class)) - return new RelatedOrderedSetElementsRuleFactory(); - return null; - } - - public static IMethodRuleFactory createMethodRule(ReadGraph g, Annotation annotation, Method m) { - if (annotation.annotationType().equals(UpdateMethod.class)) - return new UpdateMethodFactory(); - return null; - } - - public static IGetSetRuleFactory createGetSetRuleFactory(ReadGraph g, Annotation annotation, Method getter) { - if (annotation.annotationType().equals(RelatedGetValue.class)) - return new RelatedGetSetValueRuleFactory(); - if (annotation.annotationType().equals(RelatedGetObj.class)) - return new RelatedGetSetObjRuleFactory(); - if (annotation.annotationType().equals(CompoundRelatedGetValue.class)) - return new CompoundRelatedGetSetValueRuleFactory(); - return null; - } - - public static ICollectionRuleFactory createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) { - if (annotation.annotationType().equals(RelatedElementsGet.class)) - return new RelatedElementsRuleFactory2(); - if (annotation.annotationType().equals(OrderedElementsGet.class)) - return new OrderedElementsRuleFactory(); - return null; - } - - /** + + public static IClassRuleFactory createClassRule(ReadGraph g, Annotation annotation, Class clazz) { + return null; + } + + public static IFieldRuleFactory createFieldRule(ReadGraph g, Annotation annotation, Field field) { + if (annotation.annotationType().equals(RelatedElement.class)) + return new RelatedElementRuleFactory(); + if (annotation.annotationType().equals(RelatedElements.class)) + return new RelatedElementsRuleFactory(); + if (annotation.annotationType().equals(RelatedValue.class)) + return new RelatedValueRuleFactory(); + if (annotation.annotationType().equals(OptionalRelatedElements.class)) + return new OptionalRelatedElementsRuleFactory(); + if (annotation.annotationType().equals(RelatedOrderedSetElements.class)) + return new RelatedOrderedSetElementsRuleFactory(); + if (annotation.annotationType().equals(LinkedList.class)) + return new LinkedListRuleFactory(); + return null; + } + + public static IMethodRuleFactory createMethodRule(ReadGraph g, Annotation annotation, Method m) { + if (annotation.annotationType().equals(UpdateMethod.class)) + return new UpdateMethodFactory(); + return null; + } + + public static IGetSetRuleFactory createGetSetRuleFactory(ReadGraph g, Annotation annotation, Method getter) { + if (annotation.annotationType().equals(RelatedGetValue.class)) + return new RelatedGetSetValueRuleFactory(); + if (annotation.annotationType().equals(RelatedGetObj.class)) + return new RelatedGetSetObjRuleFactory(); + if (annotation.annotationType().equals(CompoundRelatedGetValue.class)) + return new CompoundRelatedGetSetValueRuleFactory(); + return null; + } + + public static ICollectionRuleFactory createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) { + if (annotation.annotationType().equals(RelatedElementsGet.class)) + return new RelatedElementsRuleFactory2(); + if (annotation.annotationType().equals(OrderedElementsGet.class)) + return new OrderedElementsRuleFactory(); + 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 fromAdaptable(ReadGraph g, String type, Class clazz) throws DatabaseException, InstantiationException, IllegalAccessException { - - - return new AdaptedLinkType(g.getResource(type), clazz); - } - - + + public static AdaptedLinkType fromAdaptable(ReadGraph g, String type, Class clazz) throws DatabaseException, InstantiationException, IllegalAccessException { + + + return new AdaptedLinkType(g.getResource(type), clazz); + } + + } diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/OrderedSetSimpleLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/OrderedSetSimpleLinkType.java index bd87c074f..748422df2 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/OrderedSetSimpleLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/OrderedSetSimpleLinkType.java @@ -20,8 +20,8 @@ public class OrderedSetSimpleLinkType extends SimpleLinkType { 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); diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleLinkType.java index fcfb3b012..9ddc43716 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleLinkType.java @@ -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 implements ILinkType { - 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 { 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 implements ILinkType { 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 implements ILinkType { }; public boolean updateDomain(WriteGraph g, IBackwardMapping 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 implements ILinkType { public boolean updateRange(ReadGraph g, IForwardMapping 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); diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/UpdateMethodFactory.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/UpdateMethodFactory.java index a5dc78f91..a2be5fa42 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/UpdateMethodFactory.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/UpdateMethodFactory.java @@ -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 implements IMethodRuleFactory { - static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + static Logger LOGGER = LoggerFactory.getLogger(UpdateMethodFactory.class); @Override public IBidirectionalMappingRule create(ReadGraph g, @@ -40,7 +41,7 @@ public class UpdateMethodFactory implements IMethodRuleFactory 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) { diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectAccessor.java index 295e60e2f..de80a9a95 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectAccessor.java @@ -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 { - 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> { - 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 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 value) throws MappingException { try { - LOGGER.info(" RelatedObjectsAccessor.set"); + LOGGER.trace(" RelatedObjectsAccessor.set"); Resource res = getServiceResource(g, element); if (res == null) return false; diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedOrderedSetElementsAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedOrderedSetElementsAccessor.java index 6c1ed3aa2..35f98994d 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedOrderedSetElementsAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedOrderedSetElementsAccessor.java @@ -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> { - 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 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 value) throws MappingException { try { - LOGGER.info(" RelatedOrderedSetElementsAccessor.set"); + LOGGER.trace(" RelatedOrderedSetElementsAccessor.set"); Resource res = getServiceResource(g, element); if (res == null) return false; diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedValueAccessor.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedValueAccessor.java index 2d3a24230..21a6733a4 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedValueAccessor.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedValueAccessor.java @@ -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 { - 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 { - 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> { - 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 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 value) throws MappingException { try { - LOGGER.info(" RelatedObjectsAccessor.set"); + LOGGER.trace(" RelatedObjectsAccessor.set"); if (!element.isStructural()) return false; diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/AdaptedLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/AdaptedLinkType.java index 4f5508486..203863a6c 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/AdaptedLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/AdaptedLinkType.java @@ -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; diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/SimpleLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/SimpleLinkType.java index 8a7091fd4..77b2ab094 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/SimpleLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/SimpleLinkType.java @@ -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 { - 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 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 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() );