+ 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);
+ }
+ }
+ }
+