1 24 package org.objectweb.jonas.resource; 25 26 import java.util.Hashtable ; 27 28 import javax.naming.Context ; 29 import javax.naming.Name ; 30 import javax.naming.RefAddr ; 31 import javax.naming.Reference ; 32 import javax.naming.spi.ObjectFactory ; 33 34 import org.objectweb.jonas.common.JNDIUtils; 35 import org.objectweb.jonas_rar.deployment.api.ConnectorDesc; 36 import org.objectweb.jonas_rar.deployment.api.JonasConnectorDesc; 37 38 44 public class ResourceObjectJNDIHandler implements ObjectFactory { 45 46 56 public Object getObjectInstance(Object refObj, Name name, 57 Context nameCtx, Hashtable env) throws Exception { 58 59 Reference ref = (Reference ) refObj; 60 61 if (ref == null) { 62 System.out.println("No reference found"); 63 return null; 64 } 65 String clname = ref.getClassName(); 66 String raname = (String ) ref.get(ResourceServiceImpl.JNDI_NAME).getContent(); 67 68 Object obj = null; 69 try { 70 obj = Rar.getResourceObject(raname); 71 } catch (Throwable ex) { 72 ex.printStackTrace(); 73 } 74 if (obj != null) { 75 return obj; 76 } 77 78 String rarObjectName = (String ) ref.get(ResourceServiceImpl.RAR_OBJNAME).getContent(); 80 String factoryType = (String ) ref.get(ResourceServiceImpl.FACTORY_TYPE).getContent(); 81 String factoryOff = (String ) ref.get(ResourceServiceImpl.FACTORY_OFFSET).getContent(); 82 int factoryOffset = Integer.parseInt(factoryOff); 83 84 RefAddr refAddr = null; 85 ConnectorDesc conn = null; 86 refAddr = ref.get(ResourceServiceImpl.RA_XML); 87 if (refAddr != null) { 88 conn = (ConnectorDesc) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent()); 89 } 90 91 JonasConnectorDesc jConn = null; 92 refAddr = ref.get(ResourceServiceImpl.JONAS_RA_XML); 93 if (refAddr != null) { 94 jConn = (JonasConnectorDesc) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent()); 95 } 96 97 Rar ra = new Rar(); 99 obj = ra.createFactory(raname, rarObjectName, factoryOffset, factoryType, 100 conn, jConn); 101 102 return obj; 103 } 104 } 105 | Popular Tags |