Package org.jibeframework.core.app.condition

Source Code of org.jibeframework.core.app.condition.ConditionEvaluator

/**
* Copyright (C) 2008 Kodeks d.o.o .
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
* or see <http://www.gnu.org/licenses/>
*
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Jibe
* FLOSS exception.  You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.jibeframework.org
*/
package org.jibeframework.core.app.condition;

import org.jibeframework.core.JibeRuntimeException;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

/**
*
*
*
* @author Denis Halupa
*
*/
public class ConditionEvaluator {

  private ExpressionParser parser = new SpelExpressionParser();
  private ConditionEvaluationContext evalContext = new ConditionEvaluationContext();

  public ConditionEvaluator() {

  }

  /**
   *
   */
  public final boolean applies(String condition) {
    if (condition != null) {
      Expression expr = parser.parseExpression(condition);
      Object value = expr.getValue(evalContext);
      if (value instanceof Boolean) {
        return (Boolean) value;
      }
      throw new JibeRuntimeException("Wrong value returned:" + condition);
    }
    return true;

  }

}
TOP

Related Classes of org.jibeframework.core.app.condition.ConditionEvaluator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.