]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ResourceURIToVariable.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / ResourceURIToVariable.java
1 package org.simantics.db.layer0.request;
2
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;
11
12 public class ResourceURIToVariable extends UnaryRead<String, Variable> implements ReadExt {
13
14         public ResourceURIToVariable(String uri) {
15                 super(uri);
16         }
17         
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);
22     }
23         
24         @Override
25         public Variable perform(ReadGraph graph) throws DatabaseException {
26                 
27         if("http://".equals(parameter) || "http:/".equals(parameter)) {
28                 return new StandardGraphChildVariable(null, null, graph.getRootLibrary());
29         } else {
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())));
35             } else {
36                 Variable parent = graph.syncRequest(new ResourceURIToVariable(parameter.substring(0, propertyPos)));
37                 return parent.getProperty(graph, URIStringUtils.unescape(parameter.substring(propertyPos + 1, parameter.length())));
38             }
39         }
40         
41         }
42
43         @Override
44         public boolean isImmutable(ReadGraph graph) throws DatabaseException {
45                 return false;
46         }
47
48         @Override
49         public int getType() {
50                 return RequestFlags.IMMEDIATE_UPDATE;
51         }
52
53 }