    1   /*
    2    * Copyright 2005 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  package org.apache.commons.scxml.env.jsp;
    17
    18  import java.util.Enumeration;
    19  import java.util.HashMap;
    20  import java.util.Map;
    21
    22  import javax.servlet.jsp.JspContext;
    23  import javax.servlet.jsp.JspWriter;
    24  import javax.servlet.jsp.el.ExpressionEvaluator;
    25  import javax.servlet.jsp.el.VariableResolver;
    26
    27  /***
    28   * A placeholder for a JspContext, to run tests against.
    29   */
    30  public class MockJspContext extends JspContext
    31          implements VariableResolver {
    32      private Map vars;
    33      public MockJspContext() {
    34          super();
    35          vars = new HashMap();
    36      }
    37      public void setAttribute(String name, Object value) {
    38          vars.put(name, value);
    39      }
    40      public void setAttribute(String name, Object value, int scope) {
    41          setAttribute(name, value);
    42      }
    43      public Object getAttribute(String name) {
    44          return vars.get(name);
    45      }
    46      public Object getAttribute(String name, int scope) {
    47          return getAttribute(name);
    48      }
    49      public void removeAttribute(String name) {
    50          vars.remove(name);
    51      }
    52      public void removeAttribute(String name, int scope) {
    53          removeAttribute(name);
    54      }
    55      public Object findAttribute(String name) {
    56          return getAttribute(name);
    57      }
    58      public VariableResolver getVariableResolver() {
    59          return this;
    60      }
    61      public Object resolveVariable(String name) {
    62          return getAttribute(name);
    63      }
    64      public ExpressionEvaluator getExpressionEvaluator() {
    65          return null;
    66      }
    67      public int getAttributesScope(String name) {
    68          return 1;
    69      }
    70      public Enumeration getAttributeNamesInScope(int scope) {
    71          return null;
    72      }
    73      public JspWriter getOut() {
    74          return null;
    75      }
    76  }
    77