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.Map;
18: import org.araneaframework.backend.list.memorybased.Variable;
19: import org.araneaframework.backend.list.memorybased.expression.VariableResolver;
20:
21: /**
22: * VariableResolver that has a map of Variable names and their resolvable
23: * values.
24: */
25: public class VariableMapper implements VariableResolver {
26: private Map map;
27:
28: public VariableMapper(Map map) {
29: if (map == null) {
30: throw new RuntimeException("Mapping must be provided");
31: }
32: this .map = map;
33: }
34:
35: public Object resolve(Variable variable) {
36: if (variable == null) {
37: throw new RuntimeException("Variable must be provided");
38: }
39: String name = variable.getName();
40: if (name == null) {
41: throw new RuntimeException("Variable name must be provided");
42: }
43: Object result = this .map.get(name);
44: if (result == null) {
45: throw new RuntimeException("Variable " + name
46: + " not supported");
47: }
48: return result;
49: }
50: }
|