| 1 | /* |
| 2 | * jDTAUS Core RI Client Container |
| 3 | * Copyright (C) 2005 Christian Schulte |
| 4 | * <cs@schulte.it> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | package org.jdtaus.core.container.ri.client; |
| 22 | |
| 23 | import java.io.Serializable; |
| 24 | import java.util.Collection; |
| 25 | import java.util.Collections; |
| 26 | import java.util.HashMap; |
| 27 | import java.util.Map; |
| 28 | import org.jdtaus.core.container.Context; |
| 29 | |
| 30 | /** |
| 31 | * {@code Context} reference implementation. |
| 32 | * |
| 33 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
| 34 | * @version $JDTAUS: DefaultContext.java 8743 2012-10-07 03:06:20Z schulte $ |
| 35 | * |
| 36 | * @see org.jdtaus.core.container.ContextFactory |
| 37 | */ |
| 38 | public class DefaultContext implements Serializable, Context |
| 39 | { |
| 40 | //--Constants--------------------------------------------------------------- |
| 41 | |
| 42 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
| 43 | private static final long serialVersionUID = -5373539407961564598L; |
| 44 | |
| 45 | //---------------------------------------------------------------Constants-- |
| 46 | //--Context----------------------------------------------------------------- |
| 47 | |
| 48 | public Collection getObjectKeys() |
| 49 | { |
| 50 | return Collections.unmodifiableCollection( this.getMap().keySet() ); |
| 51 | } |
| 52 | |
| 53 | public Object getObject( final String key ) |
| 54 | { |
| 55 | if ( key == null ) |
| 56 | { |
| 57 | throw new NullPointerException( "key" ); |
| 58 | } |
| 59 | |
| 60 | return this.getMap().get( key ); |
| 61 | } |
| 62 | |
| 63 | public Object setObject( final String key, final Object o ) |
| 64 | { |
| 65 | if ( key == null ) |
| 66 | { |
| 67 | throw new NullPointerException( "key" ); |
| 68 | } |
| 69 | |
| 70 | return this.getMap().put( key, o ); |
| 71 | } |
| 72 | |
| 73 | public Object removeObject( final String key ) |
| 74 | { |
| 75 | if ( key == null ) |
| 76 | { |
| 77 | throw new NullPointerException( "key" ); |
| 78 | } |
| 79 | |
| 80 | return this.getMap().remove( key ); |
| 81 | } |
| 82 | |
| 83 | public final Object getAttribute( final String key ) |
| 84 | { |
| 85 | return this.getObject( key ); |
| 86 | } |
| 87 | |
| 88 | public final Object setAttribute( final String key, final Serializable o ) |
| 89 | { |
| 90 | return this.setObject( key, o ); |
| 91 | } |
| 92 | |
| 93 | public final Object removeAttribute( final String key ) |
| 94 | { |
| 95 | return this.removeObject( key ); |
| 96 | } |
| 97 | |
| 98 | //-----------------------------------------------------------------Context-- |
| 99 | //--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 | } |