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.spec;
016    
017    import java.util.Collection;
018    import java.util.Collections;
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    /**
023     * Defines a contained component. This includes the information needed to get the contained
024     * component's specification, as well as any bindings for the component.
025     * 
026     * @author Howard Lewis Ship
027     */
028    
029    public class ContainedComponent extends LocatablePropertyHolder implements IContainedComponent
030    {
031        private static final int MAP_SIZE = 3;
032        
033        protected Map _bindings;
034        
035        private String _type;
036    
037        private String _copyOf;
038    
039        private boolean _inheritInformalParameters;
040    
041        /** @since 4.0 */
042        private String _propertyName;
043    
044        /**
045         * Returns the named binding, or null if the binding does not exist.
046         */
047    
048        public IBindingSpecification getBinding(String name)
049        {
050            if (_bindings == null)
051                return null;
052    
053            return (IBindingSpecification) _bindings.get(name);
054        }
055    
056        /**
057         * Returns an umodifiable <code>Collection</code> of Strings, each the name of one binding for
058         * the component.
059         */
060    
061        public Collection getBindingNames()
062        {
063            if (_bindings == null)
064                return Collections.EMPTY_LIST;
065    
066            return Collections.unmodifiableCollection(_bindings.keySet());
067        }
068    
069        public String getType()
070        {
071            return _type;
072        }
073    
074        public void setBinding(String name, IBindingSpecification spec)
075        {
076            if (_bindings == null)
077                _bindings = new HashMap(MAP_SIZE);
078    
079            _bindings.put(name, spec);
080        }
081    
082        public void setType(String value)
083        {
084            _type = value;
085        }
086        
087        /**
088         * Sets the String Id of the component being copied from. For use by IDE tools like Spindle.
089         * 
090         * @since 1.0.9
091         */
092    
093        public void setCopyOf(String id)
094        {
095            _copyOf = id;
096        }
097    
098        /**
099         * Returns the id of the component being copied from. For use by IDE tools like Spindle.
100         * 
101         * @since 1.0.9
102         */
103    
104        public String getCopyOf()
105        {
106            return _copyOf;
107        }
108    
109        /**
110         * Returns whether the contained component will inherit the informal parameters of its parent.
111         * 
112         * @since 3.0
113         */
114        public boolean getInheritInformalParameters()
115        {
116            return _inheritInformalParameters;
117        }
118    
119        /**
120         * Sets whether the contained component will inherit the informal parameters of its parent.
121         * 
122         * @since 3.0
123         */
124        public void setInheritInformalParameters(boolean value)
125        {
126            _inheritInformalParameters = value;
127        }
128    
129        /** @since 4.0 */
130        public String getPropertyName()
131        {
132            return _propertyName;
133        }
134    
135        /** @since 4.0 */
136        public void setPropertyName(String propertyName)
137        {
138            _propertyName = propertyName;
139        }
140    }