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