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 java.util.Map;
020
021 /**
022 * A Context or "scope" for storing variables; usually tied to
023 * a SCXML root or State object.
024 */
025 public interface Context {
026 /**
027 * Assigns a new value to an existing variable or creates a new one.
028 * The method searches the chain of parent Contexts for variable
029 * existence.
030 *
031 * @param name The variable name
032 * @param value The variable value
033 */
034 void set(String name, Object value);
035
036 /**
037 * Assigns a new value to an existing variable or creates a new one.
038 * The method allows to shaddow a variable of the same name up the
039 * Context chain.
040 *
041 * @param name The variable name
042 * @param value The variable value
043 */
044 void setLocal(String name, Object value);
045
046 /**
047 * Get the value of this variable; delegating to parent.
048 *
049 * @param name The name of the variable
050 * @return The value (or null)
051 */
052 Object get(String name);
053
054 /**
055 * Check if this variable exists, delegating to parent.
056 *
057 * @param name The name of the variable
058 * @return Whether a variable with the name exists in this Context
059 */
060 boolean has(String name);
061
062 /**
063 * Get the Map of all variables in this Context.
064 *
065 * @return Local variable entries Map
066 * To get variables in parent Context, call getParent().getVars().
067 * @see #getParent()
068 */
069 Map getVars();
070
071 /**
072 * Clear this Context.
073 */
074 void reset();
075
076 /**
077 * Get the parent Context, may be null.
078 *
079 * @return The parent Context in a chained Context environment
080 */
081 Context getParent();
082
083 }