Example usage for org.springframework.jndi TypeMismatchNamingException TypeMismatchNamingException

List of usage examples for org.springframework.jndi TypeMismatchNamingException TypeMismatchNamingException

Introduction

In this page you can find the example usage for org.springframework.jndi TypeMismatchNamingException TypeMismatchNamingException.

Prototype

public TypeMismatchNamingException(String jndiName, Class<?> requiredType, Class<?> actualType) 

Source Link

Document

Construct a new TypeMismatchNamingException, building an explanation text from the given arguments.

Usage

From source file:org.springframework.jndi.JndiTemplate.java

/**
 * Look up the object with the given name in the current JNDI context.
 * @param name the JNDI name of the object
 * @param requiredType type the JNDI object must match. Can be an interface or
 * superclass of the actual class, or {@code null} for any match. For example,
 * if the value is {@code Object.class}, this method will succeed whatever
 * the class of the returned instance.// w w  w .ja v a2 s .  c o m
 * @return object found (cannot be {@code null}; if a not so well-behaved
 * JNDI implementations returns null, a NamingException gets thrown)
 * @throws NamingException if there is no object with the given
 * name bound to JNDI
 */
@SuppressWarnings("unchecked")
public <T> T lookup(String name, @Nullable Class<T> requiredType) throws NamingException {
    Object jndiObject = lookup(name);
    if (requiredType != null && !requiredType.isInstance(jndiObject)) {
        throw new TypeMismatchNamingException(name, requiredType, jndiObject.getClass());
    }
    return (T) jndiObject;
}