1 22 package org.jboss.ejb3.stateless; 23 24 import javax.ejb.RemoteHome ; 25 import javax.naming.NamingException ; 26 import org.jboss.annotation.ejb.RemoteBinding; 27 import org.jboss.aop.Advisor; 28 import org.jboss.aop.AspectManager; 29 import org.jboss.aop.advice.AdviceStack; 30 import org.jboss.ejb3.JBossProxy; 31 import org.jboss.ejb3.ProxyFactoryHelper; 32 import org.jboss.ejb3.remoting.RemoteProxyFactory; 33 import org.jboss.logging.Logger; 34 import org.jboss.remoting.InvokerLocator; 35 import org.jboss.naming.Util; 36 37 38 44 public class StatelessRemoteProxyFactory extends BaseStatelessProxyFactory implements RemoteProxyFactory 45 { 46 private static final Logger log = Logger.getLogger(StatelessRemoteProxyFactory.class); 47 48 protected RemoteBinding binding; 49 protected InvokerLocator locator; 50 51 public void setRemoteBinding(RemoteBinding binding) 52 { 53 this.binding = binding; 54 } 55 56 protected Class [] getInterfaces() 57 { 58 Class [] interfaces; 59 60 Class [] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container); 61 interfaces = new Class [remoteInterfaces.length + 2]; 62 63 System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length); 64 interfaces[remoteInterfaces.length] = JBossProxy.class; 65 interfaces[remoteInterfaces.length + 1] = javax.ejb.EJBObject .class; 66 67 return interfaces; 68 } 69 70 protected void initializeJndiName() 71 { 72 jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding); 73 } 74 75 public void init() throws Exception 76 { 77 super.init(); 78 String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding); 79 locator = new InvokerLocator(clientBindUrl); 80 } 81 82 public void start() throws Exception 83 { 84 super.start(); 85 StatelessContainer statelessContainer = (StatelessContainer) container; 86 RemoteHome remoteHome = (RemoteHome ) statelessContainer.resolveAnnotation(RemoteHome .class); 87 if (remoteHome != null) 88 { 89 Object homeProxy = createHomeProxy(remoteHome.value()); 90 try 91 { 92 Util.rebind(container.getInitialContext(), jndiName + "Home", homeProxy); 93 } 94 catch (NamingException e) 95 { 96 NamingException namingException = new NamingException ("Could not bind stateless home proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + "Home"); 97 namingException.setRootCause(e); 98 throw namingException; 99 } 100 101 } 102 } 103 104 public void stop() throws Exception 105 { 106 super.stop(); 107 StatelessContainer statelessContainer = (StatelessContainer) container; 108 RemoteHome remoteHome = (RemoteHome ) statelessContainer.resolveAnnotation(RemoteHome .class); 109 if (remoteHome != null) 110 { 111 Util.unbind(container.getInitialContext(), jndiName + "Home"); 112 } 113 } 114 115 protected StatelessHandleImpl getHandle() 116 { 117 StatelessHandleImpl handle = new StatelessHandleImpl(); 118 RemoteBinding remoteBinding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class); 119 if (remoteBinding != null) 120 handle.jndiName = remoteBinding.jndiBinding() ; 121 122 return handle; 123 } 124 125 public Object createHomeProxy(Class homeInterface) 126 { 127 try 128 { 129 Object containerId = container.getObjectName().getCanonicalName(); 130 ; 131 String stackName = "StatelessSessionClientInterceptors"; 132 if (binding.interceptorStack() != null && !binding.interceptorStack().equals("")) 133 { 134 stackName = binding.interceptorStack(); 135 } 136 AdviceStack stack = AspectManager.instance().getAdviceStack(stackName); 137 StatelessRemoteProxy proxy = new StatelessRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator); 138 setEjb21Objects(proxy); 139 Class [] interfaces = {homeInterface}; 140 return java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(), interfaces, proxy); 141 } 142 catch (IllegalArgumentException e) 143 { 144 throw new RuntimeException (e); } 146 } 147 148 public Object createProxy() 149 { 150 { 152 Object containerId = container.getObjectName().getCanonicalName(); 153 ; 154 String stackName = "StatelessSessionClientInterceptors"; 155 if (binding.interceptorStack() != null && !binding.interceptorStack().equals("")) 156 { 157 stackName = binding.interceptorStack(); 158 } 159 AdviceStack stack = AspectManager.instance().getAdviceStack(stackName); 160 StatelessRemoteProxy proxy = new StatelessRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator); 161 setEjb21Objects(proxy); 162 166 return constructProxy(proxy); 167 } 168 186 } 187 188 } 189 | Popular Tags |