001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.util;
016    
017    import java.util.*;
018    
019    /**
020     *  Base class implementation for the {@link IPropertyHolder} interface.
021     *
022     *
023     *  @author Howard Lewis Ship
024     *
025     */
026    
027    public class BasePropertyHolder implements IPropertyHolder
028    {
029        private static final int MAP_SIZE = 7;
030        private Map properties;
031    
032        public String getProperty(String name)
033        {
034            if (properties == null)
035                return null;
036    
037            return (String) properties.get(name);
038        }
039    
040        public void setProperty(String name, String value)
041        {
042            if (value == null)
043            {
044                removeProperty(name);
045                return;
046            }
047    
048            if (properties == null)
049                properties = new HashMap(MAP_SIZE);
050    
051            properties.put(name, value);
052        }
053    
054        public void removeProperty(String name)
055        {
056            if (properties == null)
057                return;
058    
059            properties.remove(name);
060        }
061    
062        public List getPropertyNames()
063        {
064            if (properties == null)
065                return Collections.EMPTY_LIST;
066    
067            List result = new ArrayList(properties.keySet());
068            
069            Collections.sort(result);
070            
071            return result;
072        }
073    
074    }