001    /*
002     *  jDTAUS - DTAUS fileformat.
003     *  Copyright (c) 2005 Christian Schulte <cs@schulte.it>
004     *
005     *  This library is free software; you can redistribute it and/or
006     *  modify it under the terms of the GNU Lesser General Public
007     *  License as published by the Free Software Foundation; either
008     *  version 2.1 of the License, or any later version.
009     *
010     *  This library is distributed in the hope that it will be useful,
011     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013     *  Lesser General Public License for more details.
014     *
015     *  You should have received a copy of the GNU Lesser General Public
016     *  License along with this library; if not, write to the Free Software
017     *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
018     *
019     */
020    package org.jdtaus.core.container;
021    
022    import java.io.Serializable;
023    
024    /**
025     * Implementation context.
026     * <p>The context stores key-value pairs bound to a client. For every method
027     * invocation identical clients get identical contexts.</p>
028     *
029     * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
030     * @version $Id: Context.java 1914 2007-03-01 02:20:44Z schulte2005 $
031     *
032     * @see ContextFactory
033     */
034    public interface Context
035    {
036    
037        /**
038         * Gets an attribute from the context.
039         *
040         * @param key Key of the attribute to return.
041         *
042         * @return The attribute with key {@code key} or {@code null} if no
043         * such attribute is held by the context.
044         *
045         * @throws NullPointerException if {@code key} is {@code null}.
046         */
047        Object getAttribute(String key);
048    
049        /**
050         * Sets an attribute in the context.
051         *
052         * @param key Key of the attribute to store {@code o} with.
053         * @param o Object to store with key {@code key}.
054         *
055         * @return previous value associated with {@code key}, or {@code null}
056         * if there was no attribute for {@code key}. Returning {@code null} may
057         * also indicate that the context previously associated {@code null} with
058         * the specified key, if the implementation supports {@code null} values.
059         *
060         * @throws NullPointerException if {@code key} is {@code null}.
061         */
062        Object setAttribute(String key, Serializable o);
063    
064        /**
065         * Removes an attribute from the context.
066         *
067         * @param key Key of the attribute to remove.
068         *
069         * @return previous value associated with {@code key}, or {@code null}
070         * if there was no attribute for {@code key}. Returning {@code null} may
071         * also indicate that the context previously associated {@code null} with
072         * the specified key, if the implementation supports {@code null} values.
073         *
074         * @throws NullPointerException if {@code key} is {@code null}.
075         */
076        Object removeAttribute(String key);
077    
078    }