-/*******************************************************************************\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.exception;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-\r
-/**\r
- *\r
- * A base class for exceptions in org.simantics.db.\r
- * \r
- * There are three classes of DatabaseException\r
- * <ul>\r
- * <li>ServiceException is a class of serious failures e.g. (connection failure, database corruption) \r
- * <li>ValidationException is a class of exceptions due to invalid semantic graph \r
- * <li>AssumptionException is a class of exceptions due to unsatisfied user assumptions (e.g. user assumes a single result or existence of an adapter)\r
- * </ul>\r
- * \r
- * The resources related to an exception are available for pretty printing uses. \r
- * \r
- * @author Antti Villberg\r
- * @version 0.7\r
- * @see ValidationException\r
- * @see ServiceException\r
- * @see AssumptionException\r
- * \r
- */\r
-public class DatabaseException extends Exception {\r
-\r
- private static final long serialVersionUID = -6234485044648476711L;\r
-\r
- private ArrayList<Resource> resources;\r
- private ArrayList<String> names;\r
- private ArrayList<Integer> indices;\r
- \r
- public DatabaseException() {\r
- super();\r
- }\r
-\r
- public DatabaseException(String message, Throwable cause) {\r
- super(message, cause);\r
- }\r
-\r
- public DatabaseException(String message, Throwable cause, Resource ... rs) {\r
- super(message, cause);\r
- resources = new ArrayList<Resource>();\r
- for(Resource r : rs) resources.add(r); \r
- }\r
-\r
- public DatabaseException(Throwable cause, Resource ... rs) {\r
- super(cause);\r
- resources = new ArrayList<Resource>();\r
- for(Resource r : rs) resources.add(r); \r
- }\r
-\r
- public DatabaseException(String message, Resource ... rs) {\r
- super(message);\r
- resources = new ArrayList<Resource>();\r
- for(Resource r : rs) resources.add(r); \r
- }\r
-\r
- public DatabaseException(String message) {\r
- super(message);\r
- }\r
-\r
- public DatabaseException(String message, int ... resources) {\r
- super(message);\r
- for(int r : resources) addIndex(r);\r
- }\r
-\r
- public DatabaseException(int ... resources) {\r
- super();\r
- for(int r : resources) addIndex(r);\r
- }\r
-\r
- public DatabaseException(Throwable cause) {\r
- super(cause);\r
- }\r
- \r
- public void addResource(Resource resource) {\r
-\r
- assert(resource != null);\r
- \r
- if(resources == null) resources = new ArrayList<Resource>();\r
- \r
- resources.add(resource);\r
- \r
- }\r
- \r
- public void addIndex(int index) {\r
-\r
- assert(index != 0);\r
- \r
- if(indices == null) indices = new ArrayList<Integer>();\r
- \r
- indices.add(index);\r
- \r
- }\r
-\r
- public int getIndex(int index) {\r
- return indices.get(index);\r
- }\r
-\r
- public Collection<Resource> getResources() {\r
- return resources;\r
- }\r
- \r
- public void setNames(ArrayList<String> names) {\r
- this.names = names;\r
- }\r
- \r
- /**\r
- * Throws the exception caused by the invocation of this request. The\r
- * parameter allows checked exceptions to be thrown.\r
- * \r
- * @param <T>\r
- * @param clazz\r
- * @throws T\r
- */\r
- @SuppressWarnings("unchecked")\r
- public <T extends Throwable> void throwCause(Class<T> clazz) throws T {\r
- Throwable t = getCause();\r
- if (t == null)\r
- return;\r
- if (clazz.isInstance(t))\r
- throw (T) t;\r
- if (t instanceof RuntimeException)\r
- throw (RuntimeException) t;\r
- if (t instanceof Error)\r
- throw (Error) t;\r
- throw new RuntimeException("See cause for the real exception.", t);\r
- }\r
-\r
- public DatabaseException newStack() {\r
- return new DatabaseException(this);\r
- }\r
- \r
- @Override\r
- public String toString() {\r
- if(names != null) System.out.println(names);\r
- return super.toString();\r
- }\r
- \r
- public String getShortExplanation() {\r
- return getMessage();\r
- }\r
- \r
- public String getExplanation(ReadGraph graph) throws DatabaseException {\r
- return getShortExplanation();\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.exception;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+
+/**
+ *
+ * A base class for exceptions in org.simantics.db.
+ *
+ * There are three classes of DatabaseException
+ * <ul>
+ * <li>ServiceException is a class of serious failures e.g. (connection failure, database corruption)
+ * <li>ValidationException is a class of exceptions due to invalid semantic graph
+ * <li>AssumptionException is a class of exceptions due to unsatisfied user assumptions (e.g. user assumes a single result or existence of an adapter)
+ * </ul>
+ *
+ * The resources related to an exception are available for pretty printing uses.
+ *
+ * @author Antti Villberg
+ * @version 0.7
+ * @see ValidationException
+ * @see ServiceException
+ * @see AssumptionException
+ *
+ */
+public class DatabaseException extends Exception {
+
+ private static final long serialVersionUID = -6234485044648476711L;
+
+ private ArrayList<Resource> resources;
+ private ArrayList<String> names;
+ private ArrayList<Integer> indices;
+
+ public DatabaseException() {
+ super();
+ }
+
+ public DatabaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DatabaseException(String message, Throwable cause, Resource ... rs) {
+ super(message, cause);
+ resources = new ArrayList<Resource>();
+ for(Resource r : rs) resources.add(r);
+ }
+
+ public DatabaseException(Throwable cause, Resource ... rs) {
+ super(cause);
+ resources = new ArrayList<Resource>();
+ for(Resource r : rs) resources.add(r);
+ }
+
+ public DatabaseException(String message, Resource ... rs) {
+ super(message);
+ resources = new ArrayList<Resource>();
+ for(Resource r : rs) resources.add(r);
+ }
+
+ public DatabaseException(String message) {
+ super(message);
+ }
+
+ public DatabaseException(String message, int ... resources) {
+ super(message);
+ for(int r : resources) addIndex(r);
+ }
+
+ public DatabaseException(int ... resources) {
+ super();
+ for(int r : resources) addIndex(r);
+ }
+
+ public DatabaseException(Throwable cause) {
+ super(cause);
+ }
+
+ public void addResource(Resource resource) {
+
+ assert(resource != null);
+
+ if(resources == null) resources = new ArrayList<Resource>();
+
+ resources.add(resource);
+
+ }
+
+ public void addIndex(int index) {
+
+ assert(index != 0);
+
+ if(indices == null) indices = new ArrayList<Integer>();
+
+ indices.add(index);
+
+ }
+
+ public int getIndex(int index) {
+ return indices.get(index);
+ }
+
+ public Collection<Resource> getResources() {
+ return resources;
+ }
+
+ public void setNames(ArrayList<String> names) {
+ this.names = names;
+ }
+
+ /**
+ * Throws the exception caused by the invocation of this request. The
+ * parameter allows checked exceptions to be thrown.
+ *
+ * @param <T>
+ * @param clazz
+ * @throws T
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Throwable> void throwCause(Class<T> clazz) throws T {
+ Throwable t = getCause();
+ if (t == null)
+ return;
+ if (clazz.isInstance(t))
+ throw (T) t;
+ if (t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ if (t instanceof Error)
+ throw (Error) t;
+ throw new RuntimeException("See cause for the real exception.", t);
+ }
+
+ public DatabaseException newStack() {
+ return new DatabaseException(this);
+ }
+
+ @Override
+ public String toString() {
+ if(names != null) System.out.println(names);
+ return super.toString();
+ }
+
+ public String getShortExplanation() {
+ return getMessage();
+ }
+
+ public String getExplanation(ReadGraph graph) throws DatabaseException {
+ return getShortExplanation();
+ }
+
+}