]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Replace instantiations of DatabaseException with more specific 46/2046/5
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 29 Aug 2018 10:56:12 +0000 (13:56 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 29 Aug 2018 12:11:53 +0000 (15:11 +0300)
gitlab #92

Change-Id: I3030bdb2d02492783bda2ca8118c96b48b734c13

25 files changed:
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/InvalidVariableException.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableException.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableValueException.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/NonWritableVariableException.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/PendingVariableException.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractConstantPropertyVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardRVIResolver.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableRepository.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java
bundles/org.simantics.db/src/org/simantics/db/exception/DatabaseException.java
bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java [new file with mode: 0644]
bundles/org.simantics.db/src/org/simantics/db/exception/VariableException.java [moved from bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/VariableException.java with 86% similarity]
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/ResolveMonitorVariable.java
bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/Removers.java
bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/ScenegraphLoaderUtils.java
bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/util/SpreadsheetUtils.java
bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java

index 2af2edcaa42cedf61da6cedd32da2a0c681a12cd..03beab469fb335a838d973855138082e757d86b5 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.db.layer0.exception;
 
+import org.simantics.db.exception.VariableException;
+
 /**
  * @author Tuukka Lehtonen
  */
index 8d5fe852e27d8472ab8b1145ad52c1fdff8b648f..90be7c061bafa9d1063c2a12661d4d11c36ad200 100644 (file)
 package org.simantics.db.layer0.exception;
 
 import org.simantics.db.Resource;
-
+import org.simantics.db.exception.VariableException;
 
 public class MissingVariableException extends VariableException {
 
        private static final long serialVersionUID = -8379218573294565788L;
        
        private final Resource resource;
-       
-       public MissingVariableException(String message) {
-               super(message);
-               this.resource = null;
-       }
 
        public MissingVariableException(String message, Resource resource) {
-               super(message);
+               super(message + " " + String.valueOf(resource));
                this.resource = resource;
        }
        
index eedd4c26a4237a1b7cc0498895f00c78c577a6a4..94b4a5cbf688e404ba6ef800d8b37b8c0293126d 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.db.layer0.exception;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.VariableException;
 
 
 public class MissingVariableValueException extends VariableException {
index beb0fe01af07352c346387855936ba2928eda886..475dedbfc0a706ba4126b4663fece22136814a98 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.db.layer0.exception;
 
+import org.simantics.db.exception.VariableException;
 import org.simantics.db.layer0.variable.Variable;
 
 /**
index da0e51eecadd4921df7b06b944f82caa53e81deb..3972140b92a7fc2ea7258106f9c87ea4490ffb83 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.db.layer0.exception;
 
 import org.simantics.db.Resource;
+import org.simantics.db.exception.VariableException;
 
 
 public class PendingVariableException extends VariableException {
index 84cefe37fc47eff3fba167a7c3366e0f0eabb3ad..991a0500ce93dac89f4715fd301296b04d330863 100644 (file)
@@ -39,13 +39,16 @@ import org.simantics.db.common.utils.ListUtils;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.common.validation.L0Validations;
+import org.simantics.db.exception.AdaptionException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.DoesNotContainValueException;
 import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.exception.VariableException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
+import org.simantics.db.layer0.exception.MissingVariableException;
 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.request.PossibleURI;
 import org.simantics.db.layer0.request.PropertyInfo;
 import org.simantics.db.layer0.request.PropertyInfoRequest;
@@ -167,7 +170,7 @@ public class All {
                 if(value == null) throw new MissingVariableValueException(variable.getPossibleURI(graph));
                 return value.getValue(binding);
             } catch (AdaptException e) {
-                throw new DatabaseException(e);
+                throw new AdaptionException("Could not get value for " + context.getURI(graph), e);
             }
         }
                
@@ -267,7 +270,7 @@ public class All {
                try {
                        modifier.apply(graph, context, value, Bindings.getBinding(value.getClass()));
                } catch (BindingConstructionException e) {
-                       throw new DatabaseException(e);
+                       throw new org.simantics.db.exception.BindingException("",e);
                }
 
        }
@@ -1307,14 +1310,14 @@ public class All {
                }
 
                if (variable.parentResource == null)
-                       throw new VariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").");
+                       throw new InvalidVariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").");
 
                try {
                        return graph.getRelatedValue2(variable.parentResource, variable.property.predicate, variable);
                } catch (NoSingleResultException e) {
-                       throw new MissingVariableValueException(variable.getPossibleURI(graph));
+                       throw new MissingVariableValueException(variable.getPossibleURI(graph), e);
                } catch (DoesNotContainValueException e) {
-                       throw new MissingVariableValueException(variable.getPossibleURI(graph));
+                       throw new MissingVariableValueException(variable.getPossibleURI(graph), e);
                }
                
        }
@@ -1330,14 +1333,14 @@ public class All {
                }
 
                if (variable.parentResource == null)
-                       throw new VariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").");
+                       throw new MissingVariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").", context.getPossibleRepresents(graph));
 
                try {
                        return graph.getRelatedValue2(variable.parentResource, variable.property.predicate, variable);
                } catch (NoSingleResultException e) {
-                       throw new MissingVariableValueException(variable.getPossibleURI(graph));
+                       throw new MissingVariableValueException(variable.getPossibleURI(graph), e);
                } catch (DoesNotContainValueException e) {
-                       throw new MissingVariableValueException(variable.getPossibleURI(graph));
+                       throw new MissingVariableValueException(variable.getPossibleURI(graph), e);
                }
                
        }
index 7df21813027ab198fd3ccf5c4d0ca3fb6d3fcd99..11dd941c6f6eae72240a128782d44d214e6a22a2 100644 (file)
@@ -12,6 +12,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.exception.MissingVariableValueException;
+import org.simantics.db.layer0.exception.NonWritableVariableException;
 import org.simantics.db.layer0.variable.RVI.RVIPart;
 import org.simantics.db.layer0.variable.RVI.StringRVIPart;
 import org.simantics.db.layer0.variable.Variables.Role;
@@ -42,9 +43,8 @@ public abstract class AbstractChildVariable extends AbstractVariable {
     }
     
     @Override
-    public void setValue(WriteGraph graph, Object value, Binding binding)
-            throws DatabaseException {
-        throw new DatabaseException("Cannot write value to a child variable.");
+    public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
+        throw new NonWritableVariableException("Cannot write value to a child variable.");
     }
 
     
index aa665cf61701f3a67d06814a52cecccd13cf69a0..f2b7ff47b7919b60340614df48cb57d1f5672719 100644 (file)
@@ -12,6 +12,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.exception.NonWritableVariableException;
 import org.simantics.utils.ObjectUtils;
 
 abstract public class AbstractConstantPropertyVariable extends AbstractPropertyVariable {
@@ -40,9 +41,8 @@ abstract public class AbstractConstantPropertyVariable extends AbstractPropertyV
     }
 
     @Override
-    public void setValue(WriteGraph graph, Object value, Binding binding)
-            throws DatabaseException {
-        throw new DatabaseException("Value is constant.");
+    public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
+        throw new NonWritableVariableException("Value is constant.");
     }
 
     @Override
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);
index 5d4915d94035d204ba0c966dd949ebfc0d55256f..082caa603ba486bf4319f102434d184c5fdedd14 100644 (file)
@@ -5,6 +5,9 @@ import org.simantics.databoard.type.Datatype;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.DatatypeNotFoundException;
+import org.simantics.db.layer0.exception.MissingVariableValueException;
+import org.simantics.db.layer0.exception.NonWritableVariableException;
 import org.simantics.scl.runtime.SCLContext;
 import org.simantics.scl.runtime.function.Function1;
 import org.simantics.scl.runtime.function.Function2;
@@ -35,7 +38,7 @@ public class SCLValueAccessor implements ValueAccessor {
         try {
             return getValue1.apply(context);
         } catch (Throwable t) {
-            throw new DatabaseException(t);
+            throw new MissingVariableValueException("Could not get value for " + String.valueOf(context.getRepresents(graph)), t);
         } finally {
             sclContext.put("graph", oldGraph);
         }
@@ -48,7 +51,7 @@ public class SCLValueAccessor implements ValueAccessor {
         try {
             return getValue2.apply(context, binding);
         } catch (Throwable t) {
-            throw new DatabaseException(t);
+            throw new MissingVariableValueException("Could not get value for " + String.valueOf(context.getRepresents(graph)) + " with binding " + binding, t);
         } finally {
             sclContext.put("graph", oldGraph);
         }
@@ -61,7 +64,7 @@ public class SCLValueAccessor implements ValueAccessor {
         try {
             setValue2.apply(context, value);
         } catch (Throwable t) {
-            throw new DatabaseException(t);
+            throw new NonWritableVariableException("Could not write value " + String.valueOf(value) + " for " + String.valueOf(context.getRepresents(graph)), t);
         } finally {
             sclContext.put("graph", oldGraph);
         }
@@ -74,7 +77,7 @@ public class SCLValueAccessor implements ValueAccessor {
         try {
             setValue3.apply(context, value, binding);
         } catch (Throwable t) {
-            throw new DatabaseException(t);
+            throw new NonWritableVariableException("Could not write value " + String.valueOf(value) + " for " + String.valueOf(context.getRepresents(graph)) + " with binding " + binding, t);
         } finally {
             sclContext.put("graph", oldGraph);
         }
@@ -87,7 +90,7 @@ public class SCLValueAccessor implements ValueAccessor {
         try {
             return getDatatype.apply(context);
         } catch (Throwable t) {
-            throw new DatabaseException(t);
+            throw new DatatypeNotFoundException("Could not find datatype for " + String.valueOf(context.getRepresents(graph)), t);
         } finally {
             sclContext.put("graph", oldGraph);
         }
index cffd74727c8000ed8e84cb15dfc582480702c106..78fff71c2d44a31696332c96d1c90097aa6a7078 100644 (file)
@@ -12,8 +12,8 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.exception.AssumptionException;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.VariableException;
 import org.simantics.db.layer0.exception.InvalidVariableException;
-import org.simantics.db.layer0.exception.VariableException;
 import org.simantics.db.layer0.function.All;
 import org.simantics.db.layer0.request.ClassificationsRequest;
 import org.simantics.db.layer0.request.VariableURI;
@@ -150,7 +150,7 @@ public class StandardGraphChildVariable extends AbstractChildVariable {
        @Override
        final public Resource getRepresents(ReadGraph graph) throws DatabaseException {
            if(resource == null)
-               throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
+               throw new InvalidVariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
            return resource;
 //             Layer0X L0X = Layer0X.getInstance(graph);
 //             Resource represents = graph.getPossibleObject(resource, L0X.Represents);
index 582277c905bbcbd19a2a1308021f5f71c66510f6..2dcb6e00ab08871f296c7af6d5a498115edf7d60 100644 (file)
@@ -17,10 +17,12 @@ 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.DatatypeNotFoundException;
 import org.simantics.db.exception.ValidationException;
+import org.simantics.db.exception.VariableException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
 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;
@@ -159,7 +161,7 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable {
        @Override
        public Resource getRepresents(ReadGraph graph) throws DatabaseException {
                if(represents == null)
-                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
+                       throw new InvalidVariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
                return represents;
 //             return graph.getSingleObject(parentResource, property.predicate);
        }
@@ -233,9 +235,9 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable {
                if (type == null) {
                        String uri = this.getPossibleURI(graph);
                        if (uri != null)
-                               throw new DatabaseException("No data type for " + uri);
+                               throw new DatatypeNotFoundException("No data type for " + uri);
                        else
-                               throw new DatabaseException("No data type for " + this.getIdentifier());
+                               throw new DatatypeNotFoundException("No data type for " + this.getIdentifier());
                }
                
                return type;
index 0159e7ac69e099be424e282519930ec88aa920c9..6fa5127db65112153c8858617874d6506d82d570 100644 (file)
@@ -7,10 +7,13 @@ import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.layer0.exception.MissingVariableValueException;
-import org.simantics.db.layer0.exception.VariableException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class StandardGraphResourcePropertyVariable extends StandardGraphPropertyVariable {
-       
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphResourcePropertyVariable.class);
+
        public StandardGraphResourcePropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource property) throws DatabaseException {
            super(graph, parent, null, parentResource, property);
        }
@@ -18,24 +21,24 @@ public class StandardGraphResourcePropertyVariable extends StandardGraphProperty
        @Override
        public <T> T getValue(ReadGraph graph) throws DatabaseException {
                if (parentResource == null)
-                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
+                       throw new MissingVariableValueException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
                try {
                return (T)graph.getSingleObject(parentResource, property.predicate);
                } catch (NoSingleResultException e) {
-                       System.err.println("No object for " + parentResource + " " + property);
-                       throw new MissingVariableValueException(getPossibleURI(graph));
+                       LOGGER.error("No object for " + parentResource + " " + property);
+                       throw new MissingVariableValueException(getPossibleURI(graph), e);
                } 
        }
 
        @Override
        public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {
                if (parentResource == null)
-                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
+                       throw new MissingVariableValueException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
                try {
             return (T)graph.getSingleObject(parentResource, property.predicate);
                } catch (NoSingleResultException e) {
-                       System.err.println("No object for " + parentResource + " " + property);
-                       throw new MissingVariableValueException(getPossibleURI(graph));
+                       LOGGER.error("No object for " + parentResource + " " + property);
+                       throw new MissingVariableValueException(getPossibleURI(graph), e);
                } 
        }
        
index b01aeb32b3c810c6347b96aa01bb6bc2e8feb41c..7c7ba292d851d8bfde2cbf1f13d2fe3713885848 100644 (file)
@@ -40,7 +40,7 @@ public class StandardRVIResolver implements RVIResolver {
             Variable parent = variable.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 " + variable + " (URI=" + variable.getURI(graph) + ")");
+                throw new MissingVariableException("no parent for variable " + variable + " (URI=" + variable.getURI(graph) + ")", variable.getPossibleRepresents(graph));
             RVI base = graph.syncRequest(new VariableRVIRequest(parent));
             RVIPart part = getRVIPart(graph, variable);
             return new RVIBuilder(base).append(part).toRVI();
@@ -90,7 +90,7 @@ public class StandardRVIResolver implements RVIResolver {
                                return child;
                }
        }
-       throw new DatabaseException("Could not resolve child " + part);
+       throw new MissingVariableException("Could not resolve child " + part, variable.getPossibleRepresents(graph));
     }
 
     public static Variable resolvePropertyDefault(ReadGraph graph, Variable variable, GuidRVIPart part) throws DatabaseException {
@@ -102,7 +102,7 @@ public class StandardRVIResolver implements RVIResolver {
                                return child;
                }
        }
-       throw new DatabaseException("Could not resolve property " + part);
+       throw new MissingVariableException("Could not resolve property " + part, variable.getPossibleRepresents(graph));
     }
 
     @Override
@@ -120,7 +120,7 @@ public class StandardRVIResolver implements RVIResolver {
             if(Role.CHILD.equals(grp.getRole())) return resolveChild(graph, context, grp);
             else if(Role.PROPERTY.equals(grp.getRole())) return resolveProperty(graph, context, grp);
         }
-        throw new DatabaseException("Unrecognized RVIPart: " + part);
+        throw new MissingVariableException("Unrecognized RVIPart: " + part, context.getPossibleRepresents(graph));
     }
 
 }
index 1f6b18030e6747339179b0b99fde35443aa5f33d..d2d4ebef0ce404b7ae5fe3e9edbb8058b6e61885 100644 (file)
@@ -12,6 +12,10 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
+import org.simantics.db.layer0.exception.MissingVariableException;
+import org.simantics.db.layer0.exception.MissingVariableValueException;
+import org.simantics.db.layer0.exception.NonWritableVariableException;
 import org.simantics.db.layer0.request.PropertyInfo;
 import org.simantics.db.layer0.variable.RVI.RVIPart;
 import org.simantics.db.layer0.variable.Variables.Role;
@@ -40,37 +44,37 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public <T> T getPropertyValue(ReadGraph graph, String name) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + name);
+               throw new MissingVariableValueException("Could not resolve property " + name);
        }
 
        @Override
        public <T> T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+               throw new MissingVariableValueException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
        }
 
        @Override
        public <T> T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + name);
+               throw new MissingVariableValueException("Could not resolve property " + name);
        }
 
        @Override
        public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+               throw new MissingVariableValueException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
        }
 
        @Override
        public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + name);
+               throw new MissingVariableValueException("Could not resolve property " + name);
        }
 
        @Override
        public <T> T getPropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+               throw new MissingVariableValueException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
        }
 
        @Override
        public <T> T getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + name);
+               throw new MissingVariableValueException("Could not resolve property " + name);
        }
 
        @Override
@@ -102,37 +106,37 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
-               throw new DatabaseException("Not supported");
+               throw new NonWritableVariableException("Not supported");
        }
 
        @Override
        public void setValue(WriteGraph graph, Object value) throws DatabaseException {
-               throw new DatabaseException("Not supported");
+               throw new NonWritableVariableException("Not supported");
        }
 
        @Override
        public void setPropertyValue(WriteGraph graph, String name, Object value, Binding binding) throws DatabaseException {
-               throw new DatabaseException("Not supported");
+               throw new NonWritableVariableException("Not supported");
        }
 
        @Override
        public void setPropertyValue(WriteGraph graph, Resource property, Object value, Binding binding) throws DatabaseException {
-               throw new DatabaseException("Not supported");
+               throw new NonWritableVariableException("Not supported");
        }
 
        @Override
        public void setPropertyValue(WriteGraph graph, String name, Object value) throws DatabaseException {
-               throw new DatabaseException("Not supported");
+               throw new NonWritableVariableException("Not supported");
        }
 
        @Override
        public void setPropertyValue(WriteGraph graph, Resource property, Object value) throws DatabaseException {
-               throw new DatabaseException("Not supported");
+               throw new NonWritableVariableException("Not supported");
        }
 
        @Override
        public Variable getChild(ReadGraph graph, String name) throws DatabaseException {
-               throw new DatabaseException("Could not resolve child " + name);
+               throw new MissingVariableException("Could not resolve child " + name, getPossibleRepresents(graph));
        }
 
        @Override
@@ -142,12 +146,12 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Variable getProperty(ReadGraph graph, String name) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + name);
+               throw new MissingVariableException("Could not resolve property " + name, getPossibleRepresents(graph));
        }
 
        @Override
        public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException {
-               throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+               throw new MissingVariableException("Could not resolve property " + NameUtils.getSafeName(graph, property, true), getPossibleRepresents(graph));
        }
 
        @Override
@@ -194,7 +198,7 @@ public abstract class ValueProxyVariable implements Variable {
        public Variable browse(ReadGraph graph, String suffix) throws DatabaseException {
                if (suffix.isEmpty())
                        return this;
-               throw new DatabaseException("Could not browse with suffix '" + suffix + "'");
+               throw new MissingVariableException("Could not browse with suffix '" + suffix + "'", getPossibleRepresents(graph));
        }
 
        @Override
@@ -206,7 +210,7 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Variable browse(ReadGraph graph, Resource config) throws DatabaseException {
-               throw new DatabaseException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'");
+               throw new MissingVariableException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'", getPossibleRepresents(graph));
        }
 
        @Override
@@ -240,7 +244,7 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
@@ -253,7 +257,7 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public String getLabel(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
@@ -270,17 +274,17 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Variable getPredicate(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
        public Variable getPossiblePredicate(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
        public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
@@ -299,7 +303,7 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Resource getRepresents(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("no resource representation");
+               throw new InvalidVariableException("no resource representation");
        }
 
        @Override
@@ -309,7 +313,7 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Resource getType(ReadGraph graph) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
@@ -319,7 +323,7 @@ public abstract class ValueProxyVariable implements Variable {
 
        @Override
        public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
-               throw new DatabaseException("not supported");
+               throw new InvalidVariableException("not supported");
        }
 
        @Override
index 48062205cad175b35a806d0632d9f5fb46451513..bcb207e9e820727fa4b8368b1fe5ccae9ed877e9 100644 (file)
@@ -36,12 +36,11 @@ final public class VariableRepository {
                                return e.getValue().browse(graph, uri.substring(e.getKey().length()));
                        }
                }
-               throw new MissingVariableException(uri);
+               throw new MissingVariableException(uri, null);
        }
-       
+
        public static void clear() {
            repository.clear();
        }
     
 }
-
index 5fb0636a08dec5e41a616b863c58bbb7fbbaa4df..610e0013c8cedb57cc118b73bebc5e2a6b4763aa 100644 (file)
@@ -32,7 +32,9 @@ import org.simantics.db.common.request.PossibleIndexRoot;
 import org.simantics.db.common.request.TernaryRead;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
 import org.simantics.db.layer0.exception.MissingVariableException;
+import org.simantics.db.layer0.exception.MissingVariableValueException;
 import org.simantics.db.layer0.request.Model;
 import org.simantics.db.layer0.request.PossibleActiveVariableFromVariable;
 import org.simantics.db.layer0.request.PossibleVariableIndexRoot;
@@ -406,7 +408,8 @@ final public class Variables {
 
     public static Variable getContext(ReadGraph graph, Variable variable) throws DatabaseException {
         Variable context = getPossibleContext(graph, variable);
-        if(context == null) throw new DatabaseException("No context found for " + variable.getURI(graph));
+        if (context == null)
+            throw new MissingVariableException("No context found for " + variable.getURI(graph), variable.getPossibleRepresents(graph));
         else return context;
     }
 
@@ -425,7 +428,7 @@ final public class Variables {
     public static String getRVI(ReadGraph graph, Variable variable) throws DatabaseException {
         Resource realizationResource = getRealization(graph, variable);
         if (realizationResource == null)
-            throw new DatabaseException("No realization found for " + variable.getURI(graph));
+            throw new InvalidVariableException("No realization found for " + variable.getURI(graph));
         return variable.getURI(graph).substring(graph.getURI(realizationResource).length()); 
     }
 
@@ -471,7 +474,8 @@ final public class Variables {
 
     public static Variable switchRealization(ReadGraph graph, Variable variable, Resource realization) throws DatabaseException {
         Resource current = getRealization(graph, variable);
-        if(current == null) throw new DatabaseException("No current realization found for variable");
+        if (current == null)
+            throw new InvalidVariableException("No current realization found for variable");
         return switchRealization(graph, variable, current, realization);
     }
 
@@ -545,13 +549,13 @@ final public class Variables {
     }
 
     public static String appendRVI(ReadGraph graph, String modelURI, String rvi, Resource configuration) throws DatabaseException {
-
         Layer0 L0 = Layer0.getInstance(graph);
         String partName = graph.getPossibleRelatedValue(configuration, L0.HasName);
-        if(partName == null) throw new MissingVariableException("Can not append a child corresponding to " + configuration + " to rvi '" + rvi + "' since there is no name.");
+        if (partName == null)
+            throw new MissingVariableException("Can not append a child corresponding to " + configuration + " to rvi '"
+                    + rvi + "' since there is no name.", configuration);
         String escaped = URIStringUtils.escape(partName);
         return rvi + "/" + escaped;
-
     }
 
     public static boolean isValid(ReadGraph graph, Variable variable) {
@@ -627,7 +631,7 @@ final public class Variables {
                        }
                        
                        if (getter.exception != null)
-                               throw new DatabaseException(getter.exception);
+                               throw new MissingVariableValueException("No value for node " + node, getter.exception);
                        
                        return getter.result;
        }
@@ -671,7 +675,8 @@ final public class Variables {
 
     public static NodeStructure requestNodeStructure(ReadGraph graph, VariableNode<?> node) throws DatabaseException {
         NodeStructure value = graph.syncRequest(new NodeStructureRequest(node));
-        if (value == null) throw new DatabaseException("External data access error");
+        if (value == null)
+            throw new InvalidVariableException("External data access error " + String.valueOf(node));
        if(PENDING_NODE_STRUCTURE == value && graph.getSynchronous()) {
                // In this case a PENDING value was previously cached but now the value needs to be obtained for real.
                
@@ -680,13 +685,13 @@ final public class Variables {
                                node.support.manager.getRealm().syncExec(getter);
                        } catch (InterruptedException e) {
                                Logger.defaultLogError(e);
-                               throw new DatabaseException("External data access error", e);
+                               throw new InvalidVariableException("External data access error " + String.valueOf(node), e);
                        }
                        
                        if (getter.exception != null)
-                               throw new DatabaseException("External data access error", getter.exception);
+                               throw new InvalidVariableException("External data access error " + String.valueOf(node), getter.exception);
                        if (getter.result == null)
-                               throw new DatabaseException("External data access error");
+                               throw new InvalidVariableException("External data access error " + String.valueOf(node));
                        
                        return getter.result;
                
index 5a64bd010a6d792ed16bbc6c2c78090a62f97020..591361c9b0370af6fd420c39be96e5d6f26ca9f2 100644 (file)
@@ -18,25 +18,27 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 
 /**
- *
- * A base class for exceptions in org.simantics.db.
- * 
- * There are three classes of DatabaseException
- * <ul>
- * <li>ServiceException is a class of serious failures e.g. (connection failure, database corruption) 
- * <li>ValidationException is a class of exceptions due to invalid semantic graph 
- * <li>AssumptionException is a class of exceptions due to unsatisfied user assumptions (e.g. user assumes a single result or existence of an adapter)
- * </ul>
- * 
- * The resources related to an exception are available for pretty printing uses. 
- * 
- * @author Antti Villberg
- * @version 0.7
- * @see ValidationException
- * @see ServiceException
- * @see AssumptionException
- * 
- */
+*
+* A base class for exceptions in org.simantics.db.
+* 
+* There are three classes of DatabaseException
+* <ul>
+* <li>ServiceException is a class of serious failures e.g. (connection failure, database corruption) 
+* <li>ValidationException is a class of exceptions due to invalid semantic graph 
+* <li>AssumptionException is a class of exceptions due to unsatisfied user assumptions (e.g. user assumes a single result or existence of an adapter)
+* <li>VariableException is a class of exceptions related to Simantics Variable-interface operations
+* </ul>
+* 
+* The resources related to an exception are available for pretty printing uses. 
+* 
+* @author Antti Villberg
+* @version 0.7
+* @see ValidationException
+* @see ServiceException
+* @see AssumptionException
+* @see VariableException
+* 
+*/
 public class DatabaseException extends Exception {
 
     private static final long serialVersionUID = -6234485044648476711L;
diff --git a/bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java b/bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java
new file mode 100644 (file)
index 0000000..593c1fa
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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.db.exception;
+
+import org.simantics.db.Resource;
+
+/**
+ * @author Jani Simomaa
+ * @since 1.36.0
+ */
+public class DatatypeNotFoundException extends AssumptionException {
+
+    private static final long serialVersionUID = -5566773896759186602L;
+
+    public DatatypeNotFoundException(Throwable cause) {
+        super(cause);
+    }
+
+    public DatatypeNotFoundException(String message, Throwable cause, Resource... rs) {
+        super(message, cause, rs);
+    }
+
+    public DatatypeNotFoundException(String message, Resource... resources) {
+        super(message, resources);
+    }
+
+    public DatatypeNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DatatypeNotFoundException(String message, int... args) {
+        super(message, args);
+    }
+
+    public DatatypeNotFoundException(String message) {
+        super(message);
+    }
+
+}
similarity index 86%
rename from bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/VariableException.java
rename to bundles/org.simantics.db/src/org/simantics/db/exception/VariableException.java
index 4576391e9519f8ed79fd5aad3bc991e13b3a0dba..64b5b8d7ba59f3d42a3db5dd8557f1506bdc99ec 100644 (file)
@@ -9,11 +9,13 @@
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
  *******************************************************************************/
-package org.simantics.db.layer0.exception;
+package org.simantics.db.exception;
 
-import org.simantics.db.exception.DatabaseException;
-
-public class VariableException extends DatabaseException {
+/**
+ * @author Tuukka Lehtonen
+ *
+ */
+public abstract class VariableException extends DatabaseException {
 
     private static final long serialVersionUID = -1479596137621167295L;
 
index 9c55fdfec5766fdd7296eefb9091c01c4cec1269..ad8216d7599a17d428025cbec9860dec29394632 100644 (file)
@@ -18,7 +18,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.BinaryRead;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.exception.VariableException;
+import org.simantics.db.exception.VariableException;
 import org.simantics.db.layer0.variable.RVI;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
index 90ee3db2ffa3fb8e5a1928b1c479677d5e567944..3d04996120278e63de6270438ba8f1d722b9362b 100644 (file)
@@ -27,7 +27,7 @@ import org.simantics.db.common.request.PossibleIndexRoot;
 import org.simantics.db.common.request.PossibleObjectWithType;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.exception.VariableException;
+import org.simantics.db.exception.VariableException;
 import org.simantics.db.layer0.genericrelation.IndexQueries;
 import org.simantics.db.layer0.request.PossibleModel;
 import org.simantics.db.layer0.variable.RVI;
index b4b68a002ff4f360b0f30a1f9b7acbe366813aba..da1e7d8eb1385422eabf7ed98181fd440b5c06a2 100644 (file)
@@ -22,7 +22,7 @@ import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.AssumptionException;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.exception.VariableException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
 import org.simantics.db.layer0.request.VariableName;
 import org.simantics.db.layer0.request.VariableURI;
 import org.simantics.db.layer0.variable.Variable;
@@ -294,11 +294,13 @@ public class ScenegraphLoaderUtils {
        }
        
     public static Resource getRuntime(ReadGraph graph, Variable context) throws DatabaseException {
-       SceneGraphContext vc = getContext(graph, context);
-       if(vc != null) return vc.getRuntime();
-       Variable parent = context.getParent(graph);
-       if(parent == null) throw new DatabaseException("Runtime resource was not found from context Variable.");
-       return getRuntime(graph, parent);
+        SceneGraphContext vc = getContext(graph, context);
+        if (vc != null)
+            return vc.getRuntime();
+        Variable parent = context.getParent(graph);
+        if (parent == null)
+            throw new InvalidVariableException("Runtime resource was not found from context Variable. " + context.getURI(graph));
+        return getRuntime(graph, parent);
     }
     
     public static SceneGraphContext getContext(ReadGraph graph, Variable context) throws DatabaseException {
@@ -382,29 +384,25 @@ public class ScenegraphLoaderUtils {
        
     }
        
-       public static Variable getVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
-               
-               Variable runtimeVariable = getRuntimeVariable(graph, context);
-               if (runtimeVariable == null)
-                       throw new VariableException("no runtime variable for context " + context.getURI(graph));
-               return runtimeVariable.getPropertyValue(graph, "variable");
-               
-       }
-
-       public static Variable getPossibleVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
-           Variable runtimeVariable = getRuntimeVariable(graph, context);
-           return runtimeVariable == null ? null : (Variable) runtimeVariable.getPossiblePropertyValue(graph, "variable");
-       }
-
-       public static Resource getResourceSelection(ReadGraph graph, Variable context) throws DatabaseException {
+    public static Variable getVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
+        Variable runtimeVariable = getRuntimeVariable(graph, context);
+        if (runtimeVariable == null)
+            throw new InvalidVariableException("no runtime variable for context " + context.getURI(graph));
+        return runtimeVariable.getPropertyValue(graph, "variable");
+    }
 
-               Variable runtimeVariable = getRuntimeVariable(graph, context);
-               if (runtimeVariable == null)
-            throw new VariableException("no runtime variable for context " + context.getURI(graph));
-               Resource sel = runtimeVariable.getPropertyValue(graph, "resource"); 
-               return sel;
+    public static Variable getPossibleVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
+        Variable runtimeVariable = getRuntimeVariable(graph, context);
+        return runtimeVariable == null ? null : (Variable) runtimeVariable.getPossiblePropertyValue(graph, "variable");
+    }
 
-       }
+    public static Resource getResourceSelection(ReadGraph graph, Variable context) throws DatabaseException {
+        Variable runtimeVariable = getRuntimeVariable(graph, context);
+        if (runtimeVariable == null)
+            throw new InvalidVariableException("no runtime variable for context " + context.getURI(graph));
+        Resource sel = runtimeVariable.getPropertyValue(graph, "resource");
+        return sel;
+    }
        
        public static Resource getPossibleResourceSelection(ReadGraph graph, Variable context) throws DatabaseException {
 
index e3de813b46396a269272e648b822a133069e409b..4d6715dc5d57fd0635ed27e7cccd7d9f3db58767 100644 (file)
@@ -22,7 +22,6 @@ import org.simantics.databoard.binding.error.BindingException;
 import org.simantics.databoard.binding.mutable.MutableVariant;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.datatypes.utils.BTree;
-import org.simantics.datatypes.utils.BTreeUtils;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -30,8 +29,9 @@ import org.simantics.db.common.request.PossibleChild;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.AssumptionException;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.exception.VariableException;
+import org.simantics.db.exception.VariableException;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.layer0.variable.ProxyVariables;
 import org.simantics.db.layer0.variable.Variable;
@@ -48,8 +48,8 @@ import org.simantics.scl.runtime.function.Function1;
 import org.simantics.scl.runtime.tuple.Tuple;
 import org.simantics.spreadsheet.CellEditor;
 import org.simantics.spreadsheet.CellEditor.Transaction;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
 import org.simantics.spreadsheet.ClientModel;
+import org.simantics.spreadsheet.ClientModel.OperationMode;
 import org.simantics.spreadsheet.Range;
 import org.simantics.spreadsheet.common.TableCell;
 import org.simantics.spreadsheet.common.cell.StringCellParser;
@@ -660,7 +660,7 @@ public class SpreadsheetUtils {
        int w = 0; // name + fields 
        int h = 0; // number or rows excluding headers
        
-       if(columns < 2) throw new DatabaseException("organizeCells: number of columns needs to be greater than 1");
+       if(columns < 2) throw new AssumptionException("organizeCells: number of columns needs to be greater than 1");
        
        for(TableCell cell : cells) {
                if((cell.column+1)>w) w = cell.column+1;
index 8cf61b3e0ade8e4dc74ed2e44ca334d655a6ee0c..672edfca65c4bfc6995654fdd6b935e4cdb886e4 100644 (file)
@@ -127,16 +127,20 @@ public class StructuralRVIResolver extends StandardRVIResolver {
     @Override
     protected Variable resolveChild(ReadGraph graph, Variable variable, Resource resource) throws DatabaseException {
         Collection<Resource> path = getRVIPath(graph, variable, resource);
-        if(path == null) throw new MissingVariableException("Didn't find a variable related to " + resource + ".", resource);
-        for(Resource r : path) variable = variable.browse(graph, r);
+        if (path == null)
+            throw new MissingVariableException("Didn't find a variable related to " + resource + ".", resource);
+        for (Resource r : path)
+            variable = variable.browse(graph, r);
         return variable;
     }
-    
+
     @Override
     protected Variable resolveChild(ReadGraph graph, Variable variable, GuidRVIPart part) throws DatabaseException {
         Collection<Resource> path = getRVIPath(graph, variable, part);
-        if(path == null) throw new MissingVariableException("Didn't find a variable related to " + part + ".");
-        for(Resource r : path) variable = variable.browse(graph, r);
+        if (path == null)
+            throw new MissingVariableException("Didn't find a variable related to " + part + ".", variable.getPossibleRepresents(graph));
+        for (Resource r : path)
+            variable = variable.browse(graph, r);
         return variable;
     }