View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.scxml2;
18  
19  import java.util.Map;
20  
21  /**
22   * A Context or "scope" for storing variables; usually tied to
23   * a SCXML root or State object.
24   */
25  public interface Context {
26  
27      /**
28       * Current namespaces are saved under this key in the context.
29       */
30      String NAMESPACES_KEY = "_ALL_NAMESPACES";
31  
32      /**
33       * Assigns a new value to an existing variable or creates a new one.
34       * The method searches the chain of parent Contexts for variable
35       * existence.
36       *
37       * @param name The variable name
38       * @param value The variable value
39       */
40      void set(String name, Object value);
41  
42      /**
43       * Assigns a new value to an existing variable or creates a new one.
44       * The method allows to shaddow a variable of the same name up the
45       * Context chain.
46       *
47       * @param name The variable name
48       * @param value The variable value
49       */
50      void setLocal(String name, Object value);
51  
52      /**
53       * Get the value of this variable; delegating to parent.
54       *
55       * @param name The name of the variable
56       * @return The value (or null)
57       */
58      Object get(String name);
59  
60      /**
61       * Check if this variable exists, delegating to parent.
62       *
63       * @param name The name of the variable
64       * @return Whether a variable with the name exists in this Context
65       */
66      boolean has(String name);
67  
68      /**
69       * Check if this variable exists, only checking this Context
70       *
71       * @param name The name of the variable
72       * @return Whether a variable with the name exists in this Context
73       */
74      boolean hasLocal(String name);
75  
76      /**
77       * Get the Map of all variables in this Context.
78       *
79       * @return Local variable entries Map
80       * To get variables in parent Context, call getParent().getVars().
81       * @see #getParent()
82       */
83      Map<String, Object> getVars();
84  
85      /**
86       * Clear this Context.
87       */
88      void reset();
89  
90      /**
91       * Get the parent Context, may be null.
92       *
93       * @return The parent Context in a chained Context environment
94       */
95      Context getParent();
96  
97      /**
98       * Get the SCXMLSystemContext for this Context, should not be null unless this is the root Context
99       *
100      * @return The SCXMLSystemContext in a chained Context environment
101      */
102     SCXMLSystemContext getSystemContext();
103 
104 }