org.springframework.jndi.support
Class ExpectedLookupTemplate

java.lang.Object
  extended byorg.springframework.jndi.JndiTemplate
      extended byorg.springframework.jndi.support.ExpectedLookupTemplate

public class ExpectedLookupTemplate
extends JndiTemplate

Simple implementation of JndiTemplate interface that always returns a given object. Very useful for testing. Effectively a mock object.

Version:
$Id: ExpectedLookupTemplate.java,v 1.4 2004/03/18 02:46:11 trisberg Exp $
Author:
Rod Johnson
See Also:
DriverManagerDataSource

Field Summary
 
Fields inherited from class org.springframework.jndi.JndiTemplate
logger
 
Constructor Summary
ExpectedLookupTemplate(java.lang.String name, java.lang.Object object)
          Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.
 
Method Summary
 java.lang.Object lookup(java.lang.String name)
          If the name is the expected name specified in the constructor, return the object provided in the constructor.
 
Methods inherited from class org.springframework.jndi.JndiTemplate
bind, createInitialContext, execute, getEnvironment, setEnvironment, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpectedLookupTemplate

public ExpectedLookupTemplate(java.lang.String name,
                              java.lang.Object object)
Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.

Parameters:
name - the name the client is expected to look up
object - the object that will be returned
Method Detail

lookup

public java.lang.Object lookup(java.lang.String name)
                        throws javax.naming.NamingException
If the name is the expected name specified in the constructor, return the object provided in the constructor. If the name is unexpected, a respective NamingException gets thrown.

Overrides:
lookup in class JndiTemplate
Parameters:
name - the JNDI name of the object
Returns:
object found (cannot be null; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown)
Throws:
javax.naming.NamingException - if there is no object with the given name bound to JNDI


Copyright (C) 2003-2004 The Spring Framework Project.