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.valid;
016    
017    import java.io.Serializable;
018    
019    import org.apache.hivemind.util.Defense;
020    import org.apache.tapestry.IRender;
021    import org.apache.tapestry.form.IFormComponent;
022    
023    /**
024     * Default implementation of {@link IFieldTracking}.
025     * 
026     * @author Howard Lewis Ship
027     * @since 1.0.8
028     */
029    
030    public class FieldTracking implements IFieldTracking, Serializable
031    {
032    
033        private static final long serialVersionUID = -5397563163968532716L;
034    
035        private transient IFormComponent _component;
036    
037        private String _input;
038    
039        private IRender _renderer;
040    
041        private String _fieldName;
042    
043        private ValidationConstraint _constraint;
044    
045        /**
046         * Constructor used for unassociated errors; errors that are not about any
047         * particular field within the form.
048         */
049    
050        FieldTracking()
051        {
052        }
053    
054        /**
055         * Standard constructor for a field (with the given name), rendered by the
056         * specified component.
057         */
058    
059        FieldTracking(String fieldName, IFormComponent component)
060        {
061            Defense.notNull(fieldName, "fieldName");
062            Defense.notNull(component, "component");
063    
064            _fieldName = fieldName;
065            _component = component;
066        }
067    
068        public IFormComponent getComponent()
069        {
070            return _component;
071        }
072    
073        public IRender getErrorRenderer()
074        {
075            return _renderer;
076        }
077    
078        public void setErrorRenderer(IRender value)
079        {
080            _renderer = value;
081        }
082    
083        public String getInput()
084        {
085            return _input;
086        }
087    
088        public void setInput(String value)
089        {
090            _input = value;
091        }
092    
093        public String getFieldName()
094        {
095            return _fieldName;
096        }
097    
098        public ValidationConstraint getConstraint()
099        {
100            return _constraint;
101        }
102    
103        public void setConstraint(ValidationConstraint constraint)
104        {
105            _constraint = constraint;
106        }
107    
108        /** @since 3.0 * */
109    
110        public boolean isInError()
111        {
112            return _renderer != null;
113        }
114    
115    }