KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > dd > mdb > QueueBean


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.test.dd.mdb;
23
24 import javax.annotation.Resource;
25 import javax.ejb.MessageDrivenBean JavaDoc;
26 import javax.ejb.MessageDrivenContext JavaDoc;
27 import javax.ejb.EJBException JavaDoc;
28
29 import javax.jms.MessageListener JavaDoc;
30 import javax.jms.Message JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.sql.DataSource JavaDoc;
35
36 import org.jboss.logging.Logger;
37 import org.jboss.ejb3.Container;
38 import org.jboss.ejb3.test.dd.mdb.StatelessLocal;
39 import org.jboss.ejb3.test.dd.mdb.StatelessRemote;
40
41 /**
42  * MessageBeanImpl.java
43  *
44  *
45  * Created: Sat Nov 25 18:07:50 2000
46  *
47  * @author
48  * @version
49  */

50
51 public class QueueBean implements MessageDrivenBean JavaDoc, MessageListener JavaDoc
52 {
53    private static final Logger log = Logger.getLogger(QueueBean.class);
54
55    private MessageDrivenContext JavaDoc ctx = null;
56    
57    StatelessRemote stateless;
58    StatelessLocal statelessLocal;
59    DataSource JavaDoc testDatasource;
60
61    public QueueBean()
62    {
63
64    }
65
66    @Resource
67    public void setMessageDrivenContext(MessageDrivenContext JavaDoc ctx) throws EJBException JavaDoc
68    {
69       this.ctx = ctx;
70    }
71
72    public void ejbCreate()
73    {
74    }
75
76    public void ejbRemove()
77    {
78       ctx = null;
79    }
80
81    public void onMessage(Message JavaDoc message)
82    {
83       log.debug("DEBUG: QueueBean got message" + message.toString());
84       try
85       {
86          testInjections();
87          TestStatusBean.addDestination(message.getJMSDestination());
88       }
89       catch(Exception JavaDoc e)
90       {
91          e.printStackTrace();
92       }
93    }
94    
95    public void setStatelessLocal(StatelessLocal statelessLocal)
96    {
97       this.statelessLocal = statelessLocal;
98    }
99    
100    private void testInjections() throws Exception JavaDoc
101    {
102       stateless.test();
103       statelessLocal.testLocal();
104       testDatasource.getConnection();
105       
106       Context JavaDoc initCtx = new InitialContext JavaDoc();
107       Context JavaDoc myEnv = (Context JavaDoc) initCtx.lookup(Container.ENC_CTX_NAME + "/env");
108       Object JavaDoc obj = myEnv.lookup("res/aQueue");
109       if ((obj instanceof javax.jms.Queue JavaDoc) == false)
110          throw new NamingException JavaDoc("res/aQueue is not a javax.jms.Queue");
111       
112       obj = myEnv.lookup("testDatasource");
113       if ((obj instanceof javax.sql.DataSource JavaDoc) == false)
114          throw new NamingException JavaDoc("testDatasource is not a javax.sql.DataSource");
115    }
116 } // MessageBeanImpl
117

118
Popular Tags