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