X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FFindComponentTypeRequest.java;h=c5a91596ef72886faf21a12fe932fb830d012d58;hb=04bf1d8e31c85530bcd47d41051362533997134e;hp=566a1384fb21bbedbc6fa800b932b6e5e7a3aeb0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/FindComponentTypeRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/FindComponentTypeRequest.java index 566a1384f..c5a91596e 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/FindComponentTypeRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/FindComponentTypeRequest.java @@ -1,38 +1,38 @@ -package org.simantics.structural2.scl; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ResourceRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.utils.datastructures.Pair; - -/** - * Given component finds a component type it belongs to - */ -public class FindComponentTypeRequest extends ResourceRead> { - - public FindComponentTypeRequest(Resource resource) { - super(resource); - } - - @Override - public Pair perform(ReadGraph graph) throws DatabaseException { - StructuralResource2 STR = StructuralResource2.getInstance(graph); - Resource type = graph.getPossibleObject(resource, STR.Defines); - if(type != null) - return Pair.make(type, 0); - - Layer0 L0 = Layer0.getInstance(graph); - Resource parent = graph.getPossibleObject(resource, L0.PartOf); - if(parent != null) { - Pair result = - graph.syncRequest(new FindComponentTypeRequest(parent)); - return Pair.make(result.first, result.second+1); - } - - throw new DatabaseException("Unexpected graph structure at " + resource + "."); - } - -} +package org.simantics.structural2.scl; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.utils.datastructures.Pair; + +/** + * Given component finds a component type it belongs to + */ +public class FindComponentTypeRequest extends ResourceRead> { + + public FindComponentTypeRequest(Resource resource) { + super(resource); + } + + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource type = graph.getPossibleObject(resource, STR.Defines); + if(type != null) + return Pair.make(type, 0); + + Layer0 L0 = Layer0.getInstance(graph); + Resource parent = graph.getPossibleObject(resource, L0.PartOf); + if(parent != null) { + Pair result = + graph.syncRequest(new FindComponentTypeRequest(parent)); + return Pair.make(result.first, result.second+1); + } + + throw new DatabaseException("Unexpected graph structure at " + resource + "."); + } + +}