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.backend.list.helper;
16:
17: import java.util.HashMap;
18: import java.util.Map;
19:
20: import org.araneaframework.backend.list.helper.builder.ValueConverter;
21: import org.araneaframework.backend.list.memorybased.expression.Value;
22: import org.araneaframework.core.Assert;
23: import org.araneaframework.uilib.list.util.Converter;
24:
25: /**
26: * ValueConverter that has a map of Value names and their <code>Converter</code>
27: * objects.
28: *
29: * @see Converter
30: *
31: * @author Rein Raudjärv
32: *
33: * @since 1.1
34: */
35: public class StandardValueConverter implements ValueConverter {
36:
37: /** Value name --> Converter that is used by convert() method */
38: private final Map converters = new HashMap();
39:
40: public void addConverter(String valueName, Converter converter) {
41: Assert.notNullParam(converter, "converter");
42: this .converters.put(valueName, converter);
43: }
44:
45: public Object convert(Value value) {
46: // Find Converter
47: Converter converter = (Converter) this .converters.get(value
48: .getName());
49: if (converter == null) {
50: // No Converter registered
51: return value.getValue();
52: }
53:
54: // Convert
55: return converter.convert(value.getValue());
56: }
57: }
|