KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > transaction > TransactionManagerJndiLookup


1 /*
2  * Copyright (C) 2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.transaction;
18
19 import java.util.Properties JavaDoc;
20
21 import javax.transaction.TransactionManager JavaDoc;
22
23 import org.jboss.cache.TransactionManagerLookup;
24 import org.springframework.jndi.JndiObjectFactoryBean;
25 import org.springframework.jndi.JndiTemplate;
26
27 /**
28  * Helper lookup class to supply JBoss components with a <code>TransactionManager</code>.
29  * <p>
30  * The <code>JBossTransactionManagerLookup</code> will work when Alfresco is running in JBoss,
31  * but the <code>TreeCache</code> can be used within other containers; there might not be any
32  * container and the <code>TransactionManager</code> may held in a local JNDI tree.
33  * <p>
34  * For compatibility with other app servers, the JBoss <code>GenericTransactionManagerLookup</code>
35  * could also be used.
36  * <p>
37  * The default constructor configures the object to look in <b>java:/TransactionManager</b>
38  * for a <code>TransactionManager</code>. The only customisation that should be required is
39  * to change the {@link #setJndiName(String) jndiName} property. If more JNDI details need
40  * changing, then the actual {@link #setJndiLookup(JndiObjectFactoryBean) jndiLookup object} can
41  * be substituted with a customized version.
42  *
43  * @author Derek Hulley
44  */

45 public class TransactionManagerJndiLookup implements TransactionManagerLookup
46 {
47     public static final String JavaDoc DEFAULT_JNDI_NAME = "java:/TransactionManager";
48     
49     private JndiObjectFactoryBean jndiLookup;
50     
51     public TransactionManagerJndiLookup()
52     {
53         jndiLookup = new JndiObjectFactoryBean();
54         jndiLookup.setJndiName(DEFAULT_JNDI_NAME);
55         jndiLookup.setProxyInterface(TransactionManager JavaDoc.class);
56     }
57     
58     /**
59      * @see org.springframework.jndi.JndiAccessor#setJndiTemplate(org.springframework.jndi.JndiTemplate)
60      */

61     public void setJndiTemplate(JndiTemplate jndiTemplate)
62     {
63         this.jndiLookup.setJndiTemplate(jndiTemplate);
64     }
65
66     /**
67      * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment(java.util.Properties)
68      */

69     public void setJndiEnvironment(Properties JavaDoc jndiEnvironment)
70     {
71         this.jndiLookup.setJndiEnvironment(jndiEnvironment);
72     }
73
74     /**
75      * Set the JNDI location where the <code>TransactionManager</code> can be found.
76      *
77      * @param jndiName
78      */

79     public void setJndiName(String JavaDoc jndiName)
80     {
81         jndiLookup.setJndiName(jndiName);
82     }
83
84     /**
85      * @return Returns a <code>TransactionManager</code> looked up at the JNDI location
86      */

87     public TransactionManager JavaDoc getTransactionManager() throws Exception JavaDoc
88     {
89         return (TransactionManager JavaDoc) jndiLookup.getObject();
90     }
91 }
92
Popular Tags