1 29 30 package com.caucho.ejb.cfg; 31 32 import com.caucho.bytecode.JClass; 33 import com.caucho.bytecode.JMethod; 34 import com.caucho.config.ConfigException; 35 import com.caucho.config.types.JndiBuilder; 36 import com.caucho.ejb.AbstractServer; 37 import com.caucho.ejb.EjbServerManager; 38 import com.caucho.ejb.message.MessageServer; 39 import com.caucho.java.gen.JavaClassGenerator; 40 import com.caucho.management.j2ee.J2EEManagedObject; 41 import com.caucho.util.L10N; 42 43 import javax.annotation.PostConstruct; 44 import javax.ejb.MessageDrivenBean ; 45 import javax.jms.ConnectionFactory ; 46 import javax.jms.Destination ; 47 import javax.jms.MessageListener ; 48 import javax.jms.Session ; 49 import javax.naming.NamingException ; 50 import java.lang.reflect.Modifier ; 51 52 55 public class EjbMessageBean extends EjbBean { 56 private static L10N L = new L10N(EjbMessageBean.class); 57 58 private ConnectionFactory _connectionFactory; 59 private Destination _destination; 60 private boolean _isContainerTransaction = true; 61 private int _acknowledgeMode = Session.AUTO_ACKNOWLEDGE; 62 private String _selector; 63 private String _subscriptionName; 64 private String _destinationType; 65 private String _destinationLink; 66 private int _consumerMax = 5; 67 68 71 public EjbMessageBean(EjbConfig config, String ejbModuleName) 72 { 73 super(config, ejbModuleName); 74 75 _consumerMax = config.getEJBManager().getMessageConsumerMax(); 76 } 77 78 81 public String getEJBKind() 82 { 83 return "message"; 84 } 85 86 89 public void setEJBClass(Class ejbClass) 90 throws ConfigException 91 { 92 super.setEJBClass(ejbClass); 93 94 if (! MessageListener .class.isAssignableFrom(ejbClass)) 95 throw error(L.l("'{0}' must implement javax.jms.MessageListener. Every message-driven bean must implement MessageListener.", ejbClass.getName())); 96 97 if (! MessageDrivenBean .class.isAssignableFrom(ejbClass) && 98 ! isAllowPOJO()) 99 throw error(L.l("'{0}' must implement javax.ejb.MessageDrivenBean. Every message-driven bean must implement MessageDrivenBean.", ejbClass.getName())); 100 101 102 if (Modifier.isAbstract(ejbClass.getModifiers())) 103 throw error(L.l("'{0}' must not be abstract. Every message-driven bean must be a fully-implemented class.", 104 ejbClass.getName())); 105 106 JMethod create = getMethod(getEJBClassWrapper(), "ejbCreate", new JClass[] {}); 107 108 if (create == null) { 109 if (! isAllowPOJO()) { 110 throw error(L.l("{0}: ejbCreate() method is missing. Every message-driven bean must have an ejbCreate() method.", 111 ejbClass.getName())); 112 } 113 } 114 else if (! create.isPublic()) { 115 throw error(L.l("{0}: ejbCreate() must be public. Every message-driven bean must have a public ejbCreate method.", 116 ejbClass.getName())); 117 } 118 } 119 120 123 public MessageDrivenDestination createMessageDrivenDestination() 124 { 125 return new MessageDrivenDestination(); 126 } 127 128 131 public void setDestination(JndiBuilder destination) 132 throws ConfigException, NamingException 133 { 134 if (! (destination.getObject() instanceof Destination )) 135 throw new ConfigException(L.l("`{0}' needs to implement javax.jms.Destination.", 136 destination.getObject())); 137 138 _destination = (Destination ) destination.getObject(); 139 } 140 141 144 public Destination getDestination() 145 { 146 return _destination; 147 } 148 149 152 public void setMessageDestinationType(String type) 153 throws ConfigException, NamingException 154 { 155 _destinationType = type; 156 } 157 158 161 public void setMessageDestinationLink(String link) 162 throws ConfigException, NamingException 163 { 164 _destinationLink = link; 165 } 166 167 170 public void setConnectionFactory(JndiBuilder factory) 171 throws ConfigException, NamingException 172 { 173 if (! (factory.getObject() instanceof ConnectionFactory )) 174 throw new ConfigException(L.l("`{0}' needs to implement javax.jms.ConnectionFactory.", 175 factory.getObject())); 176 177 _connectionFactory = (ConnectionFactory ) factory.getObject(); 178 } 179 180 183 public ConnectionFactory getConnectionFactory() 184 { 185 return _connectionFactory; 186 } 187 188 191 public boolean getContainerTransaction() 192 { 193 return _isContainerTransaction; 194 } 195 196 199 public void setContainerTransaction(boolean isContainerTransaction) 200 { 201 _isContainerTransaction = isContainerTransaction; 202 } 203 204 207 public int getAcknowledgeMode() 208 { 209 return _acknowledgeMode; 210 } 211 212 215 public void setAcknowledgeMode(int acknowledgeMode) 216 { 217 _acknowledgeMode = acknowledgeMode; 218 } 219 220 223 public String getSelector() 224 { 225 return _selector; 226 } 227 228 231 public void setSelector(String selector) 232 { 233 _selector = selector; 234 } 235 236 239 public String getSubscriptionName() 240 { 241 return _subscriptionName; 242 } 243 244 247 public void setSubscriptionName(String subscriptionName) 248 { 249 _subscriptionName = subscriptionName; 250 } 251 252 255 public void setTransactionType(String type) 256 throws ConfigException 257 { 258 if (type.equals("Container")) { 259 } 260 else if (type.equals("Bean")) { 261 } 262 else 263 throw new ConfigException(L.l("`{0}' is an unknown transaction-type. transaction-type must be `Bean' or `Container'.", type)); 264 } 265 266 public void setSecurityIdentity(SecurityIdentity identity) 267 { 268 } 269 270 273 public ActivationConfig createActivationConfig() 274 { 275 return new ActivationConfig(); 276 } 277 278 281 public void setMessageConsumerMax(int consumerMax) 282 throws ConfigException 283 { 284 _consumerMax = consumerMax; 285 } 286 287 290 @PostConstruct 291 public void init() 292 throws ConfigException 293 { 294 J2EEManagedObject.register(new com.caucho.management.j2ee.MessageDrivenBean(this)); 295 } 296 297 300 public AbstractServer deployServer(EjbServerManager ejbManager, 301 JavaClassGenerator javaGen) 302 throws ClassNotFoundException 303 { 304 MessageServer server = new MessageServer(ejbManager); 305 306 server.setEJBName(getEJBName()); 307 308 311 server.setContextImplClass(getEJBClass()); 312 server.setDestination(_destination); 313 server.setConsumerMax(_consumerMax); 314 315 server.setInitProgram(getInitProgram()); 316 317 return server; 318 } 319 320 public class ActivationConfig { 321 public void addActivationConfigProperty(ActivationConfigProperty prop) 322 { 323 } 324 } 325 326 public static class ActivationConfigProperty { 327 String _name; 328 String _value; 329 330 public void setActivationConfigPropertyName(String name) 331 { 332 _name = name; 333 } 334 335 public void setActivationConfigPropertyValue(String value) 336 { 337 _value = value; 338 } 339 } 340 341 public class MessageDrivenDestination { 342 public void setDestinationType(String value) 343 throws ConfigException, NamingException 344 { 345 setMessageDestinationType(value); 346 } 347 348 public void setSubscriptionDurability(String durability) 349 { 350 } 351 352 public void setJndiName(JndiBuilder destination) 353 throws ConfigException, NamingException 354 { 355 setDestination(destination); 356 } 357 } 358 } 359 | Popular Tags |