KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > consumer > DeploymentDescriptorQueueTestConsumer


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.consumer;
23
24 import javax.interceptor.AroundInvoke;
25 import javax.interceptor.InvocationContext;
26 import javax.annotation.PostConstruct;
27 import javax.annotation.PreDestroy;
28 import javax.jms.Message JavaDoc;
29 import javax.naming.Context JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32 import javax.sql.DataSource JavaDoc;
33
34 import org.jboss.ejb3.Container;
35 import org.jboss.logging.Logger;
36
37 /**
38  * @version <tt>$Revision: 44679 $</tt>
39  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
40  */

41 public class DeploymentDescriptorQueueTestConsumer implements DeploymentDescriptorQueueTestRemote, DeploymentDescriptorQueueTestXA, DeploymentDescriptorQueueTestLocal
42 {
43    private static final Logger log = Logger.getLogger(DeploymentDescriptorQueueTestConsumer.class);
44    
45    Message JavaDoc currentMessage;
46
47    private Message JavaDoc setterMessage;
48    
49    StatelessRemote stateless;
50    StatelessLocal statelessLocal;
51    DataSource JavaDoc testDatasource;
52    
53    public void setStatelessLocal(StatelessLocal statelessLocal)
54    {
55       this.statelessLocal = statelessLocal;
56    }
57
58    void setMessage(Message JavaDoc msg)
59    {
60       setterMessage = msg;
61    }
62    
63    private void testInjections() throws Exception JavaDoc
64    {
65       stateless.test();
66       statelessLocal.testLocal();
67       testDatasource.getConnection();
68       
69       Context initCtx = new InitialContext JavaDoc();
70       Context myEnv = (Context) initCtx.lookup(Container.ENC_CTX_NAME + "/env");
71       Object JavaDoc obj = myEnv.lookup("res/aQueue");
72       if ((obj instanceof javax.jms.Queue JavaDoc) == false)
73          throw new NamingException JavaDoc("res/aQueue is not a javax.jms.Queue");
74    }
75    
76    public void method1(String JavaDoc msg, int num) throws Exception JavaDoc
77    {
78       testInjections();
79       
80       TestStatusBean.queueRan = "method1";
81       TestStatusBean.fieldMessage = currentMessage != null;
82       TestStatusBean.setterMessage = setterMessage != null;
83
84       System.out.println("method1(" + msg + ", " + num + ")");
85    }
86
87    public void method2(String JavaDoc msg, float num)
88    {
89       TestStatusBean.queueRan = "method2";
90
91       TestStatusBean.fieldMessage = currentMessage != null;
92       TestStatusBean.setterMessage = setterMessage != null;
93
94       System.out.println("method2(" + msg + ", " + num + ")");
95    }
96
97    @AroundInvoke
98    public Object JavaDoc intercept(InvocationContext ctx) throws Exception JavaDoc
99    {
100       System.out.println("**** intercepted ****" + ctx.getMethod().getName());
101       TestStatusBean.interceptedQueue = ctx.getMethod().getName();
102       return ctx.proceed();
103    }
104
105    @PostConstruct
106    public void postConstruct()
107    {
108       TestStatusBean.postConstruct = true;
109    }
110
111    @PreDestroy
112    public void preDestroy()
113    {
114       TestStatusBean.preDestroy = true;
115    }
116 }
117
Popular Tags