1 package org.simantics.db.layer0.request;
3 import org.simantics.databoard.util.URIStringUtils;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.common.request.UnaryRead;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.variable.StandardGraphChildVariable;
8 import org.simantics.db.layer0.variable.Variable;
9 import org.simantics.db.request.ReadExt;
10 import org.simantics.db.request.RequestFlags;
12 public class ResourceURIToVariable extends UnaryRead<String, Variable> implements ReadExt {
14 public ResourceURIToVariable(String uri) {
18 public static int split(String uri) {
19 int pos = uri.lastIndexOf(URIStringUtils.NAMESPACE_PATH_SEPARATOR);
20 int pos2 = uri.lastIndexOf(URIStringUtils.NAMESPACE_LOCAL_SEPARATOR);
21 return Math.max(pos, pos2);
25 public Variable perform(ReadGraph graph) throws DatabaseException {
27 if("http://".equals(parameter) || "http:/".equals(parameter)) {
28 return new StandardGraphChildVariable(null, null, graph.getRootLibrary());
30 int childPos = parameter.lastIndexOf(URIStringUtils.NAMESPACE_PATH_SEPARATOR);
31 int propertyPos = parameter.lastIndexOf(URIStringUtils.NAMESPACE_LOCAL_SEPARATOR);
32 if(childPos > propertyPos) {
33 Variable parent = graph.syncRequest(new ResourceURIToVariable(parameter.substring(0, childPos)));
34 return parent.getChild(graph, URIStringUtils.unescape(parameter.substring(childPos + 1, parameter.length())));
36 Variable parent = graph.syncRequest(new ResourceURIToVariable(parameter.substring(0, propertyPos)));
37 return parent.getProperty(graph, URIStringUtils.unescape(parameter.substring(propertyPos + 1, parameter.length())));
44 public boolean isImmutable(ReadGraph graph) throws DatabaseException {
49 public int getType() {
50 return RequestFlags.IMMEDIATE_UPDATE;