001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://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, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jndi; 018 019import javax.naming.NamingException; 020 021/** 022 * Exception thrown if a type mismatch is encountered for an object 023 * located in a JNDI environment. Thrown by JndiTemplate. 024 * 025 * @author Juergen Hoeller 026 * @since 1.2.8 027 * @see JndiTemplate#lookup(String, Class) 028 */ 029@SuppressWarnings("serial") 030public class TypeMismatchNamingException extends NamingException { 031 032 private Class<?> requiredType; 033 034 private Class<?> actualType; 035 036 037 /** 038 * Construct a new TypeMismatchNamingException, 039 * building an explanation text from the given arguments. 040 * @param jndiName the JNDI name 041 * @param requiredType the required type for the lookup 042 * @param actualType the actual type that the lookup returned 043 */ 044 public TypeMismatchNamingException(String jndiName, Class<?> requiredType, Class<?> actualType) { 045 super("Object of type [" + actualType + "] available at JNDI location [" + 046 jndiName + "] is not assignable to [" + requiredType.getName() + "]"); 047 this.requiredType = requiredType; 048 this.actualType = actualType; 049 } 050 051 /** 052 * Construct a new TypeMismatchNamingException. 053 * @param explanation the explanation text 054 * @deprecated as of Spring Framework 4.3.10 055 */ 056 @Deprecated 057 public TypeMismatchNamingException(String explanation) { 058 super(explanation); 059 } 060 061 062 /** 063 * Return the required type for the lookup, if available. 064 */ 065 public final Class<?> getRequiredType() { 066 return this.requiredType; 067 } 068 069 /** 070 * Return the actual type that the lookup returned, if available. 071 */ 072 public final Class<?> getActualType() { 073 return this.actualType; 074 } 075 076}