KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > mdb > LocalProducerFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.mdb;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.jms.Destination JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 import org.jboss.annotation.ejb.MessageProperties;
30 import org.jboss.aop.advice.Interceptor;
31 import org.jboss.ejb3.NonSerializableFactory;
32
33 /**
34  * comment
35  *
36  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
37  */

38 public class LocalProducerFactory extends ProducerFactory
39 {
40    protected String JavaDoc factoryName;
41
42    public LocalProducerFactory(ConsumerContainer container, Class JavaDoc producer, MessageProperties props, Destination JavaDoc dest, InitialContext JavaDoc ctx, Hashtable JavaDoc 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 JavaDoc e)
52       {
53          throw new RuntimeException JavaDoc(e);
54       }
55    }
56
57    public Object JavaDoc createProxy()
58    {
59       Class JavaDoc[] 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 JavaDoc
71    {
72       super.start();
73       try{
74          NonSerializableFactory.rebind(ctx, jndiName + PROXY_FACTORY_NAME, this);
75       } catch (NamingException JavaDoc e)
76       {
77          NamingException JavaDoc namingException = new NamingException JavaDoc("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 JavaDoc
84    {
85       super.stop();
86       NonSerializableFactory.unbind(ctx, jndiName + PROXY_FACTORY_NAME);
87    }
88 }
89
Popular Tags