KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jboss.annotation.ejb.AcknowledgementMode;
25 import org.jboss.annotation.ejb.DefaultActivationSpecs;
26 import org.jboss.annotation.ejb.ResourceAdapter;
27 import org.jboss.aop.AspectManager;
28 import org.jboss.aop.MethodInfo;
29 import org.jboss.aop.advice.Interceptor;
30 import org.jboss.aop.util.MethodHashing;
31 import org.jboss.deployment.DeploymentException;
32 import org.jboss.ejb3.*;
33 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
34 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
35 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
36 import org.jboss.ejb3.timerservice.TimerServiceFactory;
37 import org.jboss.jms.ConnectionFactoryHelper;
38 import org.jboss.jms.jndi.JMSProviderAdapter;
39 import org.jboss.logging.Logger;
40 import org.jboss.metadata.ActivationConfigPropertyMetaData;
41
42 import javax.ejb.*;
43 import javax.ejb.Timer JavaDoc;
44 import javax.jms.*;
45 import javax.jms.Queue JavaDoc;
46 import javax.management.MBeanServer JavaDoc;
47 import javax.management.MalformedObjectNameException JavaDoc;
48 import javax.management.ObjectName JavaDoc;
49 import javax.naming.Context JavaDoc;
50 import javax.naming.NamingException JavaDoc;
51 import java.lang.reflect.Field JavaDoc;
52 import java.lang.reflect.Method JavaDoc;
53 import java.util.*;
54
55 /**
56  * Comment
57  *
58  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
59  * @version $Revision: 46471 $
60  */

61 public class MDB extends MessagingContainer
62 {
63    private static final Logger log = Logger.getLogger(MDB.class);
64    
65    protected Class JavaDoc messagingType = null;
66    /**
67     * Default destination type. Used when no message-driven-destination is given
68     * in ejb-jar, and a lookup of destinationJNDI from jboss.xml is not
69     * successfull. Default value: javax.jms.Topic.
70     */

71    protected final static String JavaDoc DEFAULT_DESTINATION_TYPE = "javax.jms.Topic";
72
73    public MDB(String JavaDoc ejbName, AspectManager manager, ClassLoader JavaDoc cl, String JavaDoc beanClassName, Hashtable ctxProperties,
74               InterceptorInfoRepository interceptorRepository, Ejb3Deployment deployment)
75    {
76       super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment);
77    }
78    
79    public Class JavaDoc getMessagingType()
80    {
81       if (messagingType == null)
82       {
83          MessageDriven annotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
84          messagingType = annotation.messageListenerInterface();
85          if (messagingType.getName().equals(Object JavaDoc.class.getName()))
86          {
87             ArrayList<Class JavaDoc> list = ProxyFactoryHelper.getBusinessInterfaces(clazz);
88             if (list.size() > 1 || list.size() == 0) throw new RuntimeException JavaDoc("unable to determine messagingType interface for MDB");
89             messagingType = list.get(0);
90          }
91       }
92
93       return messagingType;
94    }
95    
96    public MethodInfo getMethodInfo(Method JavaDoc method)
97    {
98       long hash = MethodHashing.calculateHash(method);
99       MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
100       return info;
101    }
102
103    public Map getActivationConfigProperties()
104    {
105       HashMap result = new HashMap();
106       MessageDriven mdAnnotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
107       for (ActivationConfigProperty property : mdAnnotation.activationConfig())
108       {
109          addActivationSpecProperty(result, property);
110       }
111       
112       DefaultActivationSpecs defaultSpecsAnnotation = (DefaultActivationSpecs)resolveAnnotation(DefaultActivationSpecs.class);
113       if (defaultSpecsAnnotation != null)
114       {
115          for (ActivationConfigProperty property : defaultSpecsAnnotation.value())
116          {
117             addActivationSpecProperty(result, property);
118          }
119       }
120       
121       return result;
122    }
123    
124    public void start() throws Exception JavaDoc
125    {
126       super.start();
127    }
128
129    public ObjectName JavaDoc getJmxName()
130    {
131       ObjectName JavaDoc jmxName = null;
132       String JavaDoc jndiName = ProxyFactoryHelper.getLocalJndiName(this);
133       // The name must be escaped since the jndiName may be arbitrary
134
String JavaDoc name = org.jboss.ejb.Container.BASE_EJB_CONTAINER_NAME + ",jndiName=" + jndiName;
135       try
136       {
137          jmxName = org.jboss.mx.util.ObjectNameConverter.convert(name);
138       }
139       catch (MalformedObjectNameException JavaDoc e)
140       {
141          e.printStackTrace();
142          throw new RuntimeException JavaDoc("Failed to create ObjectName, msg=" + e.getMessage());
143       }
144
145       return jmxName;
146    }
147    
148    protected void populateActivationSpec()
149    {
150       DefaultActivationSpecs defaultSpecs = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class);
151       if (defaultSpecs != null)
152       {
153          activationSpec.merge(defaultSpecs.value());
154       }
155
156       MessageDriven md = (MessageDriven) resolveAnnotation(MessageDriven.class);
157
158       activationSpec.merge(md.activationConfig());
159    }
160 }
161
Popular Tags