    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.scxml.env.jsp;
    18
    19  import java.util.Enumeration;
    20  import java.util.HashMap;
    21  import java.util.Map;
    22
    23  import javax.servlet.jsp.JspContext;
    24  import javax.servlet.jsp.JspWriter;
    25  import javax.servlet.jsp.el.ExpressionEvaluator;
    26  import javax.servlet.jsp.el.VariableResolver;
    27
    28  /***
    29   * A placeholder for a JspContext, to run tests against.
    30   */
    31  public class MockJspContext extends JspContext
    32          implements VariableResolver {
    33      private Map vars;
    34      public MockJspContext() {
    35          super();
    36          vars = new HashMap();
    37      }
    38      public void setAttribute(String name, Object value) {
    39          vars.put(name, value);
    40      }
    41      public void setAttribute(String name, Object value, int scope) {
    42          setAttribute(name, value);
    43      }
    44      public Object getAttribute(String name) {
    45          return vars.get(name);
    46      }
    47      public Object getAttribute(String name, int scope) {
    48          return getAttribute(name);
    49      }
    50      public void removeAttribute(String name) {
    51          vars.remove(name);
    52      }
    53      public void removeAttribute(String name, int scope) {
    54          removeAttribute(name);
    55      }
    56      public Object findAttribute(String name) {
    57          return getAttribute(name);
    58      }
    59      public VariableResolver getVariableResolver() {
    60          return this;
    61      }
    62      public Object resolveVariable(String name) {
    63          return getAttribute(name);
    64      }
    65      public ExpressionEvaluator getExpressionEvaluator() {
    66          return null;
    67      }
    68      public int getAttributesScope(String name) {
    69          return 1;
    70      }
    71      public Enumeration getAttributeNamesInScope(int scope) {
    72          return null;
    73      }
    74      public JspWriter getOut() {
    75          return null;
    76      }
    77  }
    78