1 17 18 19 package org.apache.naming.factory; 20 21 import java.util.Hashtable ; 22 23 import javax.naming.Context ; 24 import javax.naming.Name ; 25 import javax.naming.NamingException ; 26 import javax.naming.RefAddr ; 27 import javax.naming.Reference ; 28 import javax.naming.spi.ObjectFactory ; 29 30 import org.apache.naming.ResourceLinkRef; 31 32 33 39 40 public class ResourceLinkFactory 41 implements ObjectFactory { 42 43 44 46 47 49 50 53 private static Context globalContext = null; 54 55 56 58 59 64 public static void setGlobalContext(Context newGlobalContext) { 65 if (globalContext != null) 66 return; 67 globalContext = newGlobalContext; 68 } 69 70 71 73 74 79 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 80 Hashtable environment) 81 throws NamingException { 82 83 if (!(obj instanceof ResourceLinkRef)) 84 return null; 85 86 Reference ref = (Reference ) obj; 88 89 String type = ref.getClassName(); 90 91 String globalName = null; 93 RefAddr refAddr = ref.get(ResourceLinkRef.GLOBALNAME); 94 if (refAddr != null) { 95 globalName = refAddr.getContent().toString(); 96 Object result = null; 97 result = globalContext.lookup(globalName); 98 return result; 100 } 101 102 return (null); 103 104 105 } 106 107 108 } 109 | Popular Tags |