001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krms.framework.engine.expression;
017
018 import java.util.Collections;
019 import java.util.List;
020
021 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
022 import org.kuali.rice.krms.framework.engine.Proposition;
023 import org.kuali.rice.krms.framework.engine.PropositionResult;
024
025 /**
026 * An implementation of {@link Proposition} which uses a given {@link Expression}<Boolean>
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 *
029 */
030 public class ExpressionBasedProposition implements Proposition {
031
032 private final Expression<Boolean> expression;
033
034 /**
035 * Create an ExpressionBasedProposition with the given value
036 * @param expression {@link Expression} to set the expression to
037 */
038 public ExpressionBasedProposition(Expression<Boolean> expression) {
039 this.expression = expression;
040 }
041
042 @Override
043 public PropositionResult evaluate(ExecutionEnvironment environment) {
044 return new PropositionResult(expression.invoke(environment).booleanValue());
045 }
046
047
048 @Override
049 public List<Proposition> getChildren() {
050 return Collections.emptyList();
051 }
052
053 @Override
054 public boolean isCompound() {
055 return false;
056 }
057 }