From: jsimomaa Date: Tue, 18 Dec 2018 13:26:44 +0000 (+0200) Subject: Do not compute replaceable type for non ReplaceableDefinedComponentTypes X-Git-Tag: v1.43.0~136^2~220 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=7e1ba415e6f14478c2aa682a89ed534e7044ac43;p=simantics%2Fplatform.git Do not compute replaceable type for non ReplaceableDefinedComponentTypes gitlab #240 Change-Id: Ia982e16172698e855eac2845be0304363c9987f7 --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java index 00b01cca6..110ed2f77 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java @@ -966,7 +966,7 @@ public abstract class AbstractVariable implements Variable { Resource typeFromFunction = getTypeFromPossibleTypeFunction(graph, Layer0.getInstance(graph).Entity, getPossibleTypeFunction(graph)); if (typeFromFunction != null) return typeFromFunction; - } catch (Throwable t) { + } catch (DatabaseException t) { return null; } @@ -1002,7 +1002,7 @@ public abstract class AbstractVariable implements Variable { Resource typeFromFunction = getTypeFromPossibleTypeFunction(graph, baseType, getPossibleTypeFunction(graph)); if (typeFromFunction != null) return typeFromFunction; - } catch (Throwable t) { + } catch (DatabaseException t) { return null; } diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java index f3f9344aa..9b5fc4586 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java @@ -23,12 +23,14 @@ import org.simantics.db.Resource; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; import org.simantics.db.common.issue.StandardIssue; +import org.simantics.db.common.primitiverequest.IsInstanceOf; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.request.TernaryRead; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.function.All; @@ -54,6 +56,7 @@ import org.simantics.layer0.Layer0; import org.simantics.scl.reflection.annotations.SCLValue; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.tuple.Tuple2; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.simulator.variable.NodeManager; import org.simantics.structural.stubs.StructuralResource2; @@ -499,31 +502,48 @@ public class Functions { } } - + + private static class StructuralOverrideDataWalkRequest + extends TernaryRead { + + public StructuralOverrideDataWalkRequest(Variable component, Resource actualRepresents, Resource actualType) { + super(component, actualRepresents, actualType); + } + + @Override + public StructuralOverrideData perform(ReadGraph graph) throws DatabaseException { + Variable component = parameter; + Resource actualRepresents = parameter2; + Resource actualType = parameter3; +// System.err.println(component.getURI(graph)); + Resource represents = component.getPossibleRepresents(graph); + if (represents != null) { + Layer0 L0 = Layer0.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource container = graph + .syncRequest(new PossibleObjectWithType(represents, L0.PartOf, STR.Composite)); + if (container != null) { + Map overrides = graph.syncRequest(new StructuralTypeOverrideMap(container), TransientCacheListener.instance()); + Resource override = overrides.get(actualType); + if (override != null) { + return new StructuralOverrideData(actualRepresents, actualType, override); + } + } + } + Variable parent = component.getParent(graph); + if (parent == null) + return new StructuralOverrideData(actualRepresents, actualType, null); + else + return graph.syncRequest(new StructuralOverrideDataWalkRequest(parent, represents, actualType), TransientCacheListener.instance()); + } + + } + public static class StructuralOverrideDataRequest extends VariableRead { public StructuralOverrideDataRequest(Variable component) { super(component); } - - public StructuralOverrideData walk(ReadGraph graph, Variable component, Resource actualRepresents, Resource actualType) throws DatabaseException { - Resource represents = component.getPossibleRepresents(graph); - if(represents != null) { - Layer0 L0 = Layer0.getInstance(graph); - StructuralResource2 STR = StructuralResource2.getInstance(graph); - Resource container = graph.syncRequest(new PossibleObjectWithType(represents, L0.PartOf, STR.Composite)); - if(container != null) { - Map overrides = graph.syncRequest(new StructuralTypeOverrideMap(container)); - Resource override = overrides.get(actualType); - if(override != null) { - return new StructuralOverrideData(actualRepresents, actualType, override); - } - } - } - Variable parent = component.getParent(graph); - if(parent == null) return new StructuralOverrideData(actualRepresents, actualType, null); - else return walk(graph, parent, represents, actualType); - } @Override public StructuralOverrideData perform(ReadGraph graph) throws DatabaseException { @@ -532,45 +552,75 @@ public class Functions { if(represents == null) { String uri = variable.getPossiblePropertyValue(graph, "typeURI"); if(uri != null) { - Resource actualType = graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.instance()); - return walk(graph, variable, null, actualType); + Resource actualType = graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.instance()); + if (graph.syncRequest(new IsInstanceOf(actualType, StructuralResource2.getInstance(graph).ReplaceableDefinedComponentType), TransientCacheListener.instance()) ) { + return graph.syncRequest(new StructuralOverrideDataWalkRequest(variable, null, actualType), TransientCacheListener.instance()); + } else { + // can not have replaceable type + return null; + } } throw new DatabaseException("No type for " + variable.getURI(graph)); } else { - return walk(graph, variable, represents, graph.getPossibleType(represents, Layer0.getInstance(graph).Entity)); + Resource possibleType = graph.getPossibleType(represents, Layer0.getInstance(graph).Entity); + if (graph.syncRequest(new IsInstanceOf(possibleType, StructuralResource2.getInstance(graph).ReplaceableDefinedComponentType), TransientCacheListener.instance()) ) { + return graph.syncRequest(new StructuralOverrideDataWalkRequest(variable, represents, possibleType), TransientCacheListener.instance()); + } else { + return null; + } } } } - + + private static class StructureTypeAndChildMapRequest extends ResourceRead { + + protected StructureTypeAndChildMapRequest(Resource resource) { + super(resource); + } + + @Override + public Tuple2 perform(ReadGraph graph) throws DatabaseException { + StructuralComponentClass clazz = StructuralComponentClass.get(graph, resource); + if (StructuralComponentClass.DEFINED.equals(clazz)) { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource def = graph.getSingleObject(resource, STR.IsDefinedBy); + Map children = graph.syncRequest(new UnescapedChildMapOfResource(def), TransientCacheListener.instance()); + return new Tuple2(clazz, children); + } + return new Tuple2(clazz, null); + } + + } + @SCLValue(type = "VariableMap") public static VariableMap structuralChildDomainChildren = new VariableMapImpl() { - + @Override public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException { Resource type = context.getPossibleType(graph); if(type == null) return null; + + Tuple2 result = graph.syncRequest(new StructureTypeAndChildMapRequest(type), TransientCacheListener.instance()); + StructuralComponentClass clazz = (StructuralComponentClass) result.c0; - StructuralComponentClass clazz = StructuralComponentClass.get(graph, type); if(StructuralComponentClass.PROCEDURAL.equals(clazz)) { Map map = graph.syncRequest(new ProceduralSubstructureRequest(context), TransientCacheListener.>instance()); if(map != null) return map.get(name); return null; } else if (StructuralComponentClass.DEFINED.equals(clazz)) { - StructuralResource2 STR = StructuralResource2.getInstance(graph); - Resource def = graph.getSingleObject(type, STR.IsDefinedBy); - Map children = graph.syncRequest(new UnescapedChildMapOfResource(def)); + Map children = (Map) result.c1; Resource child = children.get(name); if(child == null) return null; return StandardChildDomainChildren.getStandardChildDomainChildVariable(graph, context, child, name); } else { Resource represents = context.getPossibleRepresents(graph); if(represents == null) return null; - Map children = graph.syncRequest(new UnescapedChildMapOfResource(represents)); + Map children = graph.syncRequest(new UnescapedChildMapOfResource(represents), TransientCacheListener.instance()); Resource child = children.get(name); return StandardChildDomainChildren.getStandardChildDomainChildVariable(graph, context, child, name); } @@ -599,7 +649,7 @@ public class Functions { } else if (StructuralComponentClass.DEFINED.equals(clazz)) { StructuralResource2 STR = StructuralResource2.getInstance(graph); Resource def = graph.getSingleObject(type, STR.IsDefinedBy); - Map children = graph.syncRequest(new UnescapedChildMapOfResource(def)); + Map children = graph.syncRequest(new UnescapedChildMapOfResource(def), TransientCacheListener.instance()); return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, context, children, map); } else { Resource represents = context.getPossibleRepresents(graph); @@ -812,7 +862,7 @@ public class Functions { } - final Collection interfaces = graph.syncRequest(new DefinedUCInterfaceMap(type)); + final Collection interfaces = graph.syncRequest(new DefinedUCInterfaceMap(type), TransientCacheListener.instance()); if(interfaces != null) return interfaces; } diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java index c5b0087e2..e27d92f29 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java @@ -325,7 +325,9 @@ public class StructuralUtils { public static Resource structuralTypeResource(ReadGraph graph, Variable component, Resource baseType) throws DatabaseException { StructuralOverrideData od = StructuralOverrideData.compute(graph, component); - return od.type(); + if (od != null) + return od.type(); + return null; } public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException {