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.Arrays;
018    import java.util.Collection;
019    import java.util.Collections;
020    
021    import org.apache.hivemind.HiveMind;
022    import org.apache.hivemind.impl.BaseLocatable;
023    import org.apache.hivemind.util.Defense;
024    import org.apache.tapestry.TapestryUtils;
025    
026    /**
027     * Defines a formal parameter to a component. A
028     * <code>IParameterSpecification</code> is contained by a
029     * {@link IComponentSpecification}.
030     * <p>
031     * TBD: Identify arrays in some way.
032     * 
033     * @author Howard Lewis Ship
034     */
035    
036    public class ParameterSpecification extends BaseLocatable implements
037            IParameterSpecification
038    {
039    
040        private boolean _required = false;
041    
042        private String _type;
043    
044        /** @since 1.0.9 */
045        private String _description;
046    
047        /** @since 2.0.3 */
048        private String _propertyName;
049    
050        /** @since 3.0 */
051        private String _defaultValue;
052    
053        /** @since 4.0 */
054        private boolean _cache = true;
055    
056        /** @since 4.0 */
057        private Collection _aliasNames = Collections.EMPTY_LIST;
058    
059        /** @since 4.0 */
060        private String _parameterName;
061    
062        /** @since 4.0 */
063        private boolean _deprecated = false;
064    
065        /**
066         * Returns the class name of the expected type of the parameter. The default
067         * value is <code>java.lang.Object</code> which matches anything.
068         */
069    
070        public String getType()
071        {
072            return _type;
073        }
074    
075        /**
076         * Returns true if the parameter is required by the component. The default
077         * is false, meaning the parameter is optional.
078         */
079    
080        public boolean isRequired()
081        {
082            return _required;
083        }
084    
085        public void setRequired(boolean value)
086        {
087            _required = value;
088        }
089    
090        /**
091         * Sets the type of value expected for the parameter. This can be left blank
092         * to indicate any type.
093         */
094    
095        public void setType(String value)
096        {
097            _type = value;
098        }
099    
100        /**
101         * Returns the documentation for this parameter.
102         * 
103         * @since 1.0.9
104         */
105    
106        public String getDescription()
107        {
108            return _description;
109        }
110    
111        /**
112         * Sets the documentation for this parameter.
113         * 
114         * @since 1.0.9
115         */
116    
117        public void setDescription(String description)
118        {
119            _description = description;
120        }
121    
122        /**
123         * Sets the property name (of the component class) to connect the parameter
124         * to.
125         */
126    
127        public void setPropertyName(String propertyName)
128        {
129            _propertyName = propertyName;
130        }
131    
132        /**
133         * Returns the name of the JavaBeans property to connect the parameter to.
134         */
135    
136        public String getPropertyName()
137        {
138            return _propertyName;
139        }
140    
141        /**
142         * @see org.apache.tapestry.spec.IParameterSpecification#getDefaultValue()
143         */
144        public String getDefaultValue()
145        {
146            return _defaultValue;
147        }
148    
149        /**
150         * @see org.apache.tapestry.spec.IParameterSpecification#setDefaultValue(java.lang.String)
151         */
152        public void setDefaultValue(String defaultValue)
153        {
154            _defaultValue = defaultValue;
155        }
156    
157        /** @since 4.0 */
158        public boolean getCache()
159        {
160            return _cache;
161        }
162    
163        /** @since 4.0 */
164        public void setCache(boolean cache)
165        {
166            _cache = cache;
167        }
168    
169        /** @since 4.0 */
170        public Collection getAliasNames()
171        {
172            return _aliasNames;
173        }
174    
175        /** @since 4.0 */
176        public String getParameterName()
177        {
178            return _parameterName;
179        }
180    
181        /** @since 4.0 */
182        public void setAliases(String nameList)
183        {
184            if (HiveMind.isNonBlank(nameList))
185            {
186                String[] names = TapestryUtils.split(nameList);
187    
188                _aliasNames = Arrays.asList(names);
189            }
190        }
191    
192        /** @since 4.0 */
193        public void setParameterName(String name)
194        {
195            Defense.notNull(name, "name");
196    
197            _parameterName = name;
198        }
199    
200        /** @since 4.0 */
201        public boolean isDeprecated()
202        {
203            return _deprecated;
204        }
205    
206        /** @since 4.0 */
207        public void setDeprecated(boolean deprecated)
208        {
209            _deprecated = deprecated;
210        }
211    
212    }