FileDocCategorySizeDatePackage
ProducerFactory.javaAPI DocJBoss 4.2.15197Fri Jul 13 20:53:56 BST 2007org.jboss.ejb3.mdb

ProducerFactory

public abstract class ProducerFactory extends Object implements org.jboss.ejb3.ProxyFactory
comment
author
Bill Burke

Fields Summary
private static final Logger
log
protected Class
producer
protected org.jboss.annotation.ejb.MessageProperties
props
protected javax.jms.Destination
dest
protected HashMap
methodMap
protected ProducerImpl
pImpl
protected String
jndiName
protected InitialContext
ctx
protected Hashtable
initialContextProperties
public static final String
PROXY_FACTORY_NAME
Constructors Summary
protected ProducerFactory(ConsumerContainer container, Class producer, org.jboss.annotation.ejb.MessageProperties props, javax.jms.Destination dest, InitialContext ctx, Hashtable ctxProperties)



               
   
      this.producer = producer;
      this.props = props;
      this.dest = dest;
      this.ctx = ctx;
      this.initialContextProperties = ctxProperties;


      methodMap = new HashMap();
      Method[] methods = producer.getMethods();
      for (int i = 0 ; i < methods.length ; ++i)
      {
         MessageProperties mProps = (MessageProperties)methods[i].getAnnotation(MessageProperties.class);
         if (mProps != null)
         {
            try
            {
               methodMap.put(new Long(MethodHashing.methodHash(methods[i])), new MessagePropertiesImpl(mProps));
            }
            catch (Exception e)
            {
               throw new RuntimeException(e);
            }
         }
      }
  
      Producer p = (Producer) producer.getAnnotation(Producer.class);
      if (p == null)
         p = (Producer)container.resolveAnnotation(Producer.class);
      if (p == null)
      {
         Producers annotation = (Producers)container.resolveAnnotation(Producers.class);
         Producer[] producers = annotation.value();
         for (int i = 0 ; i < producers.length ; ++i)
         {
            if (producers[i].producer() != null && producers[i].producer().equals(producer))
               p = producers[i];
         }
      }
     
      pImpl = new ProducerImpl(p);
      jndiName = producer.getName();
   
Methods Summary
public java.lang.ObjectcreateHomeProxy()

      throw new UnsupportedOperationException("producer can't have a home interface");
   
public java.lang.ObjectcreateProxy(java.lang.Object id)

      if(id != null)
         throw new IllegalArgumentException("producer proxy must not have an id");
      return createProxy();
   
public voidsetContainer(org.jboss.ejb3.Container container)

   
public voidstart()

      Context baseCtx = ctx;
      Name name = baseCtx.getNameParser("").parse(jndiName);
      baseCtx = Util.createSubcontext(baseCtx, name.getPrefix(name.size() - 1));
      String atom = name.get(name.size() - 1);
      RefAddr refAddr = new StringRefAddr(JndiProxyFactory.FACTORY, atom + PROXY_FACTORY_NAME);
      Reference ref = new Reference("java.lang.Object", refAddr, JndiProxyFactory.class.getName(), null);
     
      try
      {
         Util.rebind(baseCtx, atom, ref);
      } catch (NamingException e)
      {
         NamingException namingException = new NamingException("Could not bind producer factory into JNDI under jndiName: " + baseCtx.getNameInNamespace() + "/" + atom);
         namingException.setRootCause(e);
         throw namingException;
      }
   
public voidstop()

      Util.unbind(ctx, jndiName);