1 22 package org.jboss.ejb3; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.jboss.annotation.ejb.Clustered; 28 import org.jboss.annotation.ejb.LocalBinding; 29 import org.jboss.annotation.ejb.LocalBindingImpl; 30 import org.jboss.annotation.ejb.RemoteBinding; 31 import org.jboss.annotation.ejb.RemoteBindingImpl; 32 import org.jboss.annotation.ejb.RemoteBindings; 33 import org.jboss.annotation.ejb.RemoteBindingsImpl; 34 import org.jboss.aop.Advisor; 35 import org.jboss.ejb3.remoting.RemoteProxyFactory; 36 import org.jboss.ejb3.service.ServiceContainer; 37 import org.jboss.ejb3.service.ServiceLocalProxyFactory; 38 import org.jboss.ejb3.service.ServiceRemoteProxyFactory; 39 import org.jboss.ejb3.stateful.StatefulClusterProxyFactory; 40 import org.jboss.ejb3.stateful.StatefulContainer; 41 import org.jboss.ejb3.stateful.StatefulLocalProxyFactory; 42 import org.jboss.ejb3.stateful.StatefulRemoteProxyFactory; 43 import org.jboss.ejb3.stateless.StatelessClusterProxyFactory; 44 import org.jboss.ejb3.stateless.StatelessLocalProxyFactory; 45 import org.jboss.ejb3.stateless.StatelessRemoteProxyFactory; 46 import org.jboss.logging.Logger; 47 48 54 public class ProxyDeployer 55 { 56 private static final Logger log = Logger.getLogger(ProxyDeployer.class); 57 private Container container; 58 private Advisor advisor; 59 private ArrayList <ProxyFactory> proxyFactories = new ArrayList <ProxyFactory>(); 60 private RemoteBindings remoteBindings; 61 private LocalBinding localBinding; 62 63 public ProxyDeployer(Container container) 64 { 65 this.container = container; 66 this.advisor = (Advisor) container; 67 } 68 69 public List <ProxyFactory> getProxyFactories() { return proxyFactories; } 70 71 public void start() throws Exception 72 { 73 if (remoteBindings != null) 74 { 75 RemoteBinding[] list = remoteBindings.value(); 76 for (int i = 0; i < list.length; i++) 77 { 78 Class factoryClass = list[i].factory(); 79 if (factoryClass.equals(RemoteProxyFactory.class)) factoryClass = getDefaultRemoteProxyFactory(); 80 RemoteProxyFactory factory = (RemoteProxyFactory) factoryClass.newInstance(); 81 factory.setRemoteBinding(list[i]); 82 factory.setContainer(container); 83 factory.start(); 84 proxyFactories.add(factory); 85 } 86 } 87 88 if (localBinding != null) 89 { 90 ProxyFactory factory = null; 91 if (container instanceof StatefulContainer) 92 { 93 factory = new StatefulLocalProxyFactory(); 94 } 95 else if (container instanceof ServiceContainer) 96 { 97 factory = new ServiceLocalProxyFactory(); 98 } 99 else 100 { 101 factory = new StatelessLocalProxyFactory(); 102 } 103 104 factory.setContainer(container); 105 factory.start(); 106 proxyFactories.add(factory); 107 } 108 } 109 110 public void initializeLocalBindingMetadata() 111 { 112 localBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class); 113 if (localBinding == null) 114 { 115 if (ProxyFactoryHelper.getLocalInterfaces(container) != null) 116 { 117 localBinding = new LocalBindingImpl(ProxyFactoryHelper.getLocalJndiName(container)); 118 advisor.getAnnotations().addClassAnnotation(LocalBinding.class, localBinding); 119 } 120 } 121 } 122 123 public void initializeRemoteBindingMetadata() 124 { 125 remoteBindings = (RemoteBindings) advisor.resolveAnnotation(RemoteBindings.class); 126 if (remoteBindings == null) 127 { 128 RemoteBinding binding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class); 129 if (binding == null) 130 { 131 log.debug("no declared remote bindings for : " + container.getEjbName()); 132 if (ProxyFactoryHelper.getRemoteInterfaces(container) != null) 133 { 134 log.debug("there is remote interfaces for " + container.getEjbName()); 135 String jndiName = ProxyFactoryHelper.getDefaultRemoteJndiName(container); 136 log.debug("default remote binding has jndiName of " + jndiName); 137 String uri = ""; Class factory = null; 139 factory = getDefaultRemoteProxyFactory(); 140 RemoteBinding[] list = {new RemoteBindingImpl(jndiName, "", uri, factory)}; 141 remoteBindings = new RemoteBindingsImpl(list); 142 advisor.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings); 143 } 144 } 145 else 146 { 147 RemoteBinding[] list = {binding}; 148 remoteBindings = new RemoteBindingsImpl(list); 149 advisor.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings); 150 } 151 } 152 } 153 154 private Class getDefaultRemoteProxyFactory() 155 { 156 Class factory; 157 if (container instanceof StatefulContainer) 158 { 159 if (advisor.resolveAnnotation(Clustered.class) != null) 160 { 161 factory = StatefulClusterProxyFactory.class; 162 } 163 else 164 { 165 factory = StatefulRemoteProxyFactory.class; 166 } 167 } 168 else if (container instanceof ServiceContainer) 169 { 170 factory = ServiceRemoteProxyFactory.class; 172 } 173 else 174 { 175 if (advisor.resolveAnnotation(Clustered.class) != null) 176 { 177 factory = StatelessClusterProxyFactory.class; 178 } 179 else 180 { 181 factory = StatelessRemoteProxyFactory.class; 182 } 183 } 184 return factory; 185 } 186 187 188 public void stop() throws Exception 189 { 190 for (int i = 0; i < proxyFactories.size(); i++) 191 { 192 ProxyFactory factory = (ProxyFactory) proxyFactories.get(i); 193 factory.stop(); 194 } 195 } 196 } 197 | Popular Tags |