X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FVariables.java;h=610e0013c8cedb57cc118b73bebc5e2a6b4763aa;hb=fee871302ad4c53ca2c2307bd13366d99116d930;hp=5fb0636a08dec5e41a616b863c58bbb7fbbaa4df;hpb=0dc0aca2a1944a19ebece6c535386a8769e7871d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java index 5fb0636a0..610e0013c 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java @@ -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;