001 /* 002 * Copyright 2002-2006 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.application; 017 018 /** 019 * Indicates that an application service of a given type could not be found. 020 * 021 * @author Kevin Stembridge 022 * @since 0.3 023 * 024 */ 025 public class ServiceNotFoundException extends RuntimeException { 026 027 private static final long serialVersionUID = 4732373005271272964L; 028 029 private final Class serviceClass; 030 031 private static String createDefaultMessage(Class serviceClass) { 032 033 if (serviceClass != null) { 034 return "Unable to locate an application service of type [" + serviceClass.getName() + "]"; 035 } 036 else { 037 return "Unable to locate an application service. The type of the service is either " 038 + "unknown or was not provided when this exception was created."; 039 } 040 041 } 042 043 /** 044 * Creates a new {@code ServiceNotFoundException}. A default message 045 * containing the name of the given class will be used. 046 * 047 * @param serviceClass The class of the application service that could not 048 * be located. 049 */ 050 public ServiceNotFoundException(Class serviceClass) { 051 super(createDefaultMessage(serviceClass)); 052 this.serviceClass = serviceClass; 053 } 054 055 /** 056 * Creates a new {@code ServiceNotFoundException} with the given detail 057 * message and nested exception. 058 * 059 * @param message The detail message. 060 * @param serviceClass The class of the application service that could not 061 * be located. 062 * @param cause An optional nested exception that occurred attempting to 063 * locate the service. 064 */ 065 public ServiceNotFoundException(String message, Class serviceClass) { 066 super(message); 067 this.serviceClass = serviceClass; 068 } 069 070 /** 071 * Creates a new {@code ServiceNotFoundException} with the given detail 072 * message and nested exception. 073 * 074 * @param message The detail message. 075 * @param serviceClass The class of the application service that could not 076 * be located. 077 * @param cause An optional nested exception that occurred attempting to 078 * locate the service. 079 */ 080 public ServiceNotFoundException(String message, Class serviceClass, Throwable cause) { 081 super(message, cause); 082 this.serviceClass = serviceClass; 083 } 084 085 /** 086 * Returns class of the application service that could not be located. 087 * @return Returns the service class. 088 */ 089 public Class getServiceClass() { 090 return this.serviceClass; 091 } 092 093 }