import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.simantics.db.common.procedure.adapter.DirectStatementProcedure;
import org.simantics.db.common.request.IsParent;
import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.PossibleChild;
import org.simantics.db.common.request.PossibleObjectWithType;
import org.simantics.db.common.request.PossibleOwner;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.request.RuntimeEnvironmentRequest;
+import org.simantics.db.exception.AdaptionException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.InvalidResourceReferenceException;
import org.simantics.db.service.ClusterUID;
import org.simantics.db.service.SerialisationSupport;
import org.simantics.db.service.XSupport;
import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
+import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
+import org.simantics.scl.compiler.types.Type;
import org.simantics.utils.datastructures.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return xs.isClusterLoaded(clusterUID);
}
-
+ public static void setImmutable(ReadGraph graph, Resource resource, boolean value) throws DatabaseException {
+ XSupport xs = graph.getService(XSupport.class);
+ xs.setImmutable(resource, value);
+ }
+
+ public static Type getSCLType(ReadGraph graph, RuntimeEnvironment runtimeEnvironment, String typeText) throws DatabaseException {
+ try {
+ return Environments.getType(runtimeEnvironment.getEnvironment(), typeText);
+ } catch (SCLExpressionCompilationException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
+ public static Type getSCLType(ReadGraph graph, Resource resource, String typeText) throws DatabaseException {
+ try {
+ RuntimeEnvironment runtimeEnvironment = graph.syncRequest(new RuntimeEnvironmentRequest(resource));
+ return Environments.getType(runtimeEnvironment.getEnvironment(), typeText);
+ } catch (SCLExpressionCompilationException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
+ public static Resource getPossibleChild(ReadGraph graph, Resource resource, String name) throws DatabaseException {
+ return graph.sync(new PossibleChild(resource, name));
+ }
+
+ public static Resource getPossibleChild(ReadGraph graph, Resource resource, Resource type, String name) throws DatabaseException {
+ Resource child = graph.sync(new PossibleChild(resource, name));
+ if(child == null) return null;
+ if(!graph.isInstanceOf(child, type)) return null;
+ return child;
+ }
+
+ public static String getEnumerationValueName(ReadGraph graph, Resource resource) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ String label = graph.getPossibleRelatedValue(resource, L0.HasLabel, Bindings.STRING);
+ if(label != null)
+ return label;
+ return safeName(graph, resource);
+ }
+
+ private static String safeName(ReadGraph graph, Resource value) throws DatabaseException {
+ return graph.syncRequest(new StringAdapterRequest(value));
+ }
+
+ public static class StringAdapterRequest extends ResourceRead<String> {
+ public StringAdapterRequest(Resource resource) {
+ super(resource);
+ }
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ try {
+ return graph.adapt(resource, String.class);
+ } catch (AdaptionException e) {
+ return NameUtils.getSafeName(graph, resource);
+ }
+ }
+ }
+
}