001    // SECTION-START[License Header]
002    /*
003     *   Copyright (c) 2009 The JOMC Project
004     *   Copyright (c) 2005 Christian Schulte <cs@jomc.org>
005     *   All rights reserved.
006     *
007     *   Redistribution and use in source and binary forms, with or without
008     *   modification, are permitted provided that the following conditions
009     *   are met:
010     *
011     *     o Redistributions of source code must retain the above copyright
012     *       notice, this list of conditions and the following disclaimer.
013     *
014     *     o Redistributions in binary form must reproduce the above copyright
015     *       notice, this list of conditions and the following disclaimer in
016     *       the documentation and/or other materials provided with the
017     *       distribution.
018     *
019     *   THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
020     *   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021     *   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
022     *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
023     *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
024     *   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
025     *   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
026     *   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
027     *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
028     *   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
029     *   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     *
031     *   $Id: DefaultScope.java 540 2009-09-21 18:50:19Z schulte2005 $
032     *
033     */
034    // SECTION-END
035    package org.jomc.ri;
036    
037    import java.util.Map;
038    import org.jomc.spi.Scope;
039    
040    // SECTION-START[Documentation]
041    /**
042     * Default {@code Scope} implementation.
043     *
044     * @author <a href="mailto:cs@jomc.org">Christian Schulte</a> 1.0
045     * @version $Id: DefaultScope.java 540 2009-09-21 18:50:19Z schulte2005 $
046     */
047    // SECTION-END
048    // SECTION-START[Annotations]
049    @javax.annotation.Generated( value = "org.jomc.tools.JavaSources",
050                                 comments = "See http://jomc.sourceforge.net/jomc/1.0-alpha-1/jomc-tools" )
051    // SECTION-END
052    public class DefaultScope implements Scope
053    {
054        // SECTION-START[DefaultScope]
055    
056        /** Objects of the scope. */
057        private Map<String, Object> objects;
058    
059        /**
060         * Creates a new {@code DefaultScope} instance taking a map backing the scope.
061         *
062         * @param map The map backing the scope or {@code null}.
063         */
064        public DefaultScope( final Map<String, Object> map )
065        {
066            this.objects = map;
067        }
068    
069        public Map<String, Object> getObjects()
070        {
071            return this.objects;
072        }
073    
074        public Object getObject( final String instance )
075        {
076            if ( this.getObjects() != null )
077            {
078                return this.getObjects().get( instance );
079            }
080    
081            return null;
082        }
083    
084        public Object putObject( final String instance, final Object object )
085        {
086            if ( this.getObjects() != null )
087            {
088                return this.getObjects().put( instance, object );
089            }
090    
091            return null;
092        }
093    
094        public Object removeObject( final String instance )
095        {
096            if ( this.getObjects() != null )
097            {
098                return this.getObjects().remove( instance );
099            }
100    
101            return null;
102        }
103    
104        // SECTION-END
105        // SECTION-START[Constructors]
106    
107        /** Creates a new {@code DefaultScope} instance. */
108        @javax.annotation.Generated( value = "org.jomc.tools.JavaSources",
109                                     comments = "See http://jomc.sourceforge.net/jomc/1.0-alpha-1/jomc-tools" )
110        public DefaultScope()
111        {
112            // SECTION-START[Default Constructor]
113            super();
114            // SECTION-END
115        }
116        // SECTION-END
117        // SECTION-START[Dependencies]
118        // SECTION-END
119        // SECTION-START[Properties]
120        // SECTION-END
121        // SECTION-START[Messages]
122        // SECTION-END
123    }