001/*
002 *  jDTAUS Core RI Client Container
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.container.ri.client;
022
023import java.io.Serializable;
024import java.util.Collection;
025import java.util.Collections;
026import java.util.HashMap;
027import java.util.Map;
028import org.jdtaus.core.container.Context;
029
030/**
031 * {@code Context} reference implementation.
032 *
033 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
034 * @version $JDTAUS: DefaultContext.java 8743 2012-10-07 03:06:20Z schulte $
035 *
036 * @see org.jdtaus.core.container.ContextFactory
037 */
038public class DefaultContext implements Serializable, Context
039{
040    //--Constants---------------------------------------------------------------
041
042    /** Serial version UID for backwards compatibility with 1.0.x classes. */
043    private static final long serialVersionUID = -5373539407961564598L;
044
045    //---------------------------------------------------------------Constants--
046    //--Context-----------------------------------------------------------------
047
048    public Collection getObjectKeys()
049    {
050        return Collections.unmodifiableCollection( this.getMap().keySet() );
051    }
052
053    public Object getObject( final String key )
054    {
055        if ( key == null )
056        {
057            throw new NullPointerException( "key" );
058        }
059
060        return this.getMap().get( key );
061    }
062
063    public Object setObject( final String key, final Object o )
064    {
065        if ( key == null )
066        {
067            throw new NullPointerException( "key" );
068        }
069
070        return this.getMap().put( key, o );
071    }
072
073    public Object removeObject( final String key )
074    {
075        if ( key == null )
076        {
077            throw new NullPointerException( "key" );
078        }
079
080        return this.getMap().remove( key );
081    }
082
083    public final Object getAttribute( final String key )
084    {
085        return this.getObject( key );
086    }
087
088    public final Object setAttribute( final String key, final Serializable o )
089    {
090        return this.setObject( key, o );
091    }
092
093    public final Object removeAttribute( final String key )
094    {
095        return this.removeObject( key );
096    }
097
098    //-----------------------------------------------------------------Context--
099    //--DefaultContext----------------------------------------------------------
100
101    /**
102     * {@code Map} holding the key-value pairs.
103     * @serial
104     */
105    private final Map map = new HashMap( 100 );
106
107    /** Creates a new {@code DefaultContext} instance. */
108    public DefaultContext()
109    {
110        super();
111    }
112
113    /**
114     * Gets the {@code Map} backing the instance.
115     *
116     * @return map holding the context's key-value pairs.
117     */
118    protected Map getMap()
119    {
120        return this.map;
121    }
122
123    //----------------------------------------------------------DefaultContext--
124}