01: package com.mockrunner.ejb;
02:
03: import javax.naming.Context;
04:
05: /**
06: * Global configuration options regarding EJB and JNDI.
07: * Usually you do not have to change these options.
08: */
09: public class Configuration {
10: private String userTransactionJNDIName;
11: private boolean bindMockUserTransactionToJNDI;
12: private Context context;
13:
14: public Configuration() {
15: this ("javax.transaction.UserTransaction");
16: }
17:
18: public Configuration(String userTransactionJNDIName) {
19: this (userTransactionJNDIName, true);
20: }
21:
22: public Configuration(String userTransactionJNDIName,
23: boolean bindMockUserTransactionToJNDI) {
24: this .userTransactionJNDIName = userTransactionJNDIName;
25: this .bindMockUserTransactionToJNDI = bindMockUserTransactionToJNDI;
26: this .context = null;
27: }
28:
29: /**
30: * Get the JNDI context. This method returns <code>null</code> if no context
31: * is set. In this case the {@link com.mockrunner.mock.ejb.EJBMockObjectFactory}
32: * uses the MockEJB JNDI implementation.
33: * @return the JNDI context
34: */
35: public Context getContext() {
36: return context;
37: }
38:
39: /**
40: * Set the JNDI context used by {@link com.mockrunner.mock.ejb.EJBMockObjectFactory}.
41: * @param context the JNDI context
42: */
43: public void setContext(Context context) {
44: this .context = context;
45: }
46:
47: /**
48: * Get if the mock transaction should be bound to JNDI.
49: * @return if the mock transaction should be bound to JNDI
50: */
51: public boolean getBindMockUserTransactionToJNDI() {
52: return bindMockUserTransactionToJNDI;
53: }
54:
55: /**
56: * Set if the mock transaction should be bound to JNDI.
57: * When the {@link com.mockrunner.mock.ejb.EJBMockObjectFactory}
58: * creates a {@link com.mockrunner.mock.ejb.MockUserTransaction},
59: * it tries to rebind the transaction to the JNDI tree with the
60: * specified name {@link #setUserTransactionJNDIName}, the name
61: * <code>javax.transaction.UserTransaction</code> (which is used
62: * by MockEJB and Weblogic) and the name
63: * <code>java:comp/UserTransaction</code> (which is the standard name),
64: * if this option is <code>true</code>.
65: * If this option is <code>false</code>, a mock transaction is created
66: * but not bound to JNDI.
67: * Default is <code>true</code>.
68: * @param bindMockUserTransactionToJNDI should the mock transaction be bound to JNDI
69: */
70: public void setBindMockUserTransactionToJNDI(
71: boolean bindMockUserTransactionToJNDI) {
72: this .bindMockUserTransactionToJNDI = bindMockUserTransactionToJNDI;
73: }
74:
75: /**
76: * Get the JNDI name for the user transaction.
77: * @return the JNDI name for the user transaction
78: */
79: public String getUserTransactionJNDIName() {
80: return userTransactionJNDIName;
81: }
82:
83: /**
84: * Set the JNDI name for the user transaction. The
85: * {@link com.mockrunner.mock.ejb.EJBMockObjectFactory} tries to
86: * obtain a <code>UserTransaction</code> from JNDI using this
87: * name. If the lookup fails, a {@link com.mockrunner.mock.ejb.MockUserTransaction}
88: * is created and bound to JNDI, if {@link #setBindMockUserTransactionToJNDI} is
89: * set to <code>true</code>.
90: * Default is <code>javax.transaction.UserTransaction</code>.
91: * @param userTransactionJNDIName the JNDI name for the user transaction
92: */
93: public void setUserTransactionJNDIName(
94: String userTransactionJNDIName) {
95: this.userTransactionJNDIName = userTransactionJNDIName;
96: }
97: }
|