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 final Class<?> requiredType; 033 034 private final 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 /** 053 * Return the required type for the lookup, if available. 054 */ 055 public final Class<?> getRequiredType() { 056 return this.requiredType; 057 } 058 059 /** 060 * Return the actual type that the lookup returned, if available. 061 */ 062 public final Class<?> getActualType() { 063 return this.actualType; 064 } 065 066}