01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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;
16:
17: import org.apache.tapestry.ioc.Messages;
18: import org.apache.tapestry.services.ValidationMessagesSource;
19:
20: /**
21: * Translates between client-side and server-side values. Client-side values are always strings.
22: *
23: * @param <T>
24: */
25: public interface Translator<T> {
26: /**
27: * Converts a server-side value to a client-side string. This allows for formatting of the value
28: * in a way appropriate to the end user. The output client value should be parsable by
29: * {@link #parseClient(String, Messages)}.
30: *
31: * @param value
32: * the server side value (which may be null)
33: * @return client-side value to present to the user
34: */
35: String toClient(T value);
36:
37: /**
38: * Converts a submitted request value into an appropriate server side value.
39: *
40: * @param clientValue
41: * (possibly null or the empty string)
42: * @param messages
43: * validator messages assembled by {@link ValidationMessagesSource}
44: * @return equivalent server-side value (possibly null)
45: * @throws ValidationException
46: * if the value can not be parsed
47: */
48: T parseClient(String clientValue, Messages messages)
49: throws ValidationException;
50: }
|