]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java
Replace instantiations of DatabaseException with more specific
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / AbstractVariable.java
index 53c5fb5b72922d4885dd0c03791f4c4f3c989902..00b01cca6031f967c315f37ed2d2c147f3a20c62 100644 (file)
@@ -82,7 +82,7 @@ public abstract class AbstractVariable implements Variable {
      
     @Override
     public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {
-       throw new DatabaseException("PropertyInfo is not available");
+       throw new InvalidVariableException("PropertyInfo is not available");
     }
     
     @Override
@@ -117,7 +117,7 @@ public abstract class AbstractVariable implements Variable {
                String name = child.getPossiblePropertyValue(graph, Variables.NAME, Bindings.STRING);
                if(rName.equals(name)) return child;
        }
-       throw new DatabaseException("Could not resolve child " + resource);
+       throw new MissingVariableException("Could not resolve child " + rName, resource);
     }
     
     protected Variable resolveChild(ReadGraph graph, GuidRVIPart part) throws DatabaseException {
@@ -130,7 +130,7 @@ public abstract class AbstractVariable implements Variable {
                String name = child.getPossiblePropertyValue(graph, Variables.NAME, Bindings.STRING);
                if(rName.equals(name)) return child;
        }
-       throw new DatabaseException("Could not resolve child " + resource);
+       throw new MissingVariableException("Could not resolve child " + rName, resource);
     }
 
     protected Variable resolveProperty(ReadGraph graph, GuidRVIPart part) throws DatabaseException {
@@ -203,7 +203,7 @@ public abstract class AbstractVariable implements Variable {
                Variable parent = getParent(graph);
                if (parent == null)
                        // TODO: consider using a more suitable exception here to better convey the situation.
-                       throw new MissingVariableException("no parent for variable " + this + " (URI=" + getPossibleURI(graph) + ")");
+                       throw new MissingVariableException("no parent for variable " + this + " (URI=" + getPossibleURI(graph) + ")", getPossibleRepresents(graph));
                RVI base = graph.syncRequest(new VariableRVIRequest(parent));
                RVIPart part = getRVIPart(graph);
                return new RVIBuilder(base).append(part).toRVI();
@@ -213,7 +213,7 @@ public abstract class AbstractVariable implements Variable {
     protected Variable getDomainProperty(ReadGraph graph, String name) throws DatabaseException {
         Variable property = getPossibleDomainProperty(graph, name);
         if(property == null)
-            throw new MissingVariableException(getIdentifier() + ": Didn't find property " + name + ".");
+            throw new MissingVariableException(getIdentifier() + ": Didn't find property " + name + ".", getPossibleRepresents(graph));
         return property;
     }
     
@@ -460,17 +460,20 @@ public abstract class AbstractVariable implements Variable {
 
     @SuppressWarnings("unchecked")
     @Override
-    public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding)
-            throws DatabaseException {
-        if(binding instanceof StringBinding) {
-            StringBinding sb = (StringBinding)binding;
+    public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
+        if (binding instanceof StringBinding) {
+            StringBinding sb = (StringBinding) binding;
             try {
-                if(Variables.NAME.equals(name)) return (T)sb.create((String)checkNull(graph, getName(graph)));
-                if(Variables.LABEL.equals(name)) return (T)sb.create((String)checkNull(graph, getLabel(graph)));
-                if(Variables.URI.equals(name)) return (T)sb.create((String)checkNull(graph, getURI(graph)));
-//                if(Variables.SERIALISED.equals(name)) return (T)sb.create((String)checkNull(graph, getSerialized(graph)));
-            } catch(BindingException e) {
-                throw new DatabaseException(e);
+                if (Variables.NAME.equals(name))
+                    return (T) sb.create((String) checkNull(graph, getName(graph)));
+                if (Variables.LABEL.equals(name))
+                    return (T) sb.create((String) checkNull(graph, getLabel(graph)));
+                if (Variables.URI.equals(name))
+                    return (T) sb.create((String) checkNull(graph, getURI(graph)));
+                // if(Variables.SERIALISED.equals(name)) return
+                // (T)sb.create((String)checkNull(graph, getSerialized(graph)));
+            } catch (BindingException e) {
+                throw new org.simantics.db.exception.BindingException("Could not get value for property " + name + " with binding " + binding, e);
             }
         }
         Variable property = getPossibleExtraProperty(graph, name);
@@ -478,7 +481,7 @@ public abstract class AbstractVariable implements Variable {
             return property.getValue(graph, binding);
         property = getPossibleDomainProperty(graph, name);
         if(property == null)
-            throw new MissingVariableException("Didn't find property " + name + " for " + this + ".");
+            throw new MissingVariableException("Didn't find property " + name + " for " + this + ".", getPossibleRepresents(graph));
         return property.getValue(graph, binding);
     }
 
@@ -499,7 +502,7 @@ public abstract class AbstractVariable implements Variable {
                 if(Variables.URI.equals(name)) return (T)sb.create((String)getURI(graph));
 //                if(Variables.SERIALISED.equals(name)) return (T)sb.create((String)getSerialized(graph));
             } catch(BindingException e) {
-                throw new DatabaseException(e);
+                throw new org.simantics.db.exception.BindingException("Could not get property value for " + name + " with binding " + binding, e);
             }
         }
         Variable property = getPossibleExtraProperty(graph, name);
@@ -521,7 +524,7 @@ public abstract class AbstractVariable implements Variable {
        try {
                        setValue(graph, value, Bindings.getBinding(value.getClass()));
                } catch (BindingConstructionException e) {
-                       throw new DatabaseException(e);
+                       throw new org.simantics.db.exception.BindingException("Could not set " + String.valueOf(value) + " value for " + getRepresents(graph), e);
                }
     }
     
@@ -551,7 +554,7 @@ public abstract class AbstractVariable implements Variable {
             throws DatabaseException {
         Variable child = getPossibleChild(graph, name);
         if(child == null)
-            throw new MissingVariableException(getURI(graph) + ": didn't find child " + name + " for " + getIdentifier() + ".");
+            throw new MissingVariableException(getURI(graph) + ": didn't find child " + name + " for " + getIdentifier() + ".", getPossibleRepresents(graph));
         return child;
     }    
 
@@ -559,7 +562,7 @@ public abstract class AbstractVariable implements Variable {
     public Variable getProperty(ReadGraph graph, String name)  throws DatabaseException {
         Variable result = getPossibleProperty(graph, name);
         if(result == null)
-            throw new MissingVariableException(getClass().getSimpleName() + ": Didn't find property " + name + " for " + getPossibleURI(graph) + ".");
+            throw new MissingVariableException(getClass().getSimpleName() + ": Didn't find property " + name + " for " + getPossibleURI(graph) + ".", getPossibleRepresents(graph));
         return result;
     }
     
@@ -578,7 +581,7 @@ public abstract class AbstractVariable implements Variable {
         case '.': {
             Variable parent = getParent(graph); 
             if(parent == null)
-                throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").");
+                throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph));
             return parent.browse(graph, suffix.substring(1));
         }
         case '#': {
@@ -586,7 +589,7 @@ public abstract class AbstractVariable implements Variable {
             Variable property = getProperty(graph, 
                     decodeString(suffix.substring(1, segmentEnd)));
             if(property == null) 
-                throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").");
+                throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph));
             return property.browse(graph, suffix.substring(segmentEnd));
         }
         case '/': {
@@ -594,11 +597,11 @@ public abstract class AbstractVariable implements Variable {
             Variable child = getChild(graph, 
                     decodeString(suffix.substring(1, segmentEnd)));
             if(child == null) 
-                throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").");
+                throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph));
             return child.browse(graph, suffix.substring(segmentEnd));
         }
         default:
-            throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").");
+            throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph));
         }
        
     }
@@ -652,7 +655,7 @@ public abstract class AbstractVariable implements Variable {
         Variable variable = browsePossible(graph, config);
         if(variable == null)
             throw new MissingVariableException("Didn't find a variable related to " + 
-                    NameUtils.getSafeName(graph, config) + ".");
+                    NameUtils.getSafeName(graph, config) + ".", config);
         return variable;
     }
 
@@ -722,7 +725,7 @@ public abstract class AbstractVariable implements Variable {
                try {
                                binding = Bindings.OBJECT.getContentBinding(value);
                        } catch (BindingException e) {
-                               throw new DatabaseException(e);
+                               throw new org.simantics.db.exception.BindingException("Could not bind variant value " + String.valueOf(value) + " for " + getRepresents(graph), e);
                        }
                return new Variant(binding, value);
         }
@@ -836,7 +839,7 @@ public abstract class AbstractVariable implements Variable {
                        if(Role.CHILD.equals(grp.getRole())) return resolveChild(graph, grp);
                        else if(Role.PROPERTY.equals(grp.getRole())) return resolveProperty(graph, grp);
                }
-               throw new DatabaseException("Unrecognized RVIPart: " + part);
+               throw new MissingVariableException("Unrecognized RVIPart: " + part, getPossibleRepresents(graph));
        }
 
        @Override
@@ -854,12 +857,12 @@ public abstract class AbstractVariable implements Variable {
                        if(Role.CHILD.equals(grp.getRole())) return resolvePossibleChild(graph, grp);
                        else if(Role.PROPERTY.equals(grp.getRole())) return resolvePossibleProperty(graph, grp);
                }
-               throw new DatabaseException("Unrecognized RVIPart: " + part);
+               throw new MissingVariableException("Unrecognized RVIPart: " + part, getPossibleRepresents(graph));
        }
 
        @Override
        public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("No data type.");
+               throw new InvalidVariableException("No data type.");
        }
 
        public Binding getDefaultBinding(ReadGraph graph) throws DatabaseException {
@@ -905,7 +908,7 @@ public abstract class AbstractVariable implements Variable {
 
        @Override
        public Variable getPredicate(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph));
+               throw new MissingVariableException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph), getPossibleRepresents(graph));
        }
 
        @Override
@@ -916,14 +919,15 @@ public abstract class AbstractVariable implements Variable {
             return null;
         }
        }
-       
-       @Override
-       public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
-               Variable predicate = getPredicate(graph);
-               if(predicate == null) throw new DatabaseException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph));
-               return predicate.getRepresents(graph);
-       }
-       
+
+    @Override
+    public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
+        Variable predicate = getPredicate(graph);
+        if (predicate == null)
+            throw new MissingVariableException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph), getPossibleRepresents(graph));
+        return predicate.getRepresents(graph);
+    }
+
        @Override
        public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
                Variable predicate = getPossiblePredicate(graph);