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.ArrayList;
018    import java.util.Collections;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    /**
024     *  Base class implementation for the {@link IPropertyHolder} interface.
025     *
026     *
027     *  @author Howard Lewis Ship
028     *
029     **/
030    
031    public class BasePropertyHolder implements IPropertyHolder
032    {
033        private static final int MAP_SIZE = 7;
034        private Map properties;
035    
036        public String getProperty(String name)
037        {
038            if (properties == null)
039                return null;
040    
041            return (String) properties.get(name);
042        }
043    
044        public void setProperty(String name, String value)
045        {
046            if (value == null)
047            {
048                removeProperty(name);
049                return;
050            }
051    
052            if (properties == null)
053                properties = new HashMap(MAP_SIZE);
054    
055            properties.put(name, value);
056        }
057    
058        public void removeProperty(String name)
059        {
060            if (properties == null)
061                return;
062    
063            properties.remove(name);
064        }
065    
066        public List getPropertyNames()
067        {
068            if (properties == null)
069                return Collections.EMPTY_LIST;
070    
071            List result = new ArrayList(properties.keySet());
072            
073            Collections.sort(result);
074            
075            return result;
076        }
077    
078    }