1 16 17 package org.springframework.mock.jndi; 18 19 import java.util.Collections ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import javax.naming.NamingException ; 24 25 import org.springframework.jndi.JndiTemplate; 26 27 34 public class ExpectedLookupTemplate extends JndiTemplate { 35 36 private final Map jndiObjects = Collections.synchronizedMap(new HashMap ()); 37 38 39 44 public ExpectedLookupTemplate() { 45 } 46 47 53 public ExpectedLookupTemplate(String name, Object object) { 54 addObject(name, object); 55 } 56 57 63 public void addObject(String name, Object object) { 64 this.jndiObjects.put(name, object); 65 } 66 67 68 73 public Object lookup(String name) throws NamingException { 74 Object object = this.jndiObjects.get(name); 75 if (object == null) { 76 throw new NamingException ("Unexpected JNDI name '" + name + "': expecting " + this.jndiObjects.keySet()); 77 } 78 return object; 79 } 80 81 } 82 | Popular Tags |