KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > MockDelegate


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.form;
16
17 import java.util.List JavaDoc;
18
19 import org.apache.tapestry.IMarkupWriter;
20 import org.apache.tapestry.IRender;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.valid.IFieldTracking;
23 import org.apache.tapestry.valid.IValidationDelegate;
24 import org.apache.tapestry.valid.IValidator;
25 import org.apache.tapestry.valid.ValidationConstraint;
26 import org.apache.tapestry.valid.ValidatorException;
27
28 /**
29  * Mock implementation of {@link org.apache.tapestry.valid.IValidationDelegate} used for testing
30  * (particularily, to test how the delegate decorates fields and field labels.
31  *
32  * @author Howard M. Lewis Ship
33  * @since 4.0
34  */

35 public class MockDelegate implements IValidationDelegate
36 {
37     private IFormComponent _component;
38
39     private String JavaDoc _input;
40
41     private boolean _inError;
42
43     public MockDelegate()
44     {
45         this(false);
46     }
47
48     public MockDelegate(boolean inError)
49     {
50         _inError = inError;
51     }
52
53     public IFormComponent getFormComponent()
54     {
55         return _component;
56     }
57
58     public void setFormComponent(IFormComponent component)
59     {
60         _component = component;
61     }
62
63     public boolean isInError()
64     {
65         return _inError;
66     }
67
68     public String JavaDoc getFieldInputValue()
69     {
70         return _input;
71     }
72
73     public List JavaDoc getFieldTracking()
74     {
75         return null;
76     }
77
78     public void reset()
79     {
80     }
81
82     public void clear()
83     {
84     }
85
86     public void recordFieldInputValue(String JavaDoc input)
87     {
88         _input = input;
89     }
90
91     public void record(ValidatorException ex)
92     {
93     }
94
95     public void record(String JavaDoc message, ValidationConstraint constraint)
96     {
97     }
98
99     public void record(IRender errorRenderer, ValidationConstraint constraint)
100     {
101     }
102
103     public void writePrefix(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component,
104             IValidator validator)
105     {
106         writer.begin("span");
107         writer.attribute("class", "prefix");
108     }
109
110     public void writeAttributes(IMarkupWriter writer, IRequestCycle cycle,
111             IFormComponent component, IValidator validator)
112     {
113         writer.attribute("class", "validation-delegate");
114     }
115
116     public void writeSuffix(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component,
117             IValidator validator)
118     {
119         writer.end();
120     }
121
122     public void writeLabelPrefix(IFormComponent component, IMarkupWriter writer, IRequestCycle cycle)
123     {
124     }
125
126     public void writeLabelSuffix(IFormComponent component, IMarkupWriter writer, IRequestCycle cycle)
127     {
128     }
129
130     public boolean getHasErrors()
131     {
132         return false;
133     }
134
135     public IFieldTracking getCurrentFieldTracking()
136     {
137         return null;
138     }
139
140     public List JavaDoc getErrorRenderers()
141     {
142         return null;
143     }
144
145 }
146
Popular Tags