1 package org.openejb.core.ivm.naming; 2 3 import java.util.Hashtable ; 4 5 import javax.naming.Context ; 6 import javax.naming.InitialContext ; 7 import javax.naming.NamingException ; 8 9 15 public class JndiReference implements Reference{ 16 17 private Context context; 18 private Hashtable envProperties; 19 private String jndiName; 20 private String contextJndiName; 21 26 public JndiReference(javax.naming.Context linkedContext, String jndiName){ 27 this.context = linkedContext; 28 this.jndiName = jndiName; 29 } 30 31 33 public JndiReference(String contextJndiName, String jndiName){ 34 this.contextJndiName = contextJndiName; 35 this.jndiName = jndiName; 36 } 37 38 public JndiReference(Hashtable envProperties, String jndiName){ 39 if (envProperties == null || envProperties.size() == 0 ) { 40 this.envProperties = null; 41 } else { 42 this.envProperties = envProperties; 43 } 44 this.jndiName = jndiName; 45 } 46 47 public Object getObject( ) throws NamingException{ 48 Context externalContext = getContext(); 49 synchronized(externalContext){ 50 54 return externalContext.lookup(jndiName); 55 } 56 } 57 58 protected Context getContext() throws NamingException{ 59 if (context == null) { 60 if ( contextJndiName != null ) { 61 context = (Context )org.openejb.OpenEJB.getJNDIContext().lookup(contextJndiName); 62 } else { 63 context = new InitialContext (envProperties); 64 } 65 } 66 return context; 67 } 68 } 69 | Popular Tags |