1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.layer0.utils.direct;
14 import java.util.ArrayList;
15 import java.util.Collection;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.utils.NameUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.procedure.AsyncProcedure;
23 import org.simantics.db.request.Read;
25 public class ExceptionUtils {
27 public static <T> void decipher(AsyncReadGraph graph, Throwable throwable, final AsyncProcedure<T> procedure) {
29 if(throwable instanceof DatabaseException) {
31 System.out.println("decipher " + throwable);
33 final DatabaseException e = (DatabaseException)throwable;
35 Collection<Resource> resources = e.getResources();
36 if(resources != null) {
38 graph.asyncRequest(new Read<ArrayList<String>>() {
41 public ArrayList<String> perform(ReadGraph graph) throws DatabaseException {
43 Collection<Resource> resources = e.getResources();
44 ArrayList<String> names = new ArrayList<String>();
46 for(Resource r : resources) {
47 names.add(NameUtils.getSafeName(graph, r));
54 }, new AsyncProcedure<ArrayList<String>>() {
57 public void exception(AsyncReadGraph graph, Throwable throwable) {
58 procedure.exception(graph, throwable);
62 public void execute(AsyncReadGraph graph, ArrayList<String> names) {
64 procedure.exception(graph, e);
71 procedure.exception(graph, throwable);
77 procedure.exception(graph, throwable);