01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.uilib.form.converter;
16:
17: import org.araneaframework.uilib.form.Converter;
18: import org.araneaframework.uilib.form.FormElementContext;
19:
20: /**
21: * Reverses the conversion of a contained converter.
22: *
23: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
24: *
25: */
26: public class ReverseConverter extends BaseConverter {
27:
28: protected Converter toReverse;
29:
30: /**
31: * Creates class initializing the contained converter.
32: *
33: * @param toReverse converter that will be reversed.
34: */
35: public ReverseConverter(Converter toReverse) {
36: this .toReverse = toReverse;
37: }
38:
39: /**
40: * Converts the data using {@link BaseConverter#reverseConvertNotNull}of the
41: * contained converter.
42: */
43: public Object convertNotNull(Object data) {
44: Object result = toReverse.reverseConvert(data);
45: return result;
46: }
47:
48: /**
49: * Converts the data using {@link BaseConverter#convertNotNull}of the
50: * contained converter.
51: */
52: public Object reverseConvertNotNull(Object data) {
53: Object result = toReverse.convert(data);
54: return result;
55: }
56:
57: public void setFormElementCtx(FormElementContext feCtx) {
58: super .setFormElementCtx(feCtx);
59:
60: toReverse.setFormElementCtx(feCtx);
61: }
62:
63: /**
64: * Returns a <code>new ReverseConverter(toReverse)</code>.
65: */
66: public Converter newConverter() {
67: return new ReverseConverter(toReverse.newConverter());
68: }
69: }
|