--- /dev/null
+package org.simantics.objmap.rules.adapters;\r
+\r
+public enum IdentityAdapter implements ValueAdapter {\r
+ INSTANCE;\r
+\r
+ @Override\r
+ public Object domainToRange(Object domainValue) {\r
+ return domainValue;\r
+ }\r
+\r
+ @Override\r
+ public Object rangeToDomain(Object rangeValue) {\r
+ return rangeValue;\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.objmap.rules.adapters;\r
+\r
+public interface ValueAdapter {\r
+ Object domainToRange(Object domainValue);\r
+ Object rangeToDomain(Object rangeValue);\r
+}\r
--- /dev/null
+package org.simantics.objmap.rules.range;\r
+\r
+import org.simantics.objmap.MappingException;\r
+import org.simantics.objmap.rules.adapters.ValueAdapter;\r
+\r
+public class AdaptedRangeAccessor implements IRangeAccessor<Object> {\r
+ IRangeAccessor<Object> baseAccessor;\r
+ ValueAdapter adapter;\r
+ \r
+ public AdaptedRangeAccessor(IRangeAccessor<Object> baseAccessror,\r
+ ValueAdapter adapter) {\r
+ this.baseAccessor = baseAccessror;\r
+ this.adapter = adapter;\r
+ }\r
+\r
+ @Override\r
+ public Object get(Object element) throws MappingException {\r
+ return adapter.rangeToDomain(baseAccessor.get(element)); \r
+ }\r
+ \r
+ @Override\r
+ public boolean set(Object element, Object value) throws MappingException {\r
+ return baseAccessor.set(element, adapter.domainToRange(value));\r
+ }\r
+}\r