-/*******************************************************************************\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.layer0.utils.direct;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.db.request.Read;\r
-\r
-public class ExceptionUtils {\r
- \r
- public static <T> void decipher(AsyncReadGraph graph, Throwable throwable, final AsyncProcedure<T> procedure) {\r
-\r
- if(throwable instanceof DatabaseException) {\r
-\r
- System.out.println("decipher " + throwable);\r
- \r
- final DatabaseException e = (DatabaseException)throwable;\r
- \r
- Collection<Resource> resources = e.getResources();\r
- if(resources != null) {\r
-\r
- graph.asyncRequest(new Read<ArrayList<String>>() {\r
- \r
- @Override\r
- public ArrayList<String> perform(ReadGraph graph) throws DatabaseException {\r
- \r
- Collection<Resource> resources = e.getResources();\r
- ArrayList<String> names = new ArrayList<String>();\r
- \r
- for(Resource r : resources) {\r
- names.add(NameUtils.getSafeName(graph, r));\r
- }\r
- \r
- return names;\r
- \r
- }\r
- \r
- }, new AsyncProcedure<ArrayList<String>>() {\r
- \r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- procedure.exception(graph, throwable);\r
- }\r
- \r
- @Override\r
- public void execute(AsyncReadGraph graph, ArrayList<String> names) {\r
- e.setNames(names);\r
- procedure.exception(graph, e);\r
- }\r
- \r
- });\r
- \r
- } else {\r
- \r
- procedure.exception(graph, throwable);\r
-\r
- }\r
- \r
- } else {\r
- \r
- procedure.exception(graph, throwable);\r
-\r
- }\r
- \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.layer0.utils.direct;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.Read;
+
+public class ExceptionUtils {
+
+ public static <T> void decipher(AsyncReadGraph graph, Throwable throwable, final AsyncProcedure<T> procedure) {
+
+ if(throwable instanceof DatabaseException) {
+
+ System.out.println("decipher " + throwable);
+
+ final DatabaseException e = (DatabaseException)throwable;
+
+ Collection<Resource> resources = e.getResources();
+ if(resources != null) {
+
+ graph.asyncRequest(new Read<ArrayList<String>>() {
+
+ @Override
+ public ArrayList<String> perform(ReadGraph graph) throws DatabaseException {
+
+ Collection<Resource> resources = e.getResources();
+ ArrayList<String> names = new ArrayList<String>();
+
+ for(Resource r : resources) {
+ names.add(NameUtils.getSafeName(graph, r));
+ }
+
+ return names;
+
+ }
+
+ }, new AsyncProcedure<ArrayList<String>>() {
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ procedure.exception(graph, throwable);
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, ArrayList<String> names) {
+ e.setNames(names);
+ procedure.exception(graph, e);
+ }
+
+ });
+
+ } else {
+
+ procedure.exception(graph, throwable);
+
+ }
+
+ } else {
+
+ procedure.exception(graph, throwable);
+
+ }
+
+ }
+
+}