1 22 package org.jboss.ejb3.mdb; 23 24 import java.util.Hashtable ; 25 import javax.jms.Destination ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 29 import org.jboss.annotation.ejb.MessageProperties; 30 import org.jboss.aop.advice.Interceptor; 31 import org.jboss.ejb3.NonSerializableFactory; 32 33 38 public class LocalProducerFactory extends ProducerFactory 39 { 40 protected String factoryName; 41 42 public LocalProducerFactory(ConsumerContainer container, Class producer, MessageProperties props, Destination dest, InitialContext ctx, Hashtable icProperties) 43 { 44 super(container, producer, props, dest, ctx, icProperties); 45 46 try 47 { 48 factoryName = pImpl.connectionFactory(); 49 if (factoryName.equals("")) factoryName = "java:/ConnectionFactory"; 50 } 51 catch (Exception e) 52 { 53 throw new RuntimeException (e); 54 } 55 } 56 57 public Object createProxy() 58 { 59 Class [] interfaces = {producer, ProducerObject.class}; 60 61 ProducerManagerImpl mImpl = null; 62 63 mImpl = new ProducerManagerImpl(pImpl, dest, factoryName, props.delivery(), props.timeToLive(), props.priority(), methodMap, initialContextProperties); 64 65 Interceptor[] interceptors = {mImpl}; 66 ProducerProxy ih = new ProducerProxy(mImpl, interceptors); 67 return java.lang.reflect.Proxy.newProxyInstance(producer.getClassLoader(), interfaces, ih); 68 } 69 70 public void start() throws Exception 71 { 72 super.start(); 73 try{ 74 NonSerializableFactory.rebind(ctx, jndiName + PROXY_FACTORY_NAME, this); 75 } catch (NamingException e) 76 { 77 NamingException namingException = new NamingException ("Could not bind local producer factory with name " + factoryName + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME); 78 namingException.setRootCause(e); 79 throw namingException; 80 } 81 } 82 83 public void stop() throws Exception 84 { 85 super.stop(); 86 NonSerializableFactory.unbind(ctx, jndiName + PROXY_FACTORY_NAME); 87 } 88 } 89 | Popular Tags |