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