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
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;
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;
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;
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<Class<?>> list = new ArrayList<Class<?>>();
+ getTypes( method.getGenericReturnType(), list );
+ Class<?> valueClass = list.remove(0);
+ Class<?>[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES );
+
+ return getTypeAnnotations(annotations, valueClass, parameterClasses);
+ }
+
+ private static Annotation[] getTypeAnnotations(Annotation[] annotations, Class<?> fieldClass,
+ Class<?>[] parameterClasses) {
+ if (Set.class.isAssignableFrom(fieldClass) && parameterClasses!=null &¶meterClasses.length==1) {
Annotation[] a2 = new Annotation[annotations.length+1];
System.arraycopy(annotations, 0, a2, 0, annotations.length);
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,
--- /dev/null
+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;
+}
--- /dev/null
+/*******************************************************************************
+ * 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();
+}
--- /dev/null
+/*******************************************************************************
+ * 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;
+}
--- /dev/null
+/*******************************************************************************
+ * 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();
+}
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;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
-@IsFieldRule
+@IsMethodRule
public @interface UpdateMethod {
}
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;
// Class<? extends ValueAdapter> adapterClass = getterAnn.adapter();
IRangeAccessor<Range,Object> rangeAccessor = new CompoundGetSetValueAccessor<Range,Object>(getter, setter);
+ PropertyInfo propInfo = g.syncRequest(new PropertyInfoRequest(g.getResource(getterAnn.valRelation())));
+ Binding valueBinding = propInfo.defaultBinding;
// Resource valueType;
// if (adapterClass == IdentityAdapter.class) {
// valueType = dataTypeOfClass(g, getter.getReturnType());
// }
return new ValueRule<Resource,Range>(new CompoundValueAccessor(g.getResource(getterAnn.objRelation()),
g.getResource(getterAnn.objType()),
- g.getResource(getterAnn.valRelation())),
+ g.getResource(getterAnn.valRelation()),
+ valueBinding),
rangeAccessor);
}
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;
- }
- }
}
*******************************************************************************/
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))
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;
+ }
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.objmap.graph.annotations.factories;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.exception.ServiceException;
+import org.simantics.db.exception.ValidationException;
+import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
+import org.simantics.objmap.graph.annotations.LinkedList;
+import org.simantics.objmap.graph.rules.MappedElementsRule;
+import org.simantics.objmap.graph.rules.domain.LinkedListAccessor;
+import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;
+import org.simantics.objmap.graph.rules.range.FieldAccessor;
+
+public class LinkedListRuleFactory<Range> implements IFieldRuleFactory<Resource, Range> {
+
+ @Override
+ public IBidirectionalMappingRule<Resource, Range> create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {
+ LinkedList annotation = (LinkedList)_annotation;
+ return new MappedElementsRule<Resource,Range>(
+ new LinkedListAccessor(g.getResource(annotation.value()), g.getResource(annotation.type()), annotation.composition()),
+ new FieldAccessor<Range,Collection<Range>>(field)
+ );
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.objmap.graph.annotations.factories;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
+import org.simantics.objmap.graph.annotations.LinkedListAdd;
+import org.simantics.objmap.graph.annotations.LinkedListGet;
+import org.simantics.objmap.graph.annotations.LinkedListRem;
+import org.simantics.objmap.graph.rules.MappedElementsRule;
+import org.simantics.objmap.graph.rules.domain.LinkedListAccessor;
+import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
+import org.simantics.objmap.graph.rules.range.CollectionAccessor;
+
+public class LinkedListRuleFactory2<Range> implements ICollectionRuleFactory<Resource,Range> {
+
+ @Override
+ public IBidirectionalMappingRule<Resource, Range> create(ReadGraph g, Annotation annotation,
+ Method getter, Method adder, Method remover)
+ throws DatabaseException {
+ LinkedListGet getterAnn = (LinkedListGet)annotation;
+ return new MappedElementsRule<Resource,Range>(new LinkedListAccessor(g.getResource(getterAnn.value()), g.getResource(getterAnn.type()), getterAnn.composition()),
+ new CollectionAccessor<Range,Range>(getter, adder, remover));
+ }
+
+ @Override
+ public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
+ LinkedListGet getterAnn = (LinkedListGet)getterAnnotation;
+ LinkedListAdd adderAnn = (LinkedListAdd)annotation;
+ return getterAnn.value().equals(adderAnn.value());
+ }
+
+ @Override
+ public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
+ LinkedListGet getterAnn = (LinkedListGet)getterAnnotation;
+ LinkedListRem adderAnn = (LinkedListRem)annotation;
+ return getterAnn.value().equals(adderAnn.value());
+ }
+
+}
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;
Class<? extends ValueAdapter> adapterClass = getterAnn.adapter();
IRangeAccessor<Range,Object> rangeAccessor = new GetSetValueAccessor<Range,Object>(getter, setter);
Resource valueType;
+ Binding valueBinding = null;
if (adapterClass == IdentityAdapter.class) {
- valueType = dataTypeOfClass(g, getter.getReturnType());
+ try {
+ valueBinding = Bindings.getBinding(BindingRequest.create(getter));
+ } catch (BindingConstructionException e) {
+ return null;
+ }
+ valueType = DataTypeUtils.dataTypeOfDatatype(g, valueBinding.type());
} else {
try{
ValueAdapter adapter = adapterClass.newInstance();
throw new RuntimeException(e);
}
}
- return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(getterAnn.value()), valueType),
+ return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(getterAnn.value()), valueType, valueBinding),
rangeAccessor);
}
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;
Class<? extends ValueAdapter> adapterClass = annotation.adapter();
IRangeAccessor<Range,Object> rangeAccessor = new FieldAccessor<Range,Object>(field);
Resource valueType;
+ Binding valueBinding = null;
if (adapterClass == IdentityAdapter.class) {
- valueType = DataTypeUtils.dataTypeOfClass(g, field.getType());
+ try {
+ valueBinding = Bindings.getBinding(BindingRequest.create(field));
+ valueType = DataTypeUtils.dataTypeOfDatatype(g, valueBinding.type());
+ } catch (BindingConstructionException e) {
+ return null;
+ }
} else {
try {
ValueAdapter adapter = adapterClass.newInstance();
throw new RuntimeException(e);
}
}
- return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(annotation.value()), valueType), rangeAccessor);
+ return new ValueRule<Resource,Range>(new RelatedValueAccessor(g.getResource(annotation.value()), valueType, valueBinding), rangeAccessor);
}
}
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;
public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Domain, Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(UpdateMethodFactory.class);
@Override
public IBidirectionalMappingRule<Domain, Range> create(ReadGraph g,
public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" UpdateMethodFactory.updateRange");
+ LOGGER.trace(" UpdateMethodFactory.updateRange");
try {
return (Boolean)method.invoke(rangeElement, g, domainElement);
} catch (Exception e) {
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;
*/
public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static final Logger LOGGER = LoggerFactory.getLogger(Mapping.class);
IMappingSchema<Domain, Range> schema;
}
private void createDomain(WriteGraph g, Link<Domain,Range> link) throws MappingException {
- LOGGER.info(" createDomain for " + link.rangeElement);
+ LOGGER.trace(" createDomain for " + link.rangeElement);
ILinkType<Domain,Range> type = schema.linkTypeOfRangeElement(link.rangeElement);
Domain domainElement = type.createDomainElement(g, link.rangeElement);
link.type = type;
@Override
public synchronized Collection<Domain> updateDomain(WriteGraph g) throws MappingException {
- LOGGER.info("Mapping.updateDomain");
+ LOGGER.trace("Mapping.updateDomain");
RangeToDomain map = new RangeToDomain(g);
ArrayList<Domain> updated = new ArrayList<Domain>();
while(!modifiedRangeLinks.isEmpty()) {
- LOGGER.info(" modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
+ LOGGER.trace(" modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
Link<Domain,Range> link = modifiedRangeLinks.remove(modifiedRangeLinks.size()-1);
link.rangeModified = false;
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.
@Override
public synchronized Collection<Range> updateRange(ReadGraph g) throws MappingException {
- LOGGER.info("Mapping.updateRange");
+ LOGGER.trace("Mapping.updateRange");
DomainToRange map = new DomainToRange(g);
ArrayList<Range> updated = new ArrayList<Range>();
while(!modifiedDomainLinks.isEmpty()) {
- LOGGER.info(" modifiedDomainLinks.size() = " + modifiedDomainLinks.size());
+ LOGGER.trace(" modifiedDomainLinks.size() = " + modifiedDomainLinks.size());
Link<Domain,Range> link = modifiedDomainLinks.remove(modifiedDomainLinks.size()-1);
link.domainModified = false;
void domainModified(Link<Domain,Range> link) {
if(!link.domainModified) {
synchronized(modifiedDomainLinks) {
- LOGGER.info(" domainModified for " + link.rangeElement);
+ LOGGER.trace(" domainModified for " + link.rangeElement);
link.domainModified = true;
modifiedDomainLinks.add(link);
if(modifiedDomainLinks.size() == 1) {
*******************************************************************************/
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;
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
*/
public class MappedElementRule<Domain, Range> implements IBidirectionalMappingRule<Domain, Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static final Logger LOGGER = LoggerFactory.getLogger(MappedElementRule.class);
IDomainAccessor<Domain,Domain> domainAccessor;
IRangeAccessor<Range,Range> rangeAccessor;
public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" MappedElementRule.updateDomain");
+ LOGGER.trace(" MappedElementRule.updateDomain");
Range value = rangeAccessor.get(rangeElement);
Domain mappedValue = value == null ? null : map.inverseMap(g, value);//map.inverseGet(value);
return domainAccessor.set(g, domainElement, mappedValue);
public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" MappedElementRule.updateRange");
+ LOGGER.trace(" MappedElementRule.updateRange");
Domain value = domainAccessor.get(g, domainElement);
Range mappedValue = value == null ? null : map.map(g, value);////map.get(value);
return rangeAccessor.set(rangeElement, mappedValue);
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;
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;
/**
*/
public class MappedElementsRule<Domain, Range> implements IBidirectionalMappingRule<Domain, Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static final Logger LOGGER = LoggerFactory.getLogger(MappedElementsRule.class);
IDomainAccessor<Domain,Collection<Domain>> domainAccessor;
IRangeAccessor<Range,Collection<Range>> rangeAccessor;
public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" MappedElementsRule.updateDomain");
+ LOGGER.trace(" MappedElementsRule.updateDomain");
// Snapshot the accessed range value for concurrency safety.
// NOTE: still assumes that the accessed collection is concurrent or
// synchronized for toArray to be atomic.
public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" MappedElementsRule.updateRange");
+ LOGGER.trace(" MappedElementsRule.updateRange");
Collection<Domain> value = domainAccessor.get(g, domainElement);
ArrayList<Range> mappedValue = new ArrayList<Range>(value.size());
for(Domain r : value)
*******************************************************************************/
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;
*/
public class ValueRule<Domain, Range> implements IBidirectionalMappingRule<Domain, Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(ValueRule.class);
IDomainAccessor<Domain,Object> domainAccessor;
IRangeAccessor<Range,Object> rangeAccessor;
public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" ValueRule.updateDomain");
+ LOGGER.trace(" ValueRule.updateDomain");
Object value = rangeAccessor.get(rangeElement);
return domainAccessor.set(g, domainElement, value);
}
public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" ValueRule.updateRange");
+ LOGGER.trace(" ValueRule.updateRange");
Object value = domainAccessor.get(g, domainElement);
return rangeAccessor.set(rangeElement, value);
}
*******************************************************************************/
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;
/**
*
*/
public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static final Logger LOGGER = LoggerFactory.getLogger(CompoundValueAccessor.class);
Resource objRelation;
Resource objType;
Resource valRelation;
+ Binding valueBinding;
- public CompoundValueAccessor(Resource objRelation, Resource objType, Resource valRelation) {
+ public CompoundValueAccessor(Resource objRelation, Resource objType, Resource valRelation, Binding valueBinding) {
this.objRelation = objRelation;
this.objType = objType;
this.valRelation = valRelation;
+ this.valueBinding = valueBinding;
}
@Override
public Object get(ReadGraph g, Resource element) throws MappingException {
try {
Layer0 l0 = Layer0.getInstance(g);
- LOGGER.info(" CompoundValueAccessor.get");
+ LOGGER.trace(" CompoundValueAccessor.get");
Collection<Statement> coll = g.getStatements(element, objRelation);
Map<String,Object> map = new HashMap<String, Object>();
for (Statement c : coll) {
String name = g.getRelatedValue(c.getObject(), l0.HasName);
- if (!map.containsKey(name) || !c.isAsserted(element))
- map.put(name, g.getRelatedValue(c.getObject(), valRelation));
+ if (!map.containsKey(name) || !c.isAsserted(element)) {
+ final Object value = getValue(g, c.getObject());
+ map.put(name, value);
+ }
}
return map;
} catch (DatabaseException e) {
throw new MappingException(e);
}
}
-
+
@Override
public boolean set(WriteGraph g, Resource element, Object v)
throws MappingException {
try {
Layer0 l0 = Layer0.getInstance(g);
- LOGGER.info(" CompoundValueAccessor.set");
+ LOGGER.trace(" CompoundValueAccessor.set");
@SuppressWarnings("unchecked")
Map<String,Object> values = (Map<String, Object>)v;
valueMap.put(name, g.getRelatedValue(c.getObject(), valRelation));
}
}
+
boolean changed = false;
for (String key : values.keySet()) {
Object value = values.get(key);
}
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)) {
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);
}
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.objmap.graph.rules.domain;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.ListUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.objmap.exceptions.MappingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Accesses the set of objects attached to the element by the given relation.
+ * @author Hannu Niemistö
+ */
+public class LinkedListAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
+
+ static Logger LOGGER = LoggerFactory.getLogger(LinkedListAccessor.class);
+
+ Resource relation;
+ Resource listType;
+ boolean deleteExtraObjects;
+
+ public LinkedListAccessor(Resource relation, Resource listType, boolean deleteExtraObjects) {
+ super();
+ this.relation = relation;
+ this.listType = listType;
+ this.deleteExtraObjects = deleteExtraObjects;
+ }
+
+ @Override
+ public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
+ try {
+ LOGGER.trace(" LinkdedListAccessor.get");
+ return ListUtils.toList(g, g.getPossibleObject(element, relation));
+ } catch (DatabaseException e) {
+ throw new MappingException(e);
+ }
+ }
+
+ @Override
+ public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
+ throws MappingException {
+ try {
+ LOGGER.trace(" LinkdedListAccessor.set");
+ return MappingUtils.synchronizeList(g, element, relation, listType, new ArrayList<Resource>(value), deleteExtraObjects);
+ } catch (DatabaseException e) {
+ throw new MappingException(e);
+ }
+
+ }
+
+}
/*******************************************************************************
- * 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
*
* 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.
*/
public class MappingUtils {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static final Logger LOGGER = LoggerFactory.getLogger(MappingUtils.class);
/**
* Adds and removes statements to/from the database so that <code>objects</code>
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
break;
}
else if(cmp > 0) {
- LOGGER.info(" add statement");
+ LOGGER.trace(" add statement");
g.claim(subject, predicate, objects[j]);
modified = true;
++j;
return modified;
}
+ public static boolean synchronizeList(WriteGraph g, Resource element, Resource relation, Resource listType, List<Resource> value, boolean deleteExtraObjects) throws DatabaseException {
+ final Layer0 L0 = Layer0.getInstance(g);
+
+ // Return value
+ boolean modified = false;
+
+ // Get the list - create a new one, if necessary
+ Resource currentList = g.getPossibleObject(element, relation);
+ if (currentList == null) {
+ currentList = ListUtils.create(g, listType);
+ g.claim(element, relation, currentList);
+ modified = true;
+ }
+
+ // Synchronize elements
+ List<Resource> currentNodes = ListUtils.getListNodes(g, currentList);
+ int i = 0, j = 0;
+ while (i < currentNodes.size()) {
+ Resource node = currentNodes.get(i);
+ Resource v = g.getSingleObject(node, L0.List_Element);
+ if (j < value.size() && v.equals(value.get(j))) {
+ i++;
+ j++;
+ }
+ else if (value.indexOf(v) > j) {
+ // Insert new element in the middle
+ insertElementBefore(g, L0, node, value.get(j));
+ modified = true;
+ j++;
+ }
+ else {
+ // Remove deleted element
+ if (deleteExtraObjects) g.deny(v);
+ removeNode(g, L0, node);
+ modified = true;
+ i++;
+ }
+ }
+
+ // Add new elements at end
+ while (j < value.size()) {
+ // Add tailing elements
+ insertElementBefore(g, L0, currentList, value.get(j));
+ modified = true;
+ j++;
+ }
+
+ return modified;
+ }
+
+ private static Resource insertElementBefore(WriteGraph g, final Layer0 L0, Resource node, final Resource val)
+ throws NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException {
+ Resource prev = g.getSingleObject(node, L0.List_Previous);
+ g.deny(prev, L0.List_Next, L0.List_Previous, node);
+
+ Resource newNode = g.newResource();
+ g.claim(newNode, L0.InstanceOf, L0.List_Entry);
+ g.claim(prev, L0.List_Next, L0.List_Previous, newNode);
+ g.claim(newNode, L0.List_Next, L0.List_Previous, node);
+ g.claim(newNode, L0.List_Element, val);
+ return newNode;
+ }
+
+ private static void removeNode(WriteGraph g, final Layer0 L0, Resource node)
+ throws NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException {
+ Resource prev = g.getSingleObject(node, L0.List_Previous);
+ Resource next = g.getSingleObject(node, L0.List_Next);
+ g.claim(prev, L0.List_Next, L0.List_Previous, next);
+ g.deny(node);
+ }
+
}
*******************************************************************************/
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;
*/
public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectAccessor.class);
Resource relation;
@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);
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)
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;
*/
public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectsAccessor.class);
Resource relation;
boolean deleteExtraObjects;
@Override
public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
try {
- LOGGER.info(" RelatedObjectsAccessor.get");
+ LOGGER.trace(" RelatedObjectsAccessor.get");
return g.getObjects(element, relation);
} catch (DatabaseException e) {
throw new MappingException(e);
public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
throws MappingException {
try {
- LOGGER.info(" RelatedObjectsAccessor.set");
+ LOGGER.trace(" RelatedObjectsAccessor.set");
return MappingUtils.synchronizeStatements(g, element, relation,
value.toArray(new Resource[value.size()]), deleteExtraObjects);
} catch (DatabaseException e) {
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;
*/
public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resource, Collection<Resource>> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedOrderedSetElementsAccessor.class);
boolean deleteExtraObjects;
@Override
public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
try {
- LOGGER.info(" RelatedOrderedSetElementsAccessor.get");
+ LOGGER.trace(" RelatedOrderedSetElementsAccessor.get");
return OrderedSetUtils.toList(g, element);
} catch (DatabaseException e) {
throw new MappingException(e);
public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
throws MappingException {
try {
- LOGGER.info(" RelatedOrderedSetElementsAccessor.set");
+ LOGGER.trace(" RelatedOrderedSetElementsAccessor.set");
return OrderedSetUtils.set(g, element, value);
// FIXME Implement deleteExtraObjects
} catch (DatabaseException e) {
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.
*/
public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedValueAccessor.class);
Resource relation;
Resource valueType;
+ Binding valueBinding;
- public RelatedValueAccessor(Resource relation, Resource valueType) {
+ public RelatedValueAccessor(Resource relation, Resource valueType, Binding valueBinding) {
this.relation = relation;
this.valueType = valueType;
+ this.valueBinding = valueBinding;
}
@Override
public Object get(ReadGraph g, Resource element) throws MappingException {
try {
- LOGGER.info(" RelatedValueAccessor.get");
+ LOGGER.trace(" RelatedValueAccessor.get");
Resource valueResource = g.getPossibleObject(element, relation);
if(valueResource == null)
return null;
- return g.getValue(valueResource);
+ return getValue(g, valueResource);
} catch (DatabaseException e) {
throw new MappingException(e);
}
}
-
+
@Override
public boolean set(WriteGraph g, Resource element, Object value)
throws MappingException {
try {
- LOGGER.info(" RelatedValueAccessor.set");
+ LOGGER.trace(" RelatedValueAccessor.set");
Statement valueStatement = g.getPossibleStatement(element, relation);
if(valueStatement == null) {
if(value == null)
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 {
return false;
}
}
- Object currentValue = g.getValue(valueStatement.getObject());
+ Object currentValue = getValue(g, valueStatement.getObject());
if(equals(currentValue,value))
return false;
if (!valueStatement.isAsserted(element))
g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null,
valueType);
g.claim(element, relation, valueResource);
- g.claimValue(valueResource, value);
+ claimValue(g, valueResource, value);
}
return true;
}
}
}
+
+ 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[])
if (o1 instanceof byte[])
Arrays.equals((byte[])o1,(byte[])o2);
return o1.equals(o2);
-
}
}
import java.lang.reflect.Field;
-import org.apache.log4j.Logger;
import org.simantics.objmap.exceptions.MappingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*/
public class FieldAccessor<Range,T> implements IRangeAccessor<Range,T> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static final Logger LOGGER = LoggerFactory.getLogger(FieldAccessor.class);
Field field;
@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
);
try {
Object currentValue = field.get(element);
- if(LOGGER.isInfoEnabled())
- LOGGER.info(" FieldAccessor.set " +
+ if(LOGGER.isTraceEnabled())
+ LOGGER.trace(" FieldAccessor.set " +
field.getName() + " " + currentValue +
" -> " + value
);
*******************************************************************************/
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;
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);
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) {
/*******************************************************************************
- * 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
*
* 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;
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;
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;
import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;
import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;
import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class MappingSchemas {
- /**
+ private static final Logger LOGGER = LoggerFactory.getLogger(MappingSchemas.class);
+
+ /**
* Creates a new SimpleLinkType based on the annotations in the given class.
* @throws IllegalAccessException
* @throws InstantiationException
* @see GraphType
* @see RelatedValue
*/
- public static SimpleLinkType<Object> fromAnnotations(ReadGraph g, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
- GraphType graphType = clazz.getAnnotation(GraphType.class);
-
- if (graphType != null) {
- ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
- collectRulesFromAnnotations(g, clazz, rules);
-
- return new SimpleLinkType<Object>(g.getResource(graphType.value()), clazz, rules);
- }
- DynamicGraphType dynamicType = clazz.getAnnotation(DynamicGraphType.class);
- if (dynamicType != null) {
- ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
- collectRulesFromAnnotations(g, clazz, rules);
-
- return new DynamicSimpleLinkType<Object>(g.getResource(dynamicType.value()), clazz, rules);
- }
- OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class);
- if (orderedSetType != null) {
- ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
- collectRulesFromAnnotations(g, clazz, rules);
-
- return new OrderedSetSimpleLinkType<Object>(g.getResource(orderedSetType.value()), clazz, rules);
- }
- throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations.");
- }
-
- public static void collectRulesFromAnnotations(ReadGraph g, Class<?> clazz, Collection<IBidirectionalMappingRule<Resource, Object>> rules) throws DatabaseException, InstantiationException, IllegalAccessException {
- Class<?> superclass = clazz.getSuperclass();
- if(superclass != null)
- collectRulesFromAnnotations(g, superclass, rules);
-
+ public static SimpleLinkType<Object> fromAnnotations(ReadGraph g, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
+ GraphType graphType = clazz.getAnnotation(GraphType.class);
+
+ if (graphType != null) {
+ ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
+ collectRulesFromAnnotations(g, clazz, rules);
+
+ return new SimpleLinkType<Object>(g.getResource(graphType.value()), clazz, rules);
+ }
+ DynamicGraphType dynamicType = clazz.getAnnotation(DynamicGraphType.class);
+ if (dynamicType != null) {
+ ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
+ collectRulesFromAnnotations(g, clazz, rules);
+
+ return new DynamicSimpleLinkType<Object>(g.getResource(dynamicType.value()), clazz, rules);
+ }
+ OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class);
+ if (orderedSetType != null) {
+ ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();
+ collectRulesFromAnnotations(g, clazz, rules);
+
+ return new OrderedSetSimpleLinkType<Object>(g.getResource(orderedSetType.value()), clazz, rules);
+ }
+ throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations.");
+ }
+
+ public static void collectRulesFromAnnotations(ReadGraph g, Class<?> clazz, Collection<IBidirectionalMappingRule<Resource, Object>> rules) throws DatabaseException, InstantiationException, IllegalAccessException {
+ Class<?> superclass = clazz.getSuperclass();
+ if(superclass != null)
+ collectRulesFromAnnotations(g, superclass, rules);
+
for(Annotation annotation : clazz.getAnnotations()) {
- IsClassRule tag = annotation.annotationType().getAnnotation(IsClassRule.class);
+ IsClassRule tag = annotation.annotationType().getAnnotation(IsClassRule.class);
if(tag!= null) {
- rules.add(createClassRule(g, annotation, clazz).create(g, annotation, clazz));
+ final IClassRuleFactory<Resource, Object> ruleFactory = createClassRule(g, annotation, clazz);
+ if (ruleFactory != null)
+ rules.add(ruleFactory.create(g, annotation, clazz));
+ else
+ LOGGER.warn("No rule factory found for {}", annotation);
}
}
for(Annotation annotation : f.getAnnotations()) {
- IsFieldRule tag = annotation.annotationType().getAnnotation(IsFieldRule.class);
+ IsFieldRule tag = annotation.annotationType().getAnnotation(IsFieldRule.class);
if(tag != null) {
- rules.add(createFieldRule(g, annotation, f).create(g, annotation, f));
+ final IFieldRuleFactory<Resource, Object> ruleFactory = createFieldRule(g, annotation, f);
+ if (ruleFactory != null)
+ rules.add(ruleFactory.create(g, annotation, f));
+ else
+ LOGGER.warn("No rule factory found for {}", annotation);
}
}
}
m.setAccessible(true);
for(Annotation annotation : m.getAnnotations()) {
- IsMethodRule tag =
+ IsMethodRule tag =
annotation.annotationType().getAnnotation(IsMethodRule.class);
if(tag != null) {
- rules.add(createMethodRule(g, annotation, m).create(g, annotation, m));
+ final IMethodRuleFactory<Resource, Object> ruleFactory = createMethodRule(g, annotation, m);
+ if (ruleFactory != null)
+ rules.add(ruleFactory.create(g, annotation, m));
+ else
+ LOGGER.warn("No rule factory found for {}", annotation);
}
}
}
-
+
for (Method m : clazz.getDeclaredMethods()) {
- m.setAccessible(true);
- for (Annotation annotation : m.getAnnotations()) {
- Class<? extends Annotation> annotationType = annotation.annotationType();
-
- IsGetSetRule tag =
- annotationType.getAnnotation(IsGetSetRule.class);
- if (tag != null) {
-
- HasSetter setterAnnType = annotationType.getAnnotation(HasSetter.class);
-
- Class<? extends Annotation> setterAnn = setterAnnType.value();
-
- Method getter = m;
-
- IGetSetRuleFactory<Resource,Object> ruleFactory = createGetSetRuleFactory(g, annotation, getter);
-
-
- Method setter = null;
-
- for (Method m2 : clazz.getDeclaredMethods()) {
- Annotation set = m2.getAnnotation(setterAnn);
- if (set != null && ruleFactory.isSetter(annotation, set))
- setter = m2;
- }
-
- rules.add(ruleFactory.create(g, annotation, getter, setter));
- }
-
- }
+ m.setAccessible(true);
+ for (Annotation annotation : m.getAnnotations()) {
+ Class<? extends Annotation> annotationType = annotation.annotationType();
+
+ IsGetSetRule tag =
+ annotationType.getAnnotation(IsGetSetRule.class);
+ if (tag != null) {
+
+ HasSetter setterAnnType = annotationType.getAnnotation(HasSetter.class);
+
+ Class<? extends Annotation> setterAnn = setterAnnType.value();
+
+ Method getter = m;
+
+ IGetSetRuleFactory<Resource,Object> ruleFactory = createGetSetRuleFactory(g, annotation, getter);
+ if (ruleFactory != null) {
+ Method setter = null;
+
+ for (Method m2 : clazz.getDeclaredMethods()) {
+ Annotation set = m2.getAnnotation(setterAnn);
+ if (set != null && ruleFactory.isSetter(annotation, set))
+ setter = m2;
+ }
+
+ rules.add(ruleFactory.create(g, annotation, getter, setter));
+ }
+ else {
+ LOGGER.warn("No rule factory found for {}", annotation);
+ }
+ }
+
+ }
}
-
+
for (Method m : clazz.getDeclaredMethods()) {
- m.setAccessible(true);
- for (Annotation annotation : m.getAnnotations()) {
- Class<? extends Annotation> annotationType = annotation.annotationType();
-
- IsCollectionRule tag =
- annotationType.getAnnotation(IsCollectionRule.class);
- if (tag != null) {
-
- HasCollectionAdder adderAnnType = annotationType.getAnnotation(HasCollectionAdder.class);
- HasCollectionRemover removerAnnType = annotationType.getAnnotation(HasCollectionRemover.class);
-
- Class<? extends Annotation> adderAnn = adderAnnType.value();
- Class<? extends Annotation> removerAnn = removerAnnType.value();
-
- Method getter = m;
-
- ICollectionRuleFactory<Resource,Object> ruleFactory = createCollectionRuleFactory(g, annotation, getter);
-
-
- Method adder = null;
- Method remover = null;
-
- for (Method m2 : clazz.getDeclaredMethods()) {
- Annotation add = m2.getAnnotation(adderAnn);
- Annotation rem = m2.getAnnotation(removerAnn);
- if (add != null && ruleFactory.isAdder(annotation, add))
- adder = m2;
- if (rem != null && ruleFactory.isRemover(annotation, rem))
- remover = m2;
- }
-
-
-
- rules.add(ruleFactory.create(g, annotation, getter,adder,remover));
- }
-
- }
+ m.setAccessible(true);
+ for (Annotation annotation : m.getAnnotations()) {
+ Class<? extends Annotation> annotationType = annotation.annotationType();
+
+ IsCollectionRule tag =
+ annotationType.getAnnotation(IsCollectionRule.class);
+ if (tag != null) {
+
+ HasCollectionAdder adderAnnType = annotationType.getAnnotation(HasCollectionAdder.class);
+ HasCollectionRemover removerAnnType = annotationType.getAnnotation(HasCollectionRemover.class);
+
+ Class<? extends Annotation> adderAnn = adderAnnType.value();
+ Class<? extends Annotation> removerAnn = removerAnnType.value();
+
+ Method getter = m;
+
+ ICollectionRuleFactory<Resource,Object> ruleFactory = createCollectionRuleFactory(g, annotation, getter);
+ if (ruleFactory != null) {
+ Method adder = null;
+ Method remover = null;
+
+ for (Method m2 : clazz.getDeclaredMethods()) {
+ Annotation add = m2.getAnnotation(adderAnn);
+ Annotation rem = m2.getAnnotation(removerAnn);
+ if (add != null && ruleFactory.isAdder(annotation, add))
+ adder = m2;
+ if (rem != null && ruleFactory.isRemover(annotation, rem))
+ remover = m2;
+ }
+
+ rules.add(ruleFactory.create(g, annotation, getter,adder,remover));
+ }
+ else {
+ LOGGER.warn("No rule factory found for {}", annotation);
+ }
+ }
+
+ }
}
}
-
- public static IClassRuleFactory<Resource, Object> createClassRule(ReadGraph g, Annotation annotation, Class<?> clazz) {
- return null;
- }
-
- public static IFieldRuleFactory<Resource,Object> createFieldRule(ReadGraph g, Annotation annotation, Field field) {
- if (annotation.annotationType().equals(RelatedElements.class))
- return new RelatedElementsRuleFactory<Object>();
- if (annotation.annotationType().equals(RelatedValue.class))
- return new RelatedValueRuleFactory<Object>();
- if (annotation.annotationType().equals(OptionalRelatedElements.class))
- return new OptionalRelatedElementsRuleFactory<Object>();
- if (annotation.annotationType().equals(RelatedOrderedSetElements.class))
- return new RelatedOrderedSetElementsRuleFactory<Object>();
- return null;
- }
-
- public static IMethodRuleFactory<Resource, Object> createMethodRule(ReadGraph g, Annotation annotation, Method m) {
- if (annotation.annotationType().equals(UpdateMethod.class))
- return new UpdateMethodFactory<Resource,Object>();
- return null;
- }
-
- public static IGetSetRuleFactory<Resource,Object> createGetSetRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
- if (annotation.annotationType().equals(RelatedGetValue.class))
- return new RelatedGetSetValueRuleFactory<Object>();
- if (annotation.annotationType().equals(RelatedGetObj.class))
- return new RelatedGetSetObjRuleFactory<Object>();
- if (annotation.annotationType().equals(CompoundRelatedGetValue.class))
- return new CompoundRelatedGetSetValueRuleFactory<Object>();
- return null;
- }
-
- public static ICollectionRuleFactory<Resource,Object> createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
- if (annotation.annotationType().equals(RelatedElementsGet.class))
- return new RelatedElementsRuleFactory2<Object>();
- if (annotation.annotationType().equals(OrderedElementsGet.class))
- return new OrderedElementsRuleFactory<Object>();
- return null;
- }
-
- /**
+
+ public static IClassRuleFactory<Resource, Object> createClassRule(ReadGraph g, Annotation annotation, Class<?> clazz) {
+ return null;
+ }
+
+ public static IFieldRuleFactory<Resource,Object> createFieldRule(ReadGraph g, Annotation annotation, Field field) {
+ if (annotation.annotationType().equals(RelatedElement.class))
+ return new RelatedElementRuleFactory<Object>();
+ if (annotation.annotationType().equals(RelatedElements.class))
+ return new RelatedElementsRuleFactory<Object>();
+ if (annotation.annotationType().equals(RelatedValue.class))
+ return new RelatedValueRuleFactory<Object>();
+ if (annotation.annotationType().equals(OptionalRelatedElements.class))
+ return new OptionalRelatedElementsRuleFactory<Object>();
+ if (annotation.annotationType().equals(RelatedOrderedSetElements.class))
+ return new RelatedOrderedSetElementsRuleFactory<Object>();
+ if (annotation.annotationType().equals(LinkedList.class))
+ return new LinkedListRuleFactory<Object>();
+ return null;
+ }
+
+ public static IMethodRuleFactory<Resource, Object> createMethodRule(ReadGraph g, Annotation annotation, Method m) {
+ if (annotation.annotationType().equals(UpdateMethod.class))
+ return new UpdateMethodFactory<Resource,Object>();
+ return null;
+ }
+
+ public static IGetSetRuleFactory<Resource,Object> createGetSetRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
+ if (annotation.annotationType().equals(RelatedGetValue.class))
+ return new RelatedGetSetValueRuleFactory<Object>();
+ if (annotation.annotationType().equals(RelatedGetObj.class))
+ return new RelatedGetSetObjRuleFactory<Object>();
+ if (annotation.annotationType().equals(CompoundRelatedGetValue.class))
+ return new CompoundRelatedGetSetValueRuleFactory<Object>();
+ return null;
+ }
+
+ public static ICollectionRuleFactory<Resource,Object> createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) {
+ if (annotation.annotationType().equals(RelatedElementsGet.class))
+ return new RelatedElementsRuleFactory2<Object>();
+ if (annotation.annotationType().equals(OrderedElementsGet.class))
+ return new OrderedElementsRuleFactory<Object>();
+ if (annotation.annotationType().equals(LinkedListGet.class))
+ return new LinkedListRuleFactory2<>();
+ return null;
+ }
+
+ /**
* Creates a new SimpleLinkType based on the annotations in the given class.
* @throws IllegalAccessException
* @throws InstantiationException
* @see GraphType
* @see RelatedValue
*/
-
- public static AdaptedLinkType<Object> fromAdaptable(ReadGraph g, String type, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
-
-
- return new AdaptedLinkType<Object>(g.getResource(type), clazz);
- }
-
-
+
+ public static AdaptedLinkType<Object> fromAdaptable(ReadGraph g, String type, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {
+
+
+ return new AdaptedLinkType<Object>(g.getResource(type), clazz);
+ }
+
+
}
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);
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;
*/
public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(SimpleLinkType.class);
public Resource domainType;
public Class<?> rangeType;
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();
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) {
};
public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
- if(LOGGER.isInfoEnabled())
+ if(LOGGER.isTraceEnabled())
try {
- LOGGER.info("SimpleLinkType.updateDomain " +
+ LOGGER.trace("SimpleLinkType.updateDomain " +
NameUtils.getSafeName(g, domainElement) + " " +
rangeElement.toString()
);
public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
- if(LOGGER.isInfoEnabled())
+ if(LOGGER.isTraceEnabled())
try {
- LOGGER.info("SimpleLinkType.updateRange " +
+ LOGGER.trace("SimpleLinkType.updateRange " +
NameUtils.getSafeName(g, domainElement) + " " +
- rangeElement.toString()
+ (rangeElement.getClass().getName() + "@" + Integer.toHexString(rangeElement.hashCode()))
);
} catch(DatabaseException e) {
throw new MappingException(e);
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;
public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Domain, Range> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(UpdateMethodFactory.class);
@Override
public IBidirectionalMappingRule<Domain, Range> create(ReadGraph g,
public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
Domain domainElement, Range rangeElement)
throws MappingException {
- LOGGER.info(" UpdateMethodFactory.updateRange");
+ LOGGER.trace(" UpdateMethodFactory.updateRange");
try {
return (Boolean)method.invoke(rangeElement, g, domainElement);
} catch (Exception e) {
*******************************************************************************/
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;
public class RelatedObjectAccessor implements IDomainAccessor<StructuralResource,StructuralResource> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectAccessor.class);
Resource relation;
boolean useTypeResource;
@Override
public StructuralResource get(ReadGraph g, StructuralResource element) throws MappingException {
try {
- LOGGER.info(" RelatedObjectAccessor.get");
+ LOGGER.trace(" RelatedObjectAccessor.get");
Resource res = getServiceResource(g, element);
if (res == null)
return null;
public boolean set(WriteGraph g, StructuralResource selement, StructuralResource value)
throws MappingException {
try {
- LOGGER.info(" RelatedObjectAccessor.set");
+ LOGGER.trace(" RelatedObjectAccessor.set");
Resource element = getServiceResource(g, selement);
if (element == null)
return false;
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;
public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResource,Collection<StructuralResource>> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectsAccessor.class);
Resource relation;
boolean deleteExtraObjects;
@Override
public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
try {
- LOGGER.info(" RelatedObjectsAccessor.get");
+ LOGGER.trace(" RelatedObjectsAccessor.get");
Resource res = getServiceResource(g, element);
public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
throws MappingException {
try {
- LOGGER.info(" RelatedObjectsAccessor.set");
+ LOGGER.trace(" RelatedObjectsAccessor.set");
Resource res = getServiceResource(g, element);
if (res == null)
return false;
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;
public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<StructuralResource, Collection<StructuralResource>> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedOrderedSetElementsAccessor.class);
boolean deleteExtraObjects;
boolean useTypeResource;
@Override
public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
try {
- LOGGER.info(" RelatedOrderedSetElementsAccessor.get");
+ LOGGER.trace(" RelatedOrderedSetElementsAccessor.get");
Resource res = getServiceResource(g, element);
if (res == null)
return Collections.emptyList();
public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
throws MappingException {
try {
- LOGGER.info(" RelatedOrderedSetElementsAccessor.set");
+ LOGGER.trace(" RelatedOrderedSetElementsAccessor.set");
Resource res = getServiceResource(g, element);
if (res == null)
return false;
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;
public class RelatedValueAccessor implements IDomainAccessor<StructuralResource,Object> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(RelatedValueAccessor.class);
Resource relation;
Resource valueType;
@Override
public Object get(ReadGraph g, StructuralResource element) throws MappingException {
try {
- LOGGER.info(" RelatedValueAccessor.get");
+ LOGGER.trace(" RelatedValueAccessor.get");
Resource res = getServiceResource(g, element);
if (res == null)
return null;
public boolean set(WriteGraph g, StructuralResource relement, Object value)
throws MappingException {
try {
- LOGGER.info(" RelatedValueAccessor.set");
+ LOGGER.trace(" RelatedValueAccessor.set");
Resource element = getServiceResource(g, relement);
if (element == null)
import java.util.ArrayList;
import java.util.List;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
public class StructuralRelatedObjectAccessor implements IDomainAccessor<StructuralResource,StructuralResource> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(StructuralRelatedObjectAccessor.class);
Resource relation;
boolean useTypeResource;
public StructuralResource get(ReadGraph g, StructuralResource element) throws MappingException {
try {
- LOGGER.info(" RelatedObjectAccessor.get");
+ LOGGER.trace(" RelatedObjectAccessor.get");
if (!element.isStructural())
return null;
public boolean set(WriteGraph g, StructuralResource element, StructuralResource value)
throws MappingException {
try {
- LOGGER.info(" RelatedObjectAccessor.set");
+ LOGGER.trace(" RelatedObjectAccessor.set");
Resource instance = StructuralUtils.getContainingInstance(element);
Resource publicRelation = null;
if (instance == null)
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;
public class StructuralRelatedObjectsAccessor implements IDomainAccessor<StructuralResource,Collection<StructuralResource>> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(StructuralRelatedObjectsAccessor.class);
Resource relation;
boolean deleteExtraObjects;
@Override
public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
try {
- LOGGER.info(" RelatedObjectsAccessor.get");
+ LOGGER.trace(" RelatedObjectsAccessor.get");
if (!element.isStructural())
return Collections.emptyList();
public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
throws MappingException {
try {
- LOGGER.info(" RelatedObjectsAccessor.set");
+ LOGGER.trace(" RelatedObjectsAccessor.set");
if (!element.isStructural())
return false;
*******************************************************************************/
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;
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;
public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralObject> {
- static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+ static Logger LOGGER = LoggerFactory.getLogger(SimpleLinkType.class);
public Resource domainType;
public Class<?> rangeType;
public StructuralResource createDomainElement(WriteGraph g, IStructuralObject rangeElement)
throws MappingException {
try {
- if(LOGGER.isInfoEnabled())
- LOGGER.info("SimpleLinkType.createDomainElement " +
+ if(LOGGER.isTraceEnabled())
+ LOGGER.trace("SimpleLinkType.createDomainElement " +
rangeElement.toString()
);
if (rangeElement.getContext().size() == 0) {
public IStructuralObject createRangeElement(ReadGraph g, StructuralResource domainElement)
throws MappingException {
try {
- if(LOGGER.isInfoEnabled())
+ if(LOGGER.isTraceEnabled())
try {
- LOGGER.info("SimpleLinkType.createRangeElement " + NameUtils.getSafeName(g, domainElement.getResource()));
+ LOGGER.trace("SimpleLinkType.createRangeElement " + NameUtils.getSafeName(g, domainElement.getResource()));
} catch(DatabaseException e) {
throw new MappingException(e);
}
}
public boolean updateDomain(WriteGraph g, IBackwardMapping<StructuralResource,IStructuralObject> map, StructuralResource domainElement, IStructuralObject rangeElement) throws MappingException {
- if(LOGGER.isInfoEnabled())
+ if(LOGGER.isTraceEnabled())
try {
- LOGGER.info("SimpleLinkType.updateDomain " +
+ LOGGER.trace("SimpleLinkType.updateDomain " +
NameUtils.getSafeName(g, domainElement.getResource()) + " " +
rangeElement.toString()
);
public boolean updateRange(ReadGraph g, IForwardMapping<StructuralResource, IStructuralObject> map, StructuralResource domainElement, IStructuralObject rangeElement) throws MappingException {
- if(LOGGER.isInfoEnabled())
+ if(LOGGER.isTraceEnabled())
try {
- LOGGER.info("SimpleLinkType.updateRange " +
+ LOGGER.trace("SimpleLinkType.updateRange " +
NameUtils.getSafeName(g, domainElement.getResource()) + " " +
rangeElement.toString()
);