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 */
017package org.apache.commons.scxml2;
018
019import java.util.Map;
020
021/**
022 * A Context or "scope" for storing variables; usually tied to
023 * a SCXML root or State object.
024 */
025public interface Context {
026
027    /**
028     * Current namespaces are saved under this key in the context.
029     */
030    String NAMESPACES_KEY = "_ALL_NAMESPACES";
031
032    /**
033     * Assigns a new value to an existing variable or creates a new one.
034     * The method searches the chain of parent Contexts for variable
035     * existence.
036     *
037     * @param name The variable name
038     * @param value The variable value
039     */
040    void set(String name, Object value);
041
042    /**
043     * Assigns a new value to an existing variable or creates a new one.
044     * The method allows to shaddow a variable of the same name up the
045     * Context chain.
046     *
047     * @param name The variable name
048     * @param value The variable value
049     */
050    void setLocal(String name, Object value);
051
052    /**
053     * Get the value of this variable; delegating to parent.
054     *
055     * @param name The name of the variable
056     * @return The value (or null)
057     */
058    Object get(String name);
059
060    /**
061     * Check if this variable exists, delegating to parent.
062     *
063     * @param name The name of the variable
064     * @return Whether a variable with the name exists in this Context
065     */
066    boolean has(String name);
067
068    /**
069     * Check if this variable exists, only checking this Context
070     *
071     * @param name The name of the variable
072     * @return Whether a variable with the name exists in this Context
073     */
074    boolean hasLocal(String name);
075
076    /**
077     * Get the Map of all variables in this Context.
078     *
079     * @return Local variable entries Map
080     * To get variables in parent Context, call getParent().getVars().
081     * @see #getParent()
082     */
083    Map<String, Object> getVars();
084
085    /**
086     * Clear this Context.
087     */
088    void reset();
089
090    /**
091     * Get the parent Context, may be null.
092     *
093     * @return The parent Context in a chained Context environment
094     */
095    Context getParent();
096
097    /**
098     * Get the SCXMLSystemContext for this Context, should not be null unless this is the root Context
099     *
100     * @return The SCXMLSystemContext in a chained Context environment
101     */
102    SCXMLSystemContext getSystemContext();
103
104}