01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
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: */
16: package org.outerj.daisy.repository.serverimpl.query;
17:
18: import org.outerj.daisy.query.EvaluationInfo;
19: import org.outerj.daisy.query.ExtQueryContext;
20: import org.outerj.daisy.query.QueryContext;
21: import org.outerj.daisy.query.model.PredicateExpr;
22: import org.outerj.daisy.query.model.ExprDocData;
23: import org.outerj.daisy.repository.Document;
24: import org.outerj.daisy.repository.Version;
25: import org.outerj.daisy.repository.Repository;
26: import org.outerj.daisy.repository.query.PredicateExpression;
27: import org.outerj.daisy.repository.query.QueryException;
28: import org.outerj.daisy.repository.query.EvaluationContext;
29:
30: public class PredicateExpressionImpl implements PredicateExpression {
31: private PredicateExpr predicateExpr;
32: private QueryContext queryContext;
33:
34: protected PredicateExpressionImpl(PredicateExpr predicateExpr,
35: QueryContext queryContext) {
36: this .queryContext = queryContext;
37: this .predicateExpr = predicateExpr;
38: }
39:
40: public boolean evaluate(Document document, Version version)
41: throws QueryException {
42: return evaluate(document, version, version == null,
43: queryContext, null);
44: }
45:
46: public boolean evaluate(Document document, Version version,
47: boolean searchLastVersion) throws QueryException {
48: return evaluate(document, version, searchLastVersion,
49: queryContext, null);
50: }
51:
52: public boolean evaluate(Document document, Version version,
53: boolean searchLastVersion, Repository repository)
54: throws QueryException {
55: return evaluate(document, version, searchLastVersion,
56: new ExtQueryContext(repository), null);
57: }
58:
59: public boolean evaluate(Document document, Version version,
60: boolean searchLastVersion,
61: EvaluationContext evaluationContext) throws QueryException {
62: return evaluate(document, version, searchLastVersion,
63: queryContext, evaluationContext);
64: }
65:
66: public boolean evaluate(Document document, Version version,
67: boolean searchLastVersion,
68: EvaluationContext evaluationContext, Repository repository)
69: throws QueryException {
70: return evaluate(document, version, searchLastVersion,
71: new ExtQueryContext(repository), evaluationContext);
72: }
73:
74: private boolean evaluate(Document document, Version version,
75: boolean searchLastVersion, QueryContext queryContext,
76: EvaluationContext evaluationContext) throws QueryException {
77: if (document == null)
78: throw new IllegalArgumentException(
79: "document argument cannot be null");
80:
81: if (evaluationContext == null)
82: evaluationContext = new EvaluationContext();
83:
84: EvaluationInfo evaluationInfo = new EvaluationInfo(
85: queryContext, evaluationContext);
86: evaluationInfo.setSearchLastVersion(searchLastVersion);
87:
88: return predicateExpr.evaluate(
89: new ExprDocData(document, version), evaluationInfo);
90: }
91: }
|