001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.scxml; 018 019 import org.w3c.dom.Node; 020 021 /** 022 * Interface for a component that may be used by the SCXML engines to 023 * evaluate the expressions within the SCXML document. 024 * 025 */ 026 public interface Evaluator { 027 028 /** 029 * Evaluate an expression. 030 * 031 * @param ctx variable context 032 * @param expr expression 033 * @return a result of the evaluation 034 * @throws SCXMLExpressionException A malformed exception 035 */ 036 Object eval(Context ctx, String expr) 037 throws SCXMLExpressionException; 038 039 /** 040 * Evaluate a condition. 041 * Manifests as "cond" attributes of <transition>, 042 * <if> and <elseif> elements. 043 * 044 * @param ctx variable context 045 * @param expr expression 046 * @return true/false 047 * @throws SCXMLExpressionException A malformed exception 048 */ 049 Boolean evalCond(Context ctx, String expr) 050 throws SCXMLExpressionException; 051 052 /** 053 * Evaluate a location that returns a Node within an XML data tree. 054 * Manifests as "location" attributes of <assign> element. 055 * 056 * @param ctx variable context 057 * @param expr expression 058 * @return The location node. 059 * @throws SCXMLExpressionException A malformed exception 060 */ 061 Node evalLocation(Context ctx, String expr) 062 throws SCXMLExpressionException; 063 064 /** 065 * Create a new child context. 066 * 067 * @param parent parent context 068 * @return new child context 069 */ 070 Context newContext(Context parent); 071 072 } 073