KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > jca15 > InboundCASLR


1 // InboundCASLR.java
2
// Stateless Session bean
3

4 package org.objectweb.jonas.jtests.beans.jca15;
5
6 import java.rmi.RemoteException JavaDoc;
7 import javax.ejb.CreateException JavaDoc;
8 import javax.ejb.EJBException JavaDoc;
9 import javax.ejb.RemoveException JavaDoc;
10 import javax.ejb.EJBObject JavaDoc;
11 import javax.ejb.SessionBean JavaDoc;
12 import javax.ejb.SessionContext JavaDoc;
13 import javax.naming.Context JavaDoc;
14 import javax.naming.InitialContext JavaDoc;
15 import javax.naming.NamingException JavaDoc;
16 import javax.resource.cci.Connection JavaDoc;
17 import javax.resource.spi.ManagedConnection JavaDoc;
18 import javax.resource.spi.ConnectionEvent JavaDoc;
19 import javax.resource.spi.ResourceAdapter JavaDoc;
20 import ersatz.resourceadapter.ManagedConnectionFactoryImpl;
21 import ersatz.resourceadapter.ConnectionImpl;
22 import ersatz.resourceadapter.ConnectionFactoryImpl;
23 import ersatz.resourceadapter.ResourceAdapterImpl;
24
25
26 /**
27  *
28  */

29 public class InboundCASLR implements SessionBean JavaDoc {
30
31     SessionContext JavaDoc ejbContext;
32     private ConnectionFactoryImpl cccf = null; //Common Client Connection Factory
33
private ManagedConnectionFactoryImpl mcf = null;
34     private ConnectionImpl conn = null;
35     InitialContext JavaDoc ic=null;
36     String JavaDoc cName = "InboundCASLR";
37
38     // ------------------------------------------------------------------
39
// SessionBean implementation
40
// ------------------------------------------------------------------
41

42
43     public void setSessionContext(SessionContext JavaDoc ctx) {
44         Utility.log(cName+"setSessionContext");
45         ejbContext = ctx;
46     }
47         
48
49     public void ejbRemove() {
50         Utility.log("");
51     }
52         
53
54     public void ejbCreate() throws CreateException JavaDoc {
55         Utility.log("");
56     }
57
58     public void ejbPassivate() {
59         Utility.log("");
60     }
61
62     public void ejbActivate() {
63         Utility.log("");
64     }
65     
66     // ------------------------------------------------------------------
67
// InboundCA implementation
68
// ------------------------------------------------------------------
69

70     /**
71      * method1
72      */

73     public void method1(String JavaDoc rar_jndi_name, String JavaDoc testName)
74             throws Exception JavaDoc
75     {
76         Utility.log("============================ "+testName);
77         try {
78             ic = new InitialContext JavaDoc();
79         } catch (Exception JavaDoc e1) {
80             Utility.log(cName+".method1 error: InitialContext failed");
81             throw e1;
82         }
83         try {
84             cccf = (ConnectionFactoryImpl)ic.lookup(rar_jndi_name);
85             Utility.log(cName+".method1 : found "+rar_jndi_name);
86         } catch (Exception JavaDoc e2) {
87             Utility.log(cName+".method1 error: lookup failed for "+rar_jndi_name);
88             throw e2;
89         }
90         
91         try {
92             conn = (ConnectionImpl)cccf.getConnection();
93             Utility.log(cName+".method1 : getConnection conn="+conn);
94             if (conn==null) {
95                 Utility.log(cName+".method1 error: getConnection returned null connection.");
96                 throw new Exception JavaDoc("");
97             }
98         } catch (Exception JavaDoc e3) {
99             Utility.log(cName+".method1 error: getConnection failed "
100                     +e3.toString());
101             throw e3;
102         }
103
104     }
105
106     /**
107      * closeUp
108      */

109     public void closeUp(int w) {
110         try {
111             if (w>0) {
112                 // The CONNECTION_ERROR_OCCURRED indicates that the associated
113
// ManagedConnection instance is now invalid and unusable.
114
conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED);
115                 Utility.log(cName+".closeUp : closed physical connection");
116             } else {
117                 // The CONNECTION_CLOSED indicates that connection handle
118
// is closed, but physical connection still exists
119
conn.close();
120                 Utility.log(cName+".closeUp : closed connection");
121             }
122         } catch (Exception JavaDoc e) {
123             Utility.log(cName+".closeUp error: close handle/physical connection failed");
124         }
125     }
126     /**
127      * JUnit tests
128      */

129
130     /**
131      * ra.xml contains value, used by Application Server to set EIS_URL in ra
132      */

133     public String JavaDoc getEIS_URL()
134             throws Exception JavaDoc
135     {
136         Utility.log(cName+".getEIS_URL");
137         mcf = (ManagedConnectionFactoryImpl) cccf.getMcf();
138         ResourceAdapterImpl ra = (ResourceAdapterImpl)mcf.getResourceAdapter();
139         
140         String JavaDoc cp1 = "none";
141         if (ra==null) return cp1;
142         try {
143             cp1 = ra.getEIS_URL();
144         } catch (Exception JavaDoc e) {
145             Utility.log(cName+".getEIS_URL get <configuration-property> error: failed");
146             throw e;
147         }
148         return cp1;
149     }
150     public boolean deliverMsg(String JavaDoc msg) throws Exception JavaDoc
151     {
152         boolean success;
153         
154         Utility.log(cName+".deliverMsg to resource adapter");
155         mcf = (ManagedConnectionFactoryImpl) cccf.getMcf();
156         ResourceAdapterImpl ra = (ResourceAdapterImpl)mcf.getResourceAdapter();
157         try {
158             success = ra.deliverMsg(msg);
159             Utility.log(cName+".deliverMsg o.k. msg="+msg);
160         } catch (Exception JavaDoc e) {
161             Utility.log(cName+".deliverMsg error: e="+e.toString());
162             success=false;
163         }
164         return success;
165     }
166 }
167
168
Popular Tags