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.builder.compexpr;
16:
17: import java.util.HashMap;
18: import java.util.Map;
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.araneaframework.backend.list.SqlExpression;
22: import org.araneaframework.backend.list.helper.builder.CompExprToSqlExprBuilder;
23: import org.araneaframework.backend.list.memorybased.ComparatorExpression;
24:
25: /**
26: * @author <a href="mailto:rein@araneaframework.org">Rein Raudjärv</a>
27: */
28: public class BaseCompExprToSqlExprBuilder implements
29: CompExprToSqlExprBuilder {
30: private static final Log log = LogFactory
31: .getLog(BaseCompExprToSqlExprBuilder.class);
32:
33: private Map translators = new HashMap();
34:
35: protected void addTranslator(Class expressionClass,
36: CompExprToSqlExprTranslator translator) {
37: this .translators.put(expressionClass, translator);
38: }
39:
40: public SqlExpression buildSqlExpression(
41: ComparatorExpression expression) {
42: if (log.isDebugEnabled()) {
43: log.debug("ComparatorExpression class: "
44: + expression.getClass().getName());
45: }
46: CompExprToSqlExprTranslator translator = (CompExprToSqlExprTranslator) this .translators
47: .get(expression.getClass());
48: if (translator == null) {
49: throw new RuntimeException("ComparatorExpression of class "
50: + expression.getClass() + " not supported");
51: }
52: return translator.translate(expression, this);
53: }
54: }
|