001/*
002 * Copyright 2002-2018 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 javax.naming.Context;
020import javax.naming.NamingException;
021
022import org.springframework.lang.Nullable;
023
024/**
025 * Callback interface to be implemented by classes that need to perform an
026 * operation (such as a lookup) in a JNDI context. This callback approach
027 * is valuable in simplifying error handling, which is performed by the
028 * JndiTemplate class. This is a similar to JdbcTemplate's approach.
029 *
030 * <p>Note that there is hardly any need to implement this callback
031 * interface, as JndiTemplate provides all usual JNDI operations via
032 * convenience methods.
033 *
034 * @author Rod Johnson
035 * @param <T> the resulting object type
036 * @see JndiTemplate
037 * @see org.springframework.jdbc.core.JdbcTemplate
038 */
039@FunctionalInterface
040public interface JndiCallback<T> {
041
042        /**
043         * Do something with the given JNDI context.
044         * <p>Implementations don't need to worry about error handling
045         * or cleanup, as the JndiTemplate class will handle this.
046         * @param ctx the current JNDI context
047         * @throws NamingException if thrown by JNDI methods
048         * @return a result object, or {@code null}
049         */
050        @Nullable
051        T doInContext(Context ctx) throws NamingException;
052
053}
054