]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java
Tried to improve the implementation of getPossibleDomainProperty
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / StandardGraphPropertyVariable.java
index 96711b1ac5416fdb30de09eeeaad8be7444e8058..582277c905bbcbd19a2a1308021f5f71c66510f6 100644 (file)
-package org.simantics.db.layer0.variable;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.impl.ObjectVariantBinding;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.common.validation.L0Validations;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ValidationException;\r
-import org.simantics.db.layer0.exception.MissingVariableValueException;\r
-import org.simantics.db.layer0.exception.PendingVariableException;\r
-import org.simantics.db.layer0.exception.VariableException;\r
-import org.simantics.db.layer0.function.All;\r
-import org.simantics.db.layer0.request.PropertyInfo;\r
-import org.simantics.db.layer0.request.PropertyInfoRequest;\r
-import org.simantics.db.layer0.util.Layer0Utils;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.utils.Development;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-public class StandardGraphPropertyVariable extends AbstractPropertyVariable {\r
-\r
-       protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null,\r
-                       false, Collections.<String> emptySet(), null, null, null, null, null, null,\r
-                       Collections.<String, Pair<Resource, ChildReference>> emptyMap(),\r
-                       null, false);\r
-\r
-       final public Variable parent;\r
-       final public Resource parentResource;\r
-       final public PropertyInfo property;\r
-       final public Resource represents;\r
-       \r
-       transient private int hash = 0;\r
-\r
-       public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, VariableNode node, Resource property) throws DatabaseException {\r
-               this(graph, parent, node, (Resource)parent.getPossibleRepresents(graph), getPropertyInfo(graph, property));\r
-       }\r
-       \r
-       public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, VariableNode node, Resource parentResource, Resource property) throws DatabaseException {\r
-               this(graph, parent, node, parentResource, getPropertyInfo(graph, property));\r
-       }\r
-\r
-       public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource property) throws DatabaseException {\r
-        this(graph, parent, null, (Resource)parent.getPossibleRepresents(graph), getPropertyInfo(graph, property));\r
-    }\r
-\r
-    public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, PropertyInfo property) throws DatabaseException {\r
-        this(parent, null, parentResource, property, getPossibleRepresents(graph, parentResource, property.predicate));\r
-    }\r
-    \r
-    public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, VariableNode node, Resource parentResource, PropertyInfo property) throws DatabaseException {\r
-        this(parent, node, parentResource, property, getPossibleRepresents(graph, parentResource, property.predicate));\r
-    }\r
-\r
-    private static PropertyInfo getPropertyInfo(ReadGraph graph, Resource property) throws DatabaseException {\r
-           return property != null ? graph.syncRequest(new PropertyInfoRequest(property), TransientCacheAsyncListener.<PropertyInfo>instance()) : NO_PROPERTY;\r
-    }\r
-    \r
-    private static Resource getPossibleRepresents(ReadGraph graph, Resource parentResource, Resource predicate) throws DatabaseException {\r
-       if(parentResource == null || predicate == null) return null;\r
-       return graph.getPossibleObject(parentResource, predicate);\r
-    }\r
-    \r
-    public boolean isAsserted() {\r
-       return false;\r
-    }\r
-\r
-    public StandardGraphPropertyVariable(Variable parent, VariableNode node, Resource parentResource, PropertyInfo property, Resource represents) throws DatabaseException {\r
-       super(node);\r
-               assert parent != null;\r
-               this.parent = parent;\r
-               this.property = property;\r
-               this.parentResource = parentResource;\r
-               this.represents = represents;\r
-       }\r
-\r
-       @Override\r
-       public String getName(ReadGraph graph) throws DatabaseException {\r
-           if(node != null) return node.support.manager.getName(node.node);\r
-               return property.name;\r
-       }\r
-\r
-       @Override\r
-       public String getPossibleLabel(ReadGraph graph) throws DatabaseException {\r
-               return graph.getPossibleRelatedValue2(property.predicate, graph.getService(Layer0.class).HasLabel, parent, Bindings.STRING);\r
-       }\r
-\r
-       @Override\r
-       public String getLabel(ReadGraph graph) throws DatabaseException {\r
-               return graph.getRelatedValue2(property.predicate, graph.getService(Layer0.class).HasLabel, parent, Bindings.STRING);\r
-       }\r
-\r
-       @Override\r
-       public Variable getParent(ReadGraph graph) throws DatabaseException {\r
-               return parent;\r
-       }\r
-       \r
-       @Override\r
-       public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {\r
-               return property;\r
-       }\r
-\r
-       @SuppressWarnings("unchecked")\r
-       @Override\r
-       public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
-               \r
-               if(Development.DEVELOPMENT) {\r
-                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);\r
-                       if(error != null) {\r
-                               Logger.defaultLogError(new ValidationException(error));\r
-                               //throw new ValidationException(error);\r
-                       }\r
-               }\r
-               \r
-               return (T)getValueAccessor(graph).getValue(graph, this);\r
-               \r
-       }\r
-\r
-       @SuppressWarnings("unchecked")\r
-       @Override\r
-       public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {\r
-               // Fall back to the bindingless method, if the expected output is a Java object \r
-               if (binding instanceof ObjectVariantBinding)\r
-                       return getValue(graph);         \r
-\r
-               if(Development.DEVELOPMENT) {\r
-                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);\r
-                       if(error != null) {\r
-                               Logger.defaultLogError(new ValidationException(error));\r
-                               throw new ValidationException(error);\r
-                       }\r
-               }\r
-        \r
-               try {\r
-                       \r
-                       return (T)getValueAccessor(graph).getValue(graph, this, binding);\r
-               } catch (PendingVariableException e) {\r
-                   throw e;\r
-               } catch (Throwable t) {\r
-                       throw new MissingVariableValueException(t);\r
-               }\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
-               if(represents == null)\r
-                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");\r
-               return represents;\r
-//             return graph.getSingleObject(parentResource, property.predicate);\r
-       }\r
-\r
-       @Override\r
-       public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {\r
-//        if(parentResource == null) return null;\r
-//             return graph.getPossibleObject(parentResource, property.predicate);\r
-               return represents;\r
-       }\r
-\r
-       @Override\r
-       public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {\r
-               \r
-               if(Development.DEVELOPMENT) {\r
-                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);\r
-                       if(error != null) {\r
-                               Logger.defaultLogError(new ValidationException(error));\r
-                               //throw new ValidationException(error);\r
-                       }\r
-               }\r
-               \r
-               getValueAccessor(graph).setValue(graph, this, value, binding);\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void setValue(WriteGraph graph, Object value) throws DatabaseException {\r
-               \r
-               if(Development.DEVELOPMENT) {\r
-                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);\r
-                       if(error != null) {\r
-                               Logger.defaultLogError(new ValidationException(error));\r
-                               throw new ValidationException(error);\r
-                       }\r
-               }\r
-               \r
-               getValueAccessor(graph).setValue(graph, this, value);\r
-               \r
-       }\r
-\r
-       @Override\r
-       public Binding getDefaultBinding(ReadGraph graph) throws DatabaseException {\r
-               return Layer0Utils.getDefaultBinding(graph, this);\r
-       }\r
-       \r
-       @Override\r
-       public Binding getPossibleDefaultBinding(ReadGraph graph) throws DatabaseException {\r
-               return Layer0Utils.getPossibleDefaultBinding(graph, this);\r
-       }\r
-\r
-       @Override\r
-       public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
-//<<<<<<< .mine\r
-//             \r
-//     Binding binding = getPossibleDefaultBinding(graph);\r
-//        if(binding != null) return binding.type();\r
-//\r
-//             Variant vt = getVariantValue(graph);\r
-//             binding = vt.getBinding();\r
-//             if(binding == null) throw new DatabaseException("No binding in Variant with value " + vt.getValue());\r
-//             return binding.type();\r
-//=======\r
-               Datatype type;\r
-               try {                   \r
-                       type = getValueAccessor(graph).getDatatype(graph, this);\r
-               } catch (Throwable t) {\r
-                       throw new MissingVariableValueException(t);\r
-               }\r
-               \r
-               if (type == null) {\r
-                       String uri = this.getPossibleURI(graph);\r
-                       if (uri != null)\r
-                               throw new DatabaseException("No data type for " + uri);\r
-                       else\r
-                               throw new DatabaseException("No data type for " + this.getIdentifier());\r
-               }\r
-               \r
-               return type;\r
-//>>>>>>> .r30794\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public Datatype getPossibleDatatype(ReadGraph graph) throws DatabaseException {\r
-\r
-               try {\r
-                       return getDatatype(graph);\r
-               } catch (DatabaseException e) {\r
-                       return null;\r
-               }\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public String getUnit(ReadGraph graph) throws DatabaseException {\r
-               try {\r
-                       return Layer0Utils.getUnit(graph, this);\r
-               } catch (DatabaseException e) {\r
-                       return null;\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public Resource getPropertyResource(ReadGraph graph) {\r
-               return property.predicate;\r
-       }\r
-       \r
-       @Override\r
-       public Resource getContainerResource(ReadGraph graph) throws DatabaseException {\r
-               return parentResource;\r
-       }\r
-\r
-       @Override\r
-       public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {\r
-\r
-               Map<String, Variable> result = new HashMap<String, Variable>();\r
-               VariableMap map = getPossibleChildVariableMap(graph);\r
-               if(map != null) map.getVariables(graph, this, result);\r
-               return result.values();\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
-\r
-               VariableMap map = getPossibleChildVariableMap(graph);\r
-               if(map == null) return null;\r
-               try {\r
-                       return map.getVariable(graph, this, name);\r
-               } catch (DatabaseException e) {\r
-                       return null;\r
-               }\r
-               \r
-       }\r
-       \r
-       \r
-       @Override\r
-       protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException {\r
-\r
-               VariableMap valueMap = getPossiblePropertyVariableMap(graph);\r
-               if(valueMap == null) return null;\r
-               try {\r
-                       return valueMap.getVariable(graph, this, name);\r
-               } catch (DatabaseException e) {\r
-                       return null;\r
-               } catch (Throwable t) {\r
-                       System.err.println("err: " + getURI(graph) + "  # " + name);\r
-                       return null;\r
-               }\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public Map<String, Variable> collectDomainProperties(ReadGraph graph, Map<String, Variable> properties) throws DatabaseException {\r
-\r
-               VariableMap valueMap = getPossiblePropertyVariableMap(graph);\r
-               if(valueMap == null) return properties;\r
-               return valueMap.getVariables(graph, this, properties);\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public Variable getPredicate(ReadGraph graph) throws DatabaseException {\r
-               return Variables.getVariable(graph, graph.getURI(property.predicate));\r
-       }\r
-       \r
-       @Override\r
-       public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {\r
-               return property.predicate;\r
-       }\r
-       \r
-       @Override\r
-       public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {\r
-               return property.predicate;\r
-       }\r
-\r
-       @Override\r
-       public int hashCode() {\r
-               if(hash == 0) {\r
-                       final int prime = 31;\r
-                       int result = 1;\r
-            result = prime * result + (parent != null ? parent.hashCode() : 0);\r
-            result = prime * result + (node != null ? node.hashCode() : 0);\r
-            result = prime * result + (property.predicate != null ? property.predicate.hashCode() : 0);\r
-            result = prime * result + (parentResource != null ? parentResource.hashCode() : 0);\r
-            result = prime * result + (represents != null ? represents.hashCode() : 0);\r
-                       hash =result;\r
-               }\r
-               return hash;\r
-       }\r
-\r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if (this == obj)\r
-                       return true;\r
-               if (obj == null)\r
-                       return false;\r
-               if (getClass() != obj.getClass())\r
-                       return false;\r
-               StandardGraphPropertyVariable other = (StandardGraphPropertyVariable) obj;\r
-               \r
-        if(node != null) {\r
-               if(!node.equals(other.node)) return false;\r
-        } else if (other.node != null) return false;\r
-\r
-        if(property.predicate != null) {\r
-               if(!property.predicate.equals(other.property.predicate)) return false;\r
-        } else if (other.property.predicate != null) return false;\r
-        \r
-        if(parentResource != null) {\r
-               if(!parentResource.equals(other.parentResource)) return false;\r
-        } else if (other.parentResource != null) return false;\r
-\r
-        if(parent != null) {\r
-               if(!parent.equals(other.parent)) return false;\r
-        } else if (other.parent != null) return false;\r
-\r
-        if(represents != null) {\r
-               if(!represents.equals(other.represents)) return false;\r
-        } else if (other.represents != null) return false;\r
-\r
-        return true;\r
-               \r
-       }\r
-\r
-       @Override\r
-       protected Variable getNameVariable(ReadGraph graph) throws DatabaseException {\r
-           throw new UnsupportedOperationException();\r
-       }\r
-       \r
-       protected ValueAccessor getValueAccessor(ReadGraph graph) throws DatabaseException {\r
-               if((property == null || property == NO_PROPERTY) && parentResource == null) return All.standardValueAccessor;\r
-           ValueAccessor accessor = property.valueAccessor;\r
-           if(accessor != null) return accessor;\r
-           else {\r
-               System.err.println("No value accessor for " + getURI(graph));\r
-               return All.standardValueAccessor;\r
-           }\r
-       }\r
-\r
-       protected VariableMap getPossibleChildVariableMap(ReadGraph graph) throws DatabaseException {\r
-               if(represents == null) return All.standardPropertyDomainChildren;\r
-               return graph.getPossibleRelatedValue2(represents, Layer0.getInstance(graph).domainChildren, this);\r
-       }\r
-\r
-       protected VariableMap getPossiblePropertyVariableMap(ReadGraph graph) throws DatabaseException {\r
-        if(property == null) return All.standardPropertyDomainProperties;\r
-        if(property.predicate == null) return null;\r
-               return graph.syncRequest(new PropertyVariableMapRequest(property.predicate), TransientCacheAsyncListener.<VariableMap>instance());\r
-       }\r
-       \r
-       public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {\r
-               return property.classifications;\r
-       }\r
-       \r
-       @Override\r
-    public Map<String, Variable> collectDomainProperties(ReadGraph graph, String classification, Map<String, Variable> properties) throws DatabaseException {\r
-       \r
-       VariableMap valueMap = getPossiblePropertyVariableMap(graph);\r
-               if(valueMap == null) return properties;\r
-               return valueMap.getVariables(graph, this, classification, properties);\r
-               \r
-    }\r
-       \r
-    public Collection<Variable> getProperties(ReadGraph graph, String classification) throws DatabaseException {\r
-       \r
-       VariableMap valueMap = getPossiblePropertyVariableMap(graph);\r
-               if(valueMap == null) return Collections.emptyList();\r
-               Map<String,Variable> propertyMap = valueMap.getVariables(graph, this, classification, null);\r
-       if(propertyMap == null || propertyMap.isEmpty()) return Collections.emptyList();\r
-       else return propertyMap.values();\r
-       \r
-    }\r
-       \r
-}\r
+package org.simantics.db.layer0.variable;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.impl.ObjectVariantBinding;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.common.validation.L0Validations;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ValidationException;
+import org.simantics.db.layer0.exception.MissingVariableValueException;
+import org.simantics.db.layer0.exception.PendingVariableException;
+import org.simantics.db.layer0.exception.VariableException;
+import org.simantics.db.layer0.function.All;
+import org.simantics.db.layer0.request.PropertyInfo;
+import org.simantics.db.layer0.request.PropertyInfoRequest;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.layer0.Layer0;
+import org.simantics.utils.Development;
+import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StandardGraphPropertyVariable extends AbstractPropertyVariable {
+    private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphPropertyVariable.class);
+    
+       protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null,
+                       false, Collections.<String> emptySet(), null, null, null, null, null, null,
+                       Collections.<String, Pair<Resource, ChildReference>> emptyMap(),
+                       null, false);
+
+       final public Variable parent;
+       final public Resource parentResource;
+       final public PropertyInfo property;
+       final public Resource represents;
+       
+       transient private int hash = 0;
+
+       public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, VariableNode node, Resource property) throws DatabaseException {
+               this(graph, parent, node, (Resource)parent.getPossibleRepresents(graph), getPropertyInfo(graph, property));
+       }
+       
+       public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, VariableNode node, Resource parentResource, Resource property) throws DatabaseException {
+               this(graph, parent, node, parentResource, getPropertyInfo(graph, property));
+       }
+
+       public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource property) throws DatabaseException {
+        this(graph, parent, null, (Resource)parent.getPossibleRepresents(graph), getPropertyInfo(graph, property));
+    }
+
+    public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, PropertyInfo property) throws DatabaseException {
+        this(parent, null, parentResource, property, getPossibleRepresents(graph, parentResource, property.predicate));
+    }
+    
+    public StandardGraphPropertyVariable(ReadGraph graph, Variable parent, VariableNode node, Resource parentResource, PropertyInfo property) throws DatabaseException {
+        this(parent, node, parentResource, property, getPossibleRepresents(graph, parentResource, property.predicate));
+    }
+
+    private static PropertyInfo getPropertyInfo(ReadGraph graph, Resource property) throws DatabaseException {
+           return property != null ? graph.syncRequest(new PropertyInfoRequest(property), TransientCacheAsyncListener.<PropertyInfo>instance()) : NO_PROPERTY;
+    }
+    
+    private static Resource getPossibleRepresents(ReadGraph graph, Resource parentResource, Resource predicate) throws DatabaseException {
+       if(parentResource == null || predicate == null) return null;
+       return graph.getPossibleObject(parentResource, predicate);
+    }
+    
+    public boolean isAsserted() {
+       return false;
+    }
+
+    public StandardGraphPropertyVariable(Variable parent, VariableNode node, Resource parentResource, PropertyInfo property, Resource represents) throws DatabaseException {
+       super(node);
+               assert parent != null;
+               this.parent = parent;
+               this.property = property;
+               this.parentResource = parentResource;
+               this.represents = represents;
+       }
+
+       @Override
+       public String getName(ReadGraph graph) throws DatabaseException {
+           if(node != null) return node.support.manager.getName(node.node);
+               return property.name;
+       }
+
+       @Override
+       public String getPossibleLabel(ReadGraph graph) throws DatabaseException {
+               return graph.getPossibleRelatedValue2(property.predicate, graph.getService(Layer0.class).HasLabel, parent, Bindings.STRING);
+       }
+
+       @Override
+       public String getLabel(ReadGraph graph) throws DatabaseException {
+               return graph.getRelatedValue2(property.predicate, graph.getService(Layer0.class).HasLabel, parent, Bindings.STRING);
+       }
+
+       @Override
+       public Variable getParent(ReadGraph graph) throws DatabaseException {
+               return parent;
+       }
+       
+       @Override
+       public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {
+               return property;
+       }
+
+       @SuppressWarnings("unchecked")
+       @Override
+       public <T> T getValue(ReadGraph graph) throws DatabaseException {
+               
+               if(Development.DEVELOPMENT) {
+                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+                       if(error != null) {
+                           LOGGER.error(error);
+                               //throw new ValidationException(error);
+                       }
+               }
+               
+               return (T)getValueAccessor(graph).getValue(graph, this);
+               
+       }
+
+       @SuppressWarnings("unchecked")
+       @Override
+       public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {
+               // Fall back to the bindingless method, if the expected output is a Java object 
+               if (binding instanceof ObjectVariantBinding)
+                       return getValue(graph);         
+
+               if(Development.DEVELOPMENT) {
+                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+                       if(error != null) {
+                           LOGGER.error(error);
+                               throw new ValidationException(error);
+                       }
+               }
+        
+               try {
+                       
+                       return (T)getValueAccessor(graph).getValue(graph, this, binding);
+               } catch (PendingVariableException e) {
+                   throw e;
+               } catch (Throwable t) {
+                       throw new MissingVariableValueException(t);
+               }
+               
+       }
+       
+       @Override
+       public Resource getRepresents(ReadGraph graph) throws DatabaseException {
+               if(represents == null)
+                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
+               return represents;
+//             return graph.getSingleObject(parentResource, property.predicate);
+       }
+
+       @Override
+       public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {
+//        if(parentResource == null) return null;
+//             return graph.getPossibleObject(parentResource, property.predicate);
+               return represents;
+       }
+
+       @Override
+       public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
+               
+               if(Development.DEVELOPMENT) {
+                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+                       if(error != null) {
+                           LOGGER.error(error);
+                               //throw new ValidationException(error);
+                       }
+               }
+               
+               getValueAccessor(graph).setValue(graph, this, value, binding);
+               
+       }
+       
+       @Override
+       public void setValue(WriteGraph graph, Object value) throws DatabaseException {
+               
+               if(Development.DEVELOPMENT) {
+                       String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+                       if(error != null) {
+                           LOGGER.error(error);
+                               throw new ValidationException(error);
+                       }
+               }
+               
+               getValueAccessor(graph).setValue(graph, this, value);
+               
+       }
+
+       @Override
+       public Binding getDefaultBinding(ReadGraph graph) throws DatabaseException {
+               return Layer0Utils.getDefaultBinding(graph, this);
+       }
+       
+       @Override
+       public Binding getPossibleDefaultBinding(ReadGraph graph) throws DatabaseException {
+               return Layer0Utils.getPossibleDefaultBinding(graph, this);
+       }
+
+       @Override
+       public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
+//<<<<<<< .mine
+//             
+//     Binding binding = getPossibleDefaultBinding(graph);
+//        if(binding != null) return binding.type();
+//
+//             Variant vt = getVariantValue(graph);
+//             binding = vt.getBinding();
+//             if(binding == null) throw new DatabaseException("No binding in Variant with value " + vt.getValue());
+//             return binding.type();
+//=======
+               Datatype type;
+               try {                   
+                       type = getValueAccessor(graph).getDatatype(graph, this);
+               } catch (Throwable t) {
+                       throw new MissingVariableValueException(t);
+               }
+               
+               if (type == null) {
+                       String uri = this.getPossibleURI(graph);
+                       if (uri != null)
+                               throw new DatabaseException("No data type for " + uri);
+                       else
+                               throw new DatabaseException("No data type for " + this.getIdentifier());
+               }
+               
+               return type;
+//>>>>>>> .r30794
+               
+       }
+       
+       @Override
+       public Datatype getPossibleDatatype(ReadGraph graph) throws DatabaseException {
+
+               try {
+                       return getDatatype(graph);
+               } catch (DatabaseException e) {
+                       return null;
+               }
+               
+       }
+       
+       @Override
+       public String getUnit(ReadGraph graph) throws DatabaseException {
+               try {
+                       return Layer0Utils.getUnit(graph, this);
+               } catch (DatabaseException e) {
+                       return null;
+               }
+       }
+
+       @Override
+       public Resource getPropertyResource(ReadGraph graph) {
+               return property.predicate;
+       }
+       
+       @Override
+       public Resource getContainerResource(ReadGraph graph) throws DatabaseException {
+               return parentResource;
+       }
+
+       @Override
+       public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
+
+               Map<String, Variable> result = new HashMap<String, Variable>();
+               VariableMap map = getPossibleChildVariableMap(graph);
+               if(map != null) map.getVariables(graph, this, result);
+               return result.values();
+               
+       }
+       
+       @Override
+       public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
+
+               VariableMap map = getPossibleChildVariableMap(graph);
+               if(map == null) return null;
+               try {
+                       return map.getVariable(graph, this, name);
+               } catch (DatabaseException e) {
+                       return null;
+               }
+               
+       }
+       
+       
+       @Override
+       protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException {
+
+               VariableMap valueMap = getPossiblePropertyVariableMap(graph);
+               if(valueMap == null) return null;
+               try {
+                       return valueMap.getVariable(graph, this, name);
+               } catch (DatabaseException e) {
+                       return null;
+               } catch (Exception t) {
+                       LOGGER.error("getPossibleDomainProperty is implemented incorrectly, but returns null on Exception for backward compatibility. URI="+getURI(graph)+", name="+name+".", t);
+                       return null;
+               }
+               
+       }
+       
+       @Override
+       public Map<String, Variable> collectDomainProperties(ReadGraph graph, Map<String, Variable> properties) throws DatabaseException {
+
+               VariableMap valueMap = getPossiblePropertyVariableMap(graph);
+               if(valueMap == null) return properties;
+               return valueMap.getVariables(graph, this, properties);
+               
+       }
+       
+       @Override
+       public Variable getPredicate(ReadGraph graph) throws DatabaseException {
+               return Variables.getVariable(graph, graph.getURI(property.predicate));
+       }
+       
+       @Override
+       public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
+               return property.predicate;
+       }
+       
+       @Override
+       public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
+               return property.predicate;
+       }
+
+       @Override
+       public int hashCode() {
+               if(hash == 0) {
+                       final int prime = 31;
+                       int result = 1;
+            result = prime * result + (parent != null ? parent.hashCode() : 0);
+            result = prime * result + (node != null ? node.hashCode() : 0);
+            result = prime * result + (property.predicate != null ? property.predicate.hashCode() : 0);
+            result = prime * result + (parentResource != null ? parentResource.hashCode() : 0);
+            result = prime * result + (represents != null ? represents.hashCode() : 0);
+                       hash =result;
+               }
+               return hash;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               StandardGraphPropertyVariable other = (StandardGraphPropertyVariable) obj;
+               
+        if(node != null) {
+               if(!node.equals(other.node)) return false;
+        } else if (other.node != null) return false;
+
+        if(property.predicate != null) {
+               if(!property.predicate.equals(other.property.predicate)) return false;
+        } else if (other.property.predicate != null) return false;
+        
+        if(parentResource != null) {
+               if(!parentResource.equals(other.parentResource)) return false;
+        } else if (other.parentResource != null) return false;
+
+        if(parent != null) {
+               if(!parent.equals(other.parent)) return false;
+        } else if (other.parent != null) return false;
+
+        if(represents != null) {
+               if(!represents.equals(other.represents)) return false;
+        } else if (other.represents != null) return false;
+
+        return true;
+               
+       }
+
+       @Override
+       protected Variable getNameVariable(ReadGraph graph) throws DatabaseException {
+           throw new UnsupportedOperationException();
+       }
+       
+       protected ValueAccessor getValueAccessor(ReadGraph graph) throws DatabaseException {
+               if((property == null || property == NO_PROPERTY) && parentResource == null) return All.standardValueAccessor;
+           ValueAccessor accessor = property.valueAccessor;
+           if(accessor != null) return accessor;
+           else {
+               System.err.println("No value accessor for " + getURI(graph));
+               return All.standardValueAccessor;
+           }
+       }
+
+       protected VariableMap getPossibleChildVariableMap(ReadGraph graph) throws DatabaseException {
+               if(represents == null) return All.standardPropertyDomainChildren;
+           Resource domainChildren = Layer0.getInstance(graph).domainChildren;
+               return graph.getPossibleRelatedValue2(represents, domainChildren, 
+                               new StandardGraphPropertyVariable(graph, this, domainChildren));
+       }
+
+       protected VariableMap getPossiblePropertyVariableMap(ReadGraph graph) throws DatabaseException {
+        if(property == null) return All.standardPropertyDomainProperties;
+        if(property.predicate == null) return null;
+               return graph.syncRequest(new PropertyVariableMapRequest(property.predicate), TransientCacheAsyncListener.<VariableMap>instance());
+       }
+       
+       public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
+               return property.classifications;
+       }
+       
+       @Override
+    public Map<String, Variable> collectDomainProperties(ReadGraph graph, String classification, Map<String, Variable> properties) throws DatabaseException {
+       
+       VariableMap valueMap = getPossiblePropertyVariableMap(graph);
+               if(valueMap == null) return properties;
+               return valueMap.getVariables(graph, this, classification, properties);
+               
+    }
+       
+    public Collection<Variable> getProperties(ReadGraph graph, String classification) throws DatabaseException {
+       
+       VariableMap valueMap = getPossiblePropertyVariableMap(graph);
+               if(valueMap == null) return Collections.emptyList();
+               Map<String,Variable> propertyMap = valueMap.getVariables(graph, this, classification, null);
+       if(propertyMap == null || propertyMap.isEmpty()) return Collections.emptyList();
+       else return propertyMap.values();
+       
+    }
+       
+}