2
* Copyright Terracotta, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
package net.sf.ehcache.transaction.manager.selector;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
21
import javax.naming.InitialContext;
22
import javax.naming.NamingException;
23
import javax.transaction.TransactionManager;
26
* Abstract selector performing JNDI lookup
28
* @author Ludovic Orban
30
public abstract class JndiSelector extends Selector {
31
private static final Logger LOG = LoggerFactory.getLogger(JndiSelector.class);
33
private volatile String jndiName;
38
* @param vendor the transaction manager vendor name
39
* @param jndiName the JNDI name to look up
41
public JndiSelector(String vendor, String jndiName) {
43
this.jndiName = jndiName;
47
* Get the configured JNDI name to look up
48
* @return the JNDI name to look up
50
public String getJndiName() {
55
* Set the configured JNDI name to look up
56
* @param jndiName the JNDI name to look up
58
public void setJndiName(String jndiName) {
59
this.jndiName = jndiName;
66
protected TransactionManager doLookup() {
67
InitialContext initialContext;
69
initialContext = new InitialContext();
70
} catch (NamingException ne) {
71
LOG.debug("cannot create initial context", ne);
78
jndiObject = initialContext.lookup(getJndiName());
79
if (jndiObject instanceof TransactionManager) {
80
return (TransactionManager) jndiObject;
82
} catch (NamingException e) {
83
LOG.debug("Couldn't locate TransactionManager for {} under {}", getVendor(), getJndiName());
88
initialContext.close();
89
} catch (NamingException ne) {
90
LOG.warn("error closing initial context", ne);
b'\\ No newline at end of file'