]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/uri/URIToResource.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / uri / URIToResource.java
index d8e15391219ecdd54d0f286576aaf9eb1d2b071f..cd5fb954d7aa43c85a03cc1d6cead40208f4be2f 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.common.uri;\r
-\r
-import java.util.Arrays;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.Queries;\r
-import org.simantics.db.exception.ResourceNotFoundException;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.db.request.AsyncRead;\r
-\r
-/**\r
- * TODO: should this be considered deprecated and favor {@link Queries#resource(String)} ?\r
- */\r
-public class URIToResource implements AsyncRead<Resource> {\r
-       String[] nameSequence;\r
-       \r
-       public URIToResource(String[] nameSequence) {\r
-               this.nameSequence = nameSequence;\r
-       }\r
-       \r
-       public URIToResource(String uri) {\r
-               this.nameSequence = URIEscape.splitURI(uri);\r
-       }\r
-\r
-       @Override\r
-       public void perform(AsyncReadGraph g, final AsyncProcedure<Resource> procedure) {\r
-               if(nameSequence.length == 0)\r
-                       procedure.execute(g, g.getRootLibrary());\r
-               else\r
-                       g.asyncRequest(new URIToResource(Arrays.copyOf(nameSequence, nameSequence.length-1)),\r
-                               new AsyncProcedure<Resource>() {\r
-\r
-                                       @Override\r
-                                       public void execute(AsyncReadGraph g, Resource result) {\r
-                                               g.asyncRequest(new EscapedChildMapOfResource(result),\r
-                                                       new AsyncProcedure<Map<String, Resource>>() {\r
-\r
-                                                               @Override\r
-                                                               public void execute(AsyncReadGraph g, Map<String, Resource> map) {\r
-                                                                       Resource r = map.get(nameSequence[nameSequence.length-1]);\r
-                                                                       if(r != null)\r
-                                                                               procedure.execute(g, r);\r
-                                                                       else\r
-                                                                               procedure.exception(g, new ResourceNotFoundException(\r
-                                                                                               URIEscape.joinURI(nameSequence)));\r
-                                                               }\r
-                                                       \r
-                                                               @Override\r
-                                                               public void exception(AsyncReadGraph g, Throwable t) {\r
-                                                                       procedure.exception(g, t);                                                                                                                      \r
-                                                               }\r
-                                                       \r
-                                                       }\r
-                                               );\r
-                                       }\r
-                               \r
-                                       @Override\r
-                                       public void exception(AsyncReadGraph g, Throwable t) {\r
-                                               procedure.exception(g, t);                                              \r
-                                       }\r
-                               \r
-                               }\r
-                       );\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public int hashCode() {\r
-               return Arrays.hashCode(nameSequence);\r
-       }\r
-\r
-    @Override\r
-    public int threadHash() {\r
-       return hashCode();\r
-    }\r
-\r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if(this == obj)\r
-                       return true;\r
-               if(!(obj instanceof URIToResource))\r
-                       return false;\r
-               return Arrays.equals(nameSequence, ((URIToResource)obj).nameSequence);\r
-       }\r
-    \r
-    @Override\r
-    public int getFlags() {\r
-        return 0;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.uri;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.Queries;
+import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.AsyncRead;
+
+/**
+ * TODO: should this be considered deprecated and favor {@link Queries#resource(String)} ?
+ */
+public class URIToResource implements AsyncRead<Resource> {
+       String[] nameSequence;
+       
+       public URIToResource(String[] nameSequence) {
+               this.nameSequence = nameSequence;
+       }
+       
+       public URIToResource(String uri) {
+               this.nameSequence = URIEscape.splitURI(uri);
+       }
+
+       @Override
+       public void perform(AsyncReadGraph g, final AsyncProcedure<Resource> procedure) {
+               if(nameSequence.length == 0)
+                       procedure.execute(g, g.getRootLibrary());
+               else
+                       g.asyncRequest(new URIToResource(Arrays.copyOf(nameSequence, nameSequence.length-1)),
+                               new AsyncProcedure<Resource>() {
+
+                                       @Override
+                                       public void execute(AsyncReadGraph g, Resource result) {
+                                               g.asyncRequest(new EscapedChildMapOfResource(result),
+                                                       new AsyncProcedure<Map<String, Resource>>() {
+
+                                                               @Override
+                                                               public void execute(AsyncReadGraph g, Map<String, Resource> map) {
+                                                                       Resource r = map.get(nameSequence[nameSequence.length-1]);
+                                                                       if(r != null)
+                                                                               procedure.execute(g, r);
+                                                                       else
+                                                                               procedure.exception(g, new ResourceNotFoundException(
+                                                                                               URIEscape.joinURI(nameSequence)));
+                                                               }
+                                                       
+                                                               @Override
+                                                               public void exception(AsyncReadGraph g, Throwable t) {
+                                                                       procedure.exception(g, t);                                                                                                                      
+                                                               }
+                                                       
+                                                       }
+                                               );
+                                       }
+                               
+                                       @Override
+                                       public void exception(AsyncReadGraph g, Throwable t) {
+                                               procedure.exception(g, t);                                              
+                                       }
+                               
+                               }
+                       );
+               
+       }
+       
+       @Override
+       public int hashCode() {
+               return Arrays.hashCode(nameSequence);
+       }
+
+    @Override
+    public int threadHash() {
+       return hashCode();
+    }
+
+       @Override
+       public boolean equals(Object obj) {
+               if(this == obj)
+                       return true;
+               if(!(obj instanceof URIToResource))
+                       return false;
+               return Arrays.equals(nameSequence, ((URIToResource)obj).nameSequence);
+       }
+    
+    @Override
+    public int getFlags() {
+        return 0;
+    }
+
+}