001: // connectorCASLR.java
002: // Stateless Session bean
003:
004: package org.objectweb.jonas.jtests.beans.j2eeca;
005:
006: import javax.ejb.CreateException;
007: import javax.ejb.SessionBean;
008: import javax.ejb.SessionContext;
009: import javax.naming.InitialContext;
010: import javax.resource.cci.ConnectionMetaData;
011: import javax.resource.spi.ConnectionEvent;
012:
013: import org.objectweb.jonas.common.Log;
014: import org.objectweb.util.monolog.api.BasicLevel;
015: import org.objectweb.util.monolog.api.Logger;
016:
017: import fictional.resourceadapter.CommonClient;
018: import fictional.resourceadapter.ConnectionImpl;
019: import fictional.resourceadapter.JtestInteraction;
020: import fictional.resourceadapter.JtestResourceAdapter;
021:
022: /**
023: * -
024: */
025: public class connectorCASLR implements SessionBean {
026:
027: static private Logger logger = null;
028: SessionContext ejbContext;
029: private CommonClient cccf = null; //Common Client Connection Factory
030: private JtestResourceAdapter mcf = null; //Managed Connection Factory
031: private CommonClient csp = null; //ConnectionSpec
032: private ConnectionImpl conn = null;
033: InitialContext ic = null;
034: JtestInteraction i = null;
035: ConnectionMetaData cMetaData = null;
036: String cName = "connectorCASLR";
037:
038: // ------------------------------------------------------------------
039: // SessionBean implementation
040: // ------------------------------------------------------------------
041:
042: public void setSessionContext(SessionContext ctx) {
043: if (logger == null) {
044: logger = Log.getLogger("org.objectweb.jonas.jtests.j2eeca");
045: }
046: logger.log(BasicLevel.DEBUG, cName + ".setSessionContext");
047: ejbContext = ctx;
048: }
049:
050: public void ejbRemove() {
051: logger.log(BasicLevel.DEBUG, cName + ".ejbRemove");
052: }
053:
054: public void ejbCreate() throws CreateException {
055: logger.log(BasicLevel.DEBUG, cName + ".ejbCreate");
056: }
057:
058: public void ejbPassivate() {
059: logger.log(BasicLevel.DEBUG, cName + ".ejbPassivate");
060: }
061:
062: public void ejbActivate() {
063: logger.log(BasicLevel.DEBUG, cName + ".ejbActivate");
064: }
065:
066: // ------------------------------------------------------------------
067: // connectorCA implementation
068: // ------------------------------------------------------------------
069: /**
070: * method1
071: */
072: public void method1(String rar_jndi_name, String testName)
073: throws Exception {
074: logger.log(BasicLevel.DEBUG, "============================ "
075: + testName);
076: try {
077: ic = new InitialContext();
078: } catch (Exception e1) {
079: logger.log(BasicLevel.DEBUG, cName
080: + ".method1 error: InitialContext failed");
081: throw e1;
082: }
083: try {
084: cccf = (CommonClient) ic.lookup(rar_jndi_name);
085: logger.log(BasicLevel.DEBUG, cName + ".method1 : found "
086: + rar_jndi_name);
087: } catch (Exception e2) {
088: logger.log(BasicLevel.DEBUG, cName
089: + ".method1 error: lookup failed for "
090: + rar_jndi_name);
091: throw e2;
092: }
093:
094: try {
095: csp = new CommonClient(); // get a new ConnectionSpec
096: logger.log(BasicLevel.DEBUG, cName
097: + ".method1 : ConnectionSpec o.k.");
098:
099: } catch (Exception e3) {
100: logger.log(BasicLevel.DEBUG, cName
101: + ".method1 : new connection spec failed");
102: throw e3;
103: }
104: try {
105: conn = (ConnectionImpl) cccf.getConnection();
106: logger.log(BasicLevel.DEBUG, cName
107: + ".method1 : getConnection conn=" + conn);
108: if (conn == null) {
109: logger
110: .log(
111: BasicLevel.DEBUG,
112: cName
113: + ".method1 error: getConnection returned null connection.");
114: throw new Exception("");
115: }
116: } catch (Exception e4) {
117: logger.log(BasicLevel.DEBUG, cName
118: + ".method1 error: getConnection failed "
119: + e4.toString());
120: throw e4;
121: }
122: try {
123: i = (JtestInteraction) conn.createInteraction();
124: } catch (Exception e5) {
125: logger.log(BasicLevel.DEBUG, cName
126: + ".method1 error: create interaction failed");
127: throw e5;
128: }
129: try {
130: cMetaData = (ConnectionMetaData) conn.getMetaData();
131: } catch (Exception e6) {
132: logger.log(BasicLevel.DEBUG, cName
133: + ".method1 : get ConnectionMetaData failed");
134: throw e6;
135: }
136:
137: }
138:
139: /**
140: * closeUp
141: */
142: public void closeUp(int w) {
143: try {
144: if (w > 0) {
145: // The CONNECTION_ERROR_OCCURRED indicates that the associated
146: // ManagedConnection instance is now invalid and unusable.
147: conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED);
148: logger.log(BasicLevel.DEBUG, cName
149: + ".closeUp : closed physical connection");
150: } else {
151: // The CONNECTION_CLOSED indicates that connection handle
152: // is closed, but physical connection still exists
153: conn.close();
154: logger.log(BasicLevel.DEBUG, cName
155: + ".closeUp : closed connection");
156: }
157: } catch (Exception e) {
158: logger
159: .log(
160: BasicLevel.DEBUG,
161: cName
162: + ".closeUp error: close handle/physical connection failed");
163: }
164: }
165:
166: /**
167: * JUnit tests
168: */
169: public boolean isConnectionSpec() {
170: if (csp == null)
171: return false;
172: else
173: return true;
174: }
175:
176: public boolean isConnection() {
177: if (conn == null)
178: return false;
179: else
180: return true;
181: }
182:
183: public boolean isInteraction() {
184: if (i == null)
185: return false;
186: else
187: return true;
188: }
189:
190: public String getConnectionProduct() throws Exception {
191: String s;
192: try {
193: s = cMetaData.getEISProductName();
194: logger
195: .log(
196: BasicLevel.DEBUG,
197: cName
198: + ".getConnectionProduct : ConnectionMetaData.product="
199: + s);
200: } catch (Exception e) {
201: logger
202: .log(
203: BasicLevel.DEBUG,
204: cName
205: + ".getConnectionProduct error: ConnectionMetaData.getEISProductName() failed");
206: throw e;
207: }
208: return s;
209: }
210:
211: /**
212: * The application server calls setter methods on the ManagedConnectionFactory instance
213: * to set various configuration properties on this instance. These properties provide
214: * information required by the ManagedConnectionFactory instance to create physical
215: * connections to the underlying EIS. The application server uses an existing property set
216: * (configured during the deployment of a resource adapter) to set the required properties on
217: * the ManagedConnectionFactory instance.
218: *
219: */
220: public String getServerName() throws Exception {
221: logger.log(BasicLevel.DEBUG, cName + ".getServerName");
222: mcf = (JtestResourceAdapter) cccf.getMcf(); // ManagedConnectionFactory
223: String cp1 = "null";
224: if (mcf == null)
225: return cp1;
226: try {
227: cp1 = mcf.getServerName();
228: } catch (Exception e) {
229: logger.log(BasicLevel.DEBUG, cName
230: + ".getConfigurationProperty error: failed");
231: throw e;
232: }
233: return cp1;
234: }
235:
236: public String getProtocolProperty() throws Exception {
237: logger.log(BasicLevel.DEBUG, cName + ".getProtocolProperty");
238: mcf = (JtestResourceAdapter) cccf.getMcf(); // ManagedConnectionFactory
239: String p = "null";
240: if (mcf == null)
241: return p;
242: try {
243: p = mcf.getProtocol();
244: } catch (Exception e) {
245: logger.log(BasicLevel.DEBUG, cName
246: + ".getProtocolProperty error: failed");
247: throw e;
248: }
249: return p;
250: }
251:
252: /**
253: * After the newly created ManagedConnectionFactory instance has been configured with
254: * its property set, the application server creates a new ConnectionManager instance.
255: * true returned if ConnectionManager is valid
256: */
257: public boolean getCMInstance() {
258: mcf = (JtestResourceAdapter) cccf.getMcf(); // ManagedConnectionFactory
259: if (mcf.getCM() == null) { // ConnectionManager not null
260: logger
261: .log(
262: BasicLevel.DEBUG,
263: cName
264: + ".getCMInstance error: ConnectionManager is null");
265: return false;
266: } else {
267: logger.log(BasicLevel.DEBUG, cName
268: + ".getCMInstance ConnectionManager is o.k.");
269: return true;
270: }
271: }
272:
273: public int getMCF_Pwriter() {
274: int here = 2;
275: mcf = (JtestResourceAdapter) cccf.getMcf(); // ManagedConnectionFactory
276: try {
277: if (mcf.getLogWriter() == null) { // PrintWriter not null
278: logger.log(BasicLevel.DEBUG, cName
279: + ".getMCF_Pwriter No PrintWriter registered");
280: here = 0;
281: } else {
282: logger.log(BasicLevel.DEBUG, cName
283: + ".getMCF_Pwriter PrintWriter is o.k.");
284: here = 1;
285: }
286: } catch (Exception e) {
287: logger.log(BasicLevel.DEBUG, cName
288: + ".getMCF_Pwriter error: " + e.toString());
289: }
290: return here;
291: }
292:
293: public int getMC_Pwriter() {
294: int here = 2;
295: ConnectionImpl conni = (ConnectionImpl) conn;
296: try {
297: JtestResourceAdapter mc = (JtestResourceAdapter) conni
298: .getMC(); //get ManagedConnection
299: if (mc.getLogWriter() == null) { // PrintWriter not null
300: logger
301: .log(
302: BasicLevel.DEBUG,
303: cName
304: + ".getMC_Pwriter No PrintWriter registered in ManagedConnection");
305: here = 0;
306: } else {
307: logger
308: .log(
309: BasicLevel.DEBUG,
310: cName
311: + ".getMC_Pwriter PrintWriter in ManagedConnection is o.k.");
312: here = 1;
313: }
314: } catch (Exception e) {
315: logger.log(BasicLevel.DEBUG, cName
316: + ".getMC_Pwriter error: " + e.toString());
317: }
318: return here;
319: }
320:
321: public void setMatchNull(boolean b) {
322: mcf = (JtestResourceAdapter) cccf.getMcf(); // ManagedConnectionFactory
323: mcf.setMatchNull(b);
324: }
325:
326: public int cntListeners() {
327: int i = 0;
328: ConnectionImpl conni = (ConnectionImpl) conn;
329: try {
330: JtestResourceAdapter mc = (JtestResourceAdapter) conni
331: .getMC(); //get ManagedConnection
332: i = mc.cntListeners();
333: logger.log(BasicLevel.DEBUG, cName + ".cntListeners cnt="
334: + i);
335: } catch (Exception e) {
336: logger.log(BasicLevel.DEBUG, cName
337: + ".cntListeners error: failed to count Listeners");
338: }
339: return i;
340: }
341: }
|