1 23 package com.sun.enterprise.naming.factory; 24 25 import com.sun.enterprise.ComponentInvocation; 26 import com.sun.enterprise.InvocationManager; 27 import com.sun.enterprise.Switch; 28 import com.sun.enterprise.connectors.*; 29 import com.sun.enterprise.deployment.ConnectorDescriptor; 30 import com.sun.enterprise.resource.ResourceInstaller; 31 import com.sun.logging.LogDomains; 32 import java.util.Hashtable ; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 import javax.naming.ConfigurationException ; 36 import javax.naming.Context ; 37 import javax.naming.InitialContext ; 38 import javax.naming.Name ; 39 import javax.naming.NamingException ; 40 import javax.naming.Reference ; 41 import javax.naming.spi.ObjectFactory ; 42 43 49 public class AdministeredObjectFactory implements ObjectFactory { 50 51 private static Logger logger = 52 LogDomains.getLogger(LogDomains.RSR_LOGGER); 53 54 public AdministeredObjectFactory() {} 56 57 public Object getObjectInstance(Object obj, 58 Name name, 59 Context nameCtx, 60 Hashtable env) throws Exception { 61 62 Reference ref = (Reference ) obj; 63 logger.fine("AdministeredObjectFactory: " + ref + 64 " Name:" + name); 65 66 AdministeredObjectResource aor = 68 (AdministeredObjectResource) ref.get(0).getContent(); 69 String jndiName = aor.getName(); 70 String moduleName = aor.getResourceAdapter(); 71 72 ConnectorRuntime runtime = ConnectorRuntime.getRuntime(); 73 74 if(runtime.getEnviron() == ConnectorRuntime.CLIENT) { 77 ConnectorDescriptor connectorDescriptor = null; 78 try { 79 Context ic = new InitialContext (); 80 String descriptorJNDIName = ConnectorAdminServiceUtils. 81 getReservePrefixedJNDINameForDescriptor(moduleName); 82 connectorDescriptor = (ConnectorDescriptor)ic.lookup(descriptorJNDIName); 83 } catch(NamingException ne) { 84 logger.log(Level.FINE, "Failed to look up ConnectorDescriptor " + 85 "from JNDI", moduleName); 86 throw new ConnectorRuntimeException("Failed to look up " + 87 "ConnectorDescriptor from JNDI"); 88 } 89 runtime.createActiveResourceAdapter(connectorDescriptor, moduleName, 90 null,false); 91 } 92 93 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 94 if (runtime.checkAccessibility(moduleName, loader) == false) { 95 throw new NamingException ("Only the application that has the embedded resource" + 96 "adapter can access the resource adapter"); 97 } 98 99 logger.fine("[AdministeredObjectFactory] ==> Got AdministeredObjectResource = " + aor); 100 101 return aor.createAdministeredObject(null); 102 } 103 104 } 105 | Popular Tags |