001/* 002 * Copyright 2002-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jndi; 018 019import java.util.Properties; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023 024/** 025 * Convenient superclass for JNDI accessors, providing "jndiTemplate" 026 * and "jndiEnvironment" bean properties. 027 * 028 * @author Juergen Hoeller 029 * @since 1.1 030 * @see #setJndiTemplate 031 * @see #setJndiEnvironment 032 */ 033public class JndiAccessor { 034 035 /** 036 * Logger, available to subclasses. 037 */ 038 protected final Log logger = LogFactory.getLog(getClass()); 039 040 private JndiTemplate jndiTemplate = new JndiTemplate(); 041 042 043 /** 044 * Set the JNDI template to use for JNDI lookups. 045 * <p>You can also specify JNDI environment settings via "jndiEnvironment". 046 * @see #setJndiEnvironment 047 */ 048 public void setJndiTemplate(JndiTemplate jndiTemplate) { 049 this.jndiTemplate = (jndiTemplate != null ? jndiTemplate : new JndiTemplate()); 050 } 051 052 /** 053 * Return the JNDI template to use for JNDI lookups. 054 */ 055 public JndiTemplate getJndiTemplate() { 056 return this.jndiTemplate; 057 } 058 059 /** 060 * Set the JNDI environment to use for JNDI lookups. 061 * <p>Creates a JndiTemplate with the given environment settings. 062 * @see #setJndiTemplate 063 */ 064 public void setJndiEnvironment(Properties jndiEnvironment) { 065 this.jndiTemplate = new JndiTemplate(jndiEnvironment); 066 } 067 068 /** 069 * Return the JNDI environment to use for JNDI lookups. 070 */ 071 public Properties getJndiEnvironment() { 072 return this.jndiTemplate.getEnvironment(); 073 } 074 075}