]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/exception/ServiceNotFoundException.java
Restored old NoSingleResultException constructors without result count
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / exception / ServiceNotFoundException.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.exception;
13
14 import org.simantics.db.ServiceLocator;
15
16 /**
17  * Thrown by {@link ServiceLocator} when requested services are unavailable.
18  * 
19  * @author Tuukka Lehtonen
20  */
21 public class ServiceNotFoundException extends RuntimeDatabaseException {
22
23     private static final long    serialVersionUID = 2454410258587204157L;
24
25     private final ServiceLocator locator;
26     private final Class<?>       clazz;
27
28     public ServiceNotFoundException(ServiceLocator locator, Class<?> clazz, String message) {
29         super(message);
30         this.locator = locator;
31         this.clazz = clazz;
32     }
33
34     public ServiceNotFoundException(ServiceLocator locator, Class<?> clazz) {
35         this.locator = locator;
36         this.clazz = clazz;
37     }
38
39     @Override
40     public String toString() {
41         StringBuilder sb = new StringBuilder();
42         sb.append(clazz.getName()).append(" is not available in ").append(locator.toString());
43         String msg = getMessage();
44         if (msg != null)
45             sb.append(" - ").append(msg);
46         return sb.toString();
47     }
48
49 }