]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ExtendedUris.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / ExtendedUris.java
index 2070c4916ee425b4f0676df5c44a958745a0a6a2..3ccdd691854cc3bd2b961a1b1009fb4180dfa631 100644 (file)
@@ -1,84 +1,84 @@
-package org.simantics.db.layer0.util;\r
-\r
-import java.util.Collection;\r
-\r
-import org.simantics.databoard.util.URIStringUtils;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.common.request.FunctionalStatementMapOfResource;\r
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.scl.runtime.tuple.Tuple2;\r
-\r
-public class ExtendedUris {\r
-\r
-    public static Resource resolveAbsoluteUri(ReadGraph graph, String uri) throws DatabaseException {\r
-        if(!uri.startsWith("http:/"))\r
-            throw new IllegalArgumentException("Invalid absolute URI '" + uri + "'.");\r
-        return resolveRelativeUri(graph, graph.getRootLibrary(), uri.substring(6));\r
-    }\r
-\r
-    public static Resource resolveRelativeUri(ReadGraph graph, Resource parent, String uri) throws DatabaseException {\r
-        int beginPos = 0;\r
-        while(beginPos < uri.length()) {\r
-            int endPos;\r
-            for(endPos = beginPos+1; endPos < uri.length(); ++endPos) {\r
-                char c = uri.charAt(endPos);\r
-                if(c == '/' || c == '#')\r
-                    break;\r
-            }\r
-\r
-            char c = uri.charAt(beginPos);\r
-            if(c == '/') {\r
-                String escapedName = uri.substring(beginPos+1, endPos);\r
-                String name = URIStringUtils.unescape(escapedName);\r
-                parent = graph.syncRequest(new UnescapedChildMapOfResource(parent)).get(name);\r
-                if(parent == null)\r
-                    throw new DatabaseException("Didn't find a child " + name);\r
-            }\r
-            else if(c == '#') {\r
-                String escapedName = uri.substring(beginPos+1, endPos);\r
-                String name = URIStringUtils.unescape(escapedName);\r
-                parent = graph.syncRequest(new FunctionalStatementMapOfResource(parent)).get(name);\r
-                if(parent == null)\r
-                    throw new DatabaseException("Didn't find a property " + name);\r
-            }\r
-            else\r
-                throw new IllegalArgumentException("Invalid relative URI '" + uri + "'.");\r
-            beginPos = endPos;\r
-        }\r
-        return parent;\r
-    }\r
-    \r
-    private static boolean initialized = false;\r
-    private static Resource ElementToComponent;\r
-    private static void initialize(ReadGraph graph) throws DatabaseException {\r
-        ElementToComponent = graph.getResource("http://www.simantics.org/Modeling-1.2/ElementToComponent");\r
-        initialized = true;\r
-    }\r
-    \r
-    public static Tuple2 getPrimaryFunctionalReference(ReadGraph graph, Resource r) throws DatabaseException {\r
-        if(!initialized)\r
-            initialize(graph);\r
-        Statement stat = graph.getPossibleStatement(r, ElementToComponent);\r
-        if(stat != null)\r
-            return statementToResult(graph, stat);\r
-        return null;\r
-    }\r
-    \r
-    public static Tuple2 getSecondaryFunctionalReference(ReadGraph graph, Resource r) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        Collection<Statement> statements = graph.getStatements(r, L0.PropertyOf);\r
-        if(statements.size() == 1) \r
-            for(Statement stat : statements)\r
-                return statementToResult(graph, stat);\r
-        return null;\r
-    }\r
-    \r
-    private static Tuple2 statementToResult(ReadGraph graph, Statement stat) throws DatabaseException {\r
-        return new Tuple2(stat.getObject(), graph.getInverse(stat.getPredicate()));\r
-    }\r
-\r
-}\r
+package org.simantics.db.layer0.util;
+
+import java.util.Collection;
+
+import org.simantics.databoard.util.URIStringUtils;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.request.FunctionalStatementMapOfResource;
+import org.simantics.db.common.uri.UnescapedChildMapOfResource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.scl.runtime.tuple.Tuple2;
+
+public class ExtendedUris {
+
+    public static Resource resolveAbsoluteUri(ReadGraph graph, String uri) throws DatabaseException {
+        if(!uri.startsWith("http:/"))
+            throw new IllegalArgumentException("Invalid absolute URI '" + uri + "'.");
+        return resolveRelativeUri(graph, graph.getRootLibrary(), uri.substring(6));
+    }
+
+    public static Resource resolveRelativeUri(ReadGraph graph, Resource parent, String uri) throws DatabaseException {
+        int beginPos = 0;
+        while(beginPos < uri.length()) {
+            int endPos;
+            for(endPos = beginPos+1; endPos < uri.length(); ++endPos) {
+                char c = uri.charAt(endPos);
+                if(c == '/' || c == '#')
+                    break;
+            }
+
+            char c = uri.charAt(beginPos);
+            if(c == '/') {
+                String escapedName = uri.substring(beginPos+1, endPos);
+                String name = URIStringUtils.unescape(escapedName);
+                parent = graph.syncRequest(new UnescapedChildMapOfResource(parent)).get(name);
+                if(parent == null)
+                    throw new DatabaseException("Didn't find a child " + name);
+            }
+            else if(c == '#') {
+                String escapedName = uri.substring(beginPos+1, endPos);
+                String name = URIStringUtils.unescape(escapedName);
+                parent = graph.syncRequest(new FunctionalStatementMapOfResource(parent)).get(name);
+                if(parent == null)
+                    throw new DatabaseException("Didn't find a property " + name);
+            }
+            else
+                throw new IllegalArgumentException("Invalid relative URI '" + uri + "'.");
+            beginPos = endPos;
+        }
+        return parent;
+    }
+    
+    private static boolean initialized = false;
+    private static Resource ElementToComponent;
+    private static void initialize(ReadGraph graph) throws DatabaseException {
+        ElementToComponent = graph.getResource("http://www.simantics.org/Modeling-1.2/ElementToComponent");
+        initialized = true;
+    }
+    
+    public static Tuple2 getPrimaryFunctionalReference(ReadGraph graph, Resource r) throws DatabaseException {
+        if(!initialized)
+            initialize(graph);
+        Statement stat = graph.getPossibleStatement(r, ElementToComponent);
+        if(stat != null)
+            return statementToResult(graph, stat);
+        return null;
+    }
+    
+    public static Tuple2 getSecondaryFunctionalReference(ReadGraph graph, Resource r) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        Collection<Statement> statements = graph.getStatements(r, L0.PropertyOf);
+        if(statements.size() == 1) 
+            for(Statement stat : statements)
+                return statementToResult(graph, stat);
+        return null;
+    }
+    
+    private static Tuple2 statementToResult(ReadGraph graph, Statement stat) throws DatabaseException {
+        return new Tuple2(stat.getObject(), graph.getInverse(stat.getPredicate()));
+    }
+
+}