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