001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.oozie.coord.input.logic; 020 021import org.apache.commons.jexl2.Interpreter; 022import org.apache.commons.jexl2.JexlContext; 023import org.apache.commons.jexl2.JexlEngine; 024import org.apache.commons.jexl2.parser.ASTAndNode; 025import org.apache.commons.jexl2.parser.ASTOrNode; 026import org.apache.commons.jexl2.parser.JexlNode; 027import org.apache.oozie.coord.input.logic.CoordInputLogicEvaluatorResult.STATUS; 028 029/** 030 * Oozie implementation of jexl Interpreter 031 */ 032public class OozieJexlInterpreter extends Interpreter { 033 034 protected OozieJexlInterpreter(Interpreter base) { 035 super(base); 036 } 037 038 public Object interpret(JexlNode node) { 039 return node.jjtAccept(this, ""); 040 } 041 042 public OozieJexlInterpreter(JexlEngine jexlEngine, JexlContext jexlContext, boolean strictFlag, boolean silentFlag) { 043 super(jexlEngine, jexlContext, strictFlag, silentFlag); 044 } 045 046 public Object visit(ASTOrNode node, Object data) { 047 CoordInputLogicEvaluatorResult left = (CoordInputLogicEvaluatorResult) node.jjtGetChild(0) 048 .jjtAccept(this, data); 049 050 if (left.isTrue()) { 051 return left; 052 } 053 054 return node.jjtGetChild(1).jjtAccept(this, data); 055 } 056 057 /** {@inheritDoc} */ 058 public Object visit(ASTAndNode node, Object data) { 059 CoordInputLogicEvaluatorResult left = (CoordInputLogicEvaluatorResult) node.jjtGetChild(0) 060 .jjtAccept(this, data); 061 062 if(left.isWaiting() || !left.isTrue()){ 063 return left; 064 } 065 066 CoordInputLogicEvaluatorResult right = (CoordInputLogicEvaluatorResult) node.jjtGetChild(1).jjtAccept(this, 067 data); 068 if(right.isWaiting()){ 069 return right; 070 } 071 if(left.isPhaseTwoEvaluation() || right.isPhaseTwoEvaluation()){ 072 return new CoordInputLogicEvaluatorResult(STATUS.PHASE_TWO_EVALUATION); 073 } 074 075 if (right.isTrue()) { 076 right.appendDataSets(left.getDataSets()); 077 } 078 return right; 079 } 080 081}