01: /**
02: * MVEL (The MVFLEX Expression Language)
03: *
04: * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: */package org.mvel.ast;
19:
20: import static org.mvel.MVEL.eval;
21: import org.mvel.compiler.ExecutableStatement;
22: import org.mvel.integration.VariableResolverFactory;
23: import static org.mvel.util.ParseTools.subCompileExpression;
24:
25: import static java.lang.String.valueOf;
26: import static java.util.regex.Pattern.compile;
27:
28: public class RegExMatch extends ASTNode {
29: private ExecutableStatement stmt;
30: private ExecutableStatement patternStmt;
31: private char[] pattern;
32:
33: public RegExMatch(char[] expr, int fields, char[] pattern) {
34: super (expr, fields);
35: this .pattern = pattern;
36:
37: if ((fields & COMPILE_IMMEDIATE) != 0) {
38: this .stmt = (ExecutableStatement) subCompileExpression(expr);
39: this .patternStmt = (ExecutableStatement) subCompileExpression(pattern);
40: }
41: }
42:
43: public Object getReducedValueAccelerated(Object ctx,
44: Object this Value, VariableResolverFactory factory) {
45: return compile(
46: valueOf(patternStmt.getValue(ctx, this Value, factory)))
47: .matcher(
48: valueOf(stmt.getValue(ctx, this Value, factory)))
49: .matches();
50: }
51:
52: public Object getReducedValue(Object ctx, Object this Value,
53: VariableResolverFactory factory) {
54: return compile(valueOf(eval(pattern, ctx, factory))).matcher(
55: valueOf(eval(name, ctx, factory))).matches();
56: }
57: }
|