001/* 002 * Copyright 2002-2017 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 024import org.springframework.lang.Nullable; 025 026/** 027 * Convenient superclass for JNDI accessors, providing "jndiTemplate" 028 * and "jndiEnvironment" bean properties. 029 * 030 * @author Juergen Hoeller 031 * @since 1.1 032 * @see #setJndiTemplate 033 * @see #setJndiEnvironment 034 */ 035public class JndiAccessor { 036 037 /** 038 * Logger, available to subclasses. 039 */ 040 protected final Log logger = LogFactory.getLog(getClass()); 041 042 private JndiTemplate jndiTemplate = new JndiTemplate(); 043 044 045 /** 046 * Set the JNDI template to use for JNDI lookups. 047 * <p>You can also specify JNDI environment settings via "jndiEnvironment". 048 * @see #setJndiEnvironment 049 */ 050 public void setJndiTemplate(@Nullable JndiTemplate jndiTemplate) { 051 this.jndiTemplate = (jndiTemplate != null ? jndiTemplate : new JndiTemplate()); 052 } 053 054 /** 055 * Return the JNDI template to use for JNDI lookups. 056 */ 057 public JndiTemplate getJndiTemplate() { 058 return this.jndiTemplate; 059 } 060 061 /** 062 * Set the JNDI environment to use for JNDI lookups. 063 * <p>Creates a JndiTemplate with the given environment settings. 064 * @see #setJndiTemplate 065 */ 066 public void setJndiEnvironment(@Nullable Properties jndiEnvironment) { 067 this.jndiTemplate = new JndiTemplate(jndiEnvironment); 068 } 069 070 /** 071 * Return the JNDI environment to use for JNDI lookups. 072 */ 073 @Nullable 074 public Properties getJndiEnvironment() { 075 return this.jndiTemplate.getEnvironment(); 076 } 077 078}