001 package com.mockrunner.ejb; 002 003 import javax.naming.Context; 004 005 /** 006 * Global configuration options regarding EJB and JNDI. 007 * Usually you do not have to change these options. 008 */ 009 public class Configuration 010 { 011 private String userTransactionJNDIName; 012 private boolean bindMockUserTransactionToJNDI; 013 private Context context; 014 015 public Configuration() 016 { 017 this("javax.transaction.UserTransaction"); 018 } 019 020 public Configuration(String userTransactionJNDIName) 021 { 022 this(userTransactionJNDIName, true); 023 } 024 025 public Configuration(String userTransactionJNDIName, boolean bindMockUserTransactionToJNDI) 026 { 027 this.userTransactionJNDIName = userTransactionJNDIName; 028 this.bindMockUserTransactionToJNDI = bindMockUserTransactionToJNDI; 029 this.context = null; 030 } 031 032 /** 033 * Get the JNDI context. This method returns <code>null</code> if no context 034 * is set. In this case the {@link com.mockrunner.mock.ejb.EJBMockObjectFactory} 035 * uses the MockEJB JNDI implementation. 036 * @return the JNDI context 037 */ 038 public Context getContext() 039 { 040 return context; 041 } 042 043 /** 044 * Set the JNDI context used by {@link com.mockrunner.mock.ejb.EJBMockObjectFactory}. 045 * @param context the JNDI context 046 */ 047 public void setContext(Context context) 048 { 049 this.context = context; 050 } 051 052 /** 053 * Get if the mock transaction should be bound to JNDI. 054 * @return if the mock transaction should be bound to JNDI 055 */ 056 public boolean getBindMockUserTransactionToJNDI() 057 { 058 return bindMockUserTransactionToJNDI; 059 } 060 061 /** 062 * Set if the mock transaction should be bound to JNDI. 063 * When the {@link com.mockrunner.mock.ejb.EJBMockObjectFactory} 064 * creates a {@link com.mockrunner.mock.ejb.MockUserTransaction}, 065 * it tries to rebind the transaction to the JNDI tree with the 066 * specified name {@link #setUserTransactionJNDIName}, the name 067 * <code>javax.transaction.UserTransaction</code> (which is used 068 * by MockEJB and Weblogic) and the name 069 * <code>java:comp/UserTransaction</code> (which is the standard name), 070 * if this option is <code>true</code>. 071 * If this option is <code>false</code>, a mock transaction is created 072 * but not bound to JNDI. 073 * Default is <code>true</code>. 074 * @param bindMockUserTransactionToJNDI should the mock transaction be bound to JNDI 075 */ 076 public void setBindMockUserTransactionToJNDI(boolean bindMockUserTransactionToJNDI) 077 { 078 this.bindMockUserTransactionToJNDI = bindMockUserTransactionToJNDI; 079 } 080 081 /** 082 * Get the JNDI name for the user transaction. 083 * @return the JNDI name for the user transaction 084 */ 085 public String getUserTransactionJNDIName() 086 { 087 return userTransactionJNDIName; 088 } 089 090 /** 091 * Set the JNDI name for the user transaction. The 092 * {@link com.mockrunner.mock.ejb.EJBMockObjectFactory} tries to 093 * obtain a <code>UserTransaction</code> from JNDI using this 094 * name. If the lookup fails, a {@link com.mockrunner.mock.ejb.MockUserTransaction} 095 * is created and bound to JNDI, if {@link #setBindMockUserTransactionToJNDI} is 096 * set to <code>true</code>. 097 * Default is <code>javax.transaction.UserTransaction</code>. 098 * @param userTransactionJNDIName the JNDI name for the user transaction 099 */ 100 public void setUserTransactionJNDIName(String userTransactionJNDIName) 101 { 102 this.userTransactionJNDIName = userTransactionJNDIName; 103 } 104 }