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.list.structure.filter.field;
16:
17: import java.util.Map;
18: import org.apache.commons.lang.Validate;
19: import org.araneaframework.backend.list.memorybased.expression.constant.ValueExpression;
20: import org.araneaframework.backend.list.memorybased.expression.variable.VariableExpression;
21: import org.araneaframework.uilib.list.structure.filter.BaseFilter;
22: import org.araneaframework.uilib.list.structure.filter.FieldFilter;
23: import org.araneaframework.uilib.list.util.ExpressionUtil;
24:
25: /**
26: * Base implementation for {@link FieldFilter}.
27: *
28: * @author <a href="mailto:rein@araneaframework.org">Rein Raudjärv</a>
29: */
30: public abstract class BaseFieldFilter extends BaseFilter implements
31: FieldFilter {
32:
33: // Field
34: private String fieldId;
35:
36: // Value
37: private String valueId;
38: private Object value;
39: private boolean constant = false;
40:
41: public String getFieldId() {
42: return this .fieldId;
43: }
44:
45: public void setFieldId(String fieldId) {
46: Validate.notNull(fieldId);
47: this .fieldId = fieldId;
48: }
49:
50: public String getValueId() {
51: return this .valueId;
52: }
53:
54: public void setValueId(String valueId) {
55: this .valueId = valueId;
56: }
57:
58: public Object getValue() {
59: return value;
60: }
61:
62: public void setValue(Object value) {
63: this .value = value;
64: this .constant = true;
65: }
66:
67: public boolean isConstant() {
68: return constant;
69: }
70:
71: // Building expressions
72:
73: protected boolean isActive(Map filterInfo) {
74: return isConstant() || filterInfo.containsKey(getValueId());
75: }
76:
77: protected VariableExpression buildVariableExpression() {
78: return ExpressionUtil.var(getFieldId());
79: }
80:
81: protected ValueExpression buildValueExpression(Map filterInfo) {
82: Object val = isConstant() ? getValue() : filterInfo
83: .get(getValueId());
84: return ExpressionUtil.value(getValueId(), val);
85: }
86: }
|