1 22 package org.jboss.ejb3.stateful; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import javax.ejb.LocalHome ; 26 import javax.naming.NamingException ; 27 import org.jboss.annotation.ejb.LocalBinding; 28 import org.jboss.ejb3.EJBContainer; 29 import org.jboss.ejb3.JBossProxy; 30 import org.jboss.ejb3.NonSerializableFactory; 31 import org.jboss.ejb3.ProxyFactoryHelper; 32 33 34 40 public class StatefulLocalProxyFactory extends BaseStatefulProxyFactory 41 { 42 protected Class [] getInterfaces() 43 { 44 Class [] interfaces; 45 46 Class [] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container); 47 interfaces = new Class [localInterfaces.length + 2]; 48 System.arraycopy(localInterfaces, 0, interfaces, 0, localInterfaces.length); 49 interfaces[localInterfaces.length] = JBossProxy.class; 50 interfaces[localInterfaces.length + 1] = javax.ejb.EJBLocalObject .class; 51 return interfaces; 52 } 53 54 protected void initializeJndiName() 55 { 56 jndiName = ProxyFactoryHelper.getLocalJndiName(container); 57 } 58 59 public void start() throws Exception 60 { 61 super.start(); 62 63 try 64 { 65 NonSerializableFactory.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, this); 66 } 67 catch (NamingException e) 68 { 69 NamingException namingException = new NamingException ("Could not bind stateful local proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME); 70 namingException.setRootCause(e); 71 throw namingException; 72 } 73 74 LocalHome localHome = (LocalHome ) ((EJBContainer) container).resolveAnnotation(LocalHome .class); 75 if (localHome != null) 76 { 77 Class [] interfaces = {localHome.value()}; 78 Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(), 79 interfaces, new StatefulLocalHomeProxy(container)); 80 NonSerializableFactory.rebind(container.getInitialContext(), jndiName + "Home", homeProxy); 81 } 82 } 83 84 public void stop() throws Exception 85 { 86 super.stop(); 87 NonSerializableFactory.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME); 88 LocalHome localHome = (LocalHome ) ((EJBContainer) container).resolveAnnotation(LocalHome .class); 89 if (localHome != null) 90 { 91 NonSerializableFactory.unbind(container.getInitialContext(), jndiName + "Home"); 92 } 93 } 94 95 public Object createProxy() 96 { 97 try 98 { 99 StatefulContainer sfsb = (StatefulContainer) container; 100 StatefulBeanContext ctx = sfsb.getCache().create(); 101 ctx.inUse = false; 102 Object id = ctx.getId(); 103 Object [] args = {new StatefulLocalProxy(container, id)}; 104 return proxyConstructor.newInstance(args); 105 } 106 catch (InstantiationException e) 107 { 108 throw new RuntimeException (e); } 110 catch (IllegalAccessException e) 111 { 112 throw new RuntimeException (e); } 114 catch (IllegalArgumentException e) 115 { 116 throw new RuntimeException (e); } 118 catch (InvocationTargetException e) 119 { 120 throw new RuntimeException (e.getTargetException()); } 122 } 123 124 public Object createProxy(Object id) 125 { 126 try 127 { 128 StatefulContainer sfsb = (StatefulContainer) container; 129 Object [] args = {new StatefulLocalProxy(container, id)}; 130 return proxyConstructor.newInstance(args); 131 } 132 catch (InstantiationException e) 133 { 134 throw new RuntimeException (e); } 136 catch (IllegalAccessException e) 137 { 138 throw new RuntimeException (e); } 140 catch (IllegalArgumentException e) 141 { 142 throw new RuntimeException (e); } 144 catch (InvocationTargetException e) 145 { 146 throw new RuntimeException (e.getTargetException()); } 148 } 149 public Object createProxy(Class [] initTypes, Object [] initValues) 150 { 151 try 152 { 153 StatefulContainer sfsb = (StatefulContainer) container; 154 Object id = sfsb.createSession(initTypes, initValues); 155 Object [] args = {new StatefulLocalProxy(container, id)}; 156 return proxyConstructor.newInstance(args); 157 } 158 catch (InstantiationException e) 159 { 160 throw new RuntimeException (e); } 162 catch (IllegalAccessException e) 163 { 164 throw new RuntimeException (e); } 166 catch (IllegalArgumentException e) 167 { 168 throw new RuntimeException (e); } 170 catch (InvocationTargetException e) 171 { 172 throw new RuntimeException (e.getTargetException()); } 174 } 175 176 protected StatefulHandleImpl getHandle() 177 { 178 StatefulHandleImpl handle = new StatefulHandleImpl(); 179 LocalBinding remoteBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class); 180 if (remoteBinding != null) 181 handle.jndiName = remoteBinding.jndiBinding(); 182 183 return handle; 184 } 185 } 186 | Popular Tags |