package org.simantics.db.layer0.exception;
+import org.simantics.db.exception.VariableException;
+
/**
* @author Tuukka Lehtonen
*/
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;
}
import org.simantics.db.ReadGraph;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.VariableException;
public class MissingVariableValueException extends VariableException {
*******************************************************************************/
package org.simantics.db.layer0.exception;
+import org.simantics.db.exception.VariableException;
import org.simantics.db.layer0.variable.Variable;
/**
package org.simantics.db.layer0.exception;
import org.simantics.db.Resource;
+import org.simantics.db.exception.VariableException;
public class PendingVariableException extends VariableException {
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;
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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;
}
@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.");
}
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 {
}
@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
@Override
public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {
- throw new DatabaseException("PropertyInfo is not available");
+ throw new InvalidVariableException("PropertyInfo is not available");
}
@Override
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 {
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 {
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();
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;
}
@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);
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);
}
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);
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);
}
}
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;
}
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;
}
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 '#': {
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 '/': {
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));
}
}
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;
}
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);
}
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
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 {
@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
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);
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;
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);
}
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);
}
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);
}
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);
}
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);
}
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;
@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);
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;
@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);
}
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;
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);
}
@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);
}
}
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();
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 {
return child;
}
}
- throw new DatabaseException("Could not resolve property " + part);
+ throw new MissingVariableException("Could not resolve property " + part, variable.getPossibleRepresents(graph));
}
@Override
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));
}
}
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;
@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
@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
@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
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
@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
@Override
public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException {
- throw new DatabaseException("not supported");
+ throw new InvalidVariableException("not supported");
}
@Override
@Override
public String getLabel(ReadGraph graph) throws DatabaseException {
- throw new DatabaseException("not supported");
+ throw new InvalidVariableException("not supported");
}
@Override
@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
@Override
public Resource getRepresents(ReadGraph graph) throws DatabaseException {
- throw new DatabaseException("no resource representation");
+ throw new InvalidVariableException("no resource representation");
}
@Override
@Override
public Resource getType(ReadGraph graph) throws DatabaseException {
- throw new DatabaseException("not supported");
+ throw new InvalidVariableException("not supported");
}
@Override
@Override
public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
- throw new DatabaseException("not supported");
+ throw new InvalidVariableException("not supported");
}
@Override
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();
}
}
-
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;
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;
}
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());
}
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);
}
}
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) {
}
if (getter.exception != null)
- throw new DatabaseException(getter.exception);
+ throw new MissingVariableValueException("No value for node " + node, getter.exception);
return getter.result;
}
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.
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;
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;
--- /dev/null
+/*******************************************************************************
+ * 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);
+ }
+
+}
* 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;
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;
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;
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;
}
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 {
}
- 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 {
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;
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;
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;
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;
@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;
}