KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > consumer_deployment_descriptor > bean > TesterBean


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.tutorial.consumer_deployment_descriptor.bean;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import org.jboss.annotation.JndiInject;
27 import javax.ejb.Remote JavaDoc;
28 import javax.ejb.Stateless JavaDoc;
29 import javax.ejb.TransactionAttribute JavaDoc;
30 import javax.ejb.TransactionAttributeType JavaDoc;
31 import org.jboss.ejb3.mdb.ProducerManager;
32 import org.jboss.ejb3.mdb.ProducerObject;
33
34 /**
35  * Show injecting in producers
36  * Show how to interact with local producers
37  *
38  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
39  * @version $Revision: 37459 $
40  */

41 @Stateless JavaDoc
42 @Remote JavaDoc(Tester.class)
43 public class TesterBean implements Tester
44 {
45    private ExampleProducerXA xa;
46    private ProducerManager xaManager;
47
48    @JndiInject(jndiName="org.jboss.tutorial.consumer_deployment_descriptor.bean.ExampleProducerXA")
49    public void setXa(ExampleProducerXA xa)
50    {
51       this.xa = xa;
52       this.xaManager = ((ProducerObject)xa).getProducerManager();
53    }
54
55    private ExampleProducer local;
56    private ProducerManager localManager;
57
58    @JndiInject(jndiName="org.jboss.tutorial.consumer_deployment_descriptor.bean.ExampleProducerLocal")
59    public void setLocal(ExampleProducer local)
60    {
61       this.local = local;
62       this.localManager = ((ProducerObject)local).getProducerManager();
63    }
64
65    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRED)
66    public void testXA() throws Exception JavaDoc
67    {
68
69       xaManager.connect();
70       xa.method1("testXA", 1);
71       Map JavaDoc<String JavaDoc, String JavaDoc> map = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
72       map.put("hello", "world");
73       map.put("great", "ejb3");
74       xa.method2("testXA2", map);
75       System.out.println("end TESTXA **");
76       xaManager.close();
77    }
78
79    public void testLocal() throws Exception JavaDoc
80    {
81
82       localManager.connect();
83       local.method1("testLocal", 1);
84       Map JavaDoc<String JavaDoc, String JavaDoc> map = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
85       map.put("hello", "world");
86       map.put("great", "ejb3");
87       local.method2("testLocal2", map);
88       localManager.close();
89    }
90
91 }
92
Popular Tags