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.env.minimal;
18  
19  import java.util.Collections;
20  import java.util.Map;
21  
22  import org.apache.commons.scxml2.Context;
23  import org.apache.commons.scxml2.env.SimpleContext;
24  
25  /**
26   * MinimalContext implementation for the SCXML Null Data Model.
27   * <p>
28   * This context disables any access to the parent context (other than through getParent()) and
29   * ignores setting any local data.
30   * </p>
31   * <p>
32   * The MinimalContext requires a none MinimalContext based parent Context for creation.
33   * If the parent context is of type MinimalContext, <em>its</em> parent will be used as the parent of the
34   * new MinimalContext instance
35   * </p>
36   */
37  public class MinimalContext extends SimpleContext {
38  
39      /** Serial version UID. */
40      private static final long serialVersionUID = 1L;
41  
42      private static Context getMinimalContextParent(final Context parent) {
43          if (parent != null) {
44              if (parent instanceof MinimalContext) {
45                  return getMinimalContextParent(parent.getParent());
46              }
47              return parent;
48          }
49          throw new IllegalStateException("A MinimalContext instance requires a non MinimalContext based parent.");
50      }
51  
52      public MinimalContext(final Context parent) {
53          super(getMinimalContextParent(parent));
54      }
55  
56      @Override
57      public void set(final String name, final Object value) {
58      }
59  
60      @Override
61      public Object get(final String name) {
62          return null;
63      }
64  
65      @Override
66      public boolean has(final String name) {
67          return false;
68      }
69  
70      @Override
71      public boolean hasLocal(final String name) {
72          return false;
73      }
74  
75      @Override
76      public void reset() {
77      }
78  
79      @Override
80      public void setLocal(final String name, final Object value) {
81      }
82  
83      @Override
84      protected void setVars(final Map<String, Object> vars) {
85      }
86  
87      @Override
88      public Map<String, Object> getVars() {
89          return Collections.emptyMap();
90      }
91  }