View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidadbuild.test;
20  
21  import javax.el.ELContext;
22  import javax.el.ELResolver;
23  import javax.el.FunctionMapper;
24  import javax.el.VariableMapper;
25  
26  import java.util.HashMap;
27  import java.util.Locale;
28  import java.util.Map;
29  
30  import javax.faces.application.Application;
31  
32  public class MockELContext extends ELContext
33  {
34    public MockELContext(Application application)
35    {
36      // =-=AdamWiner:  this is not right;  the Application should
37      // be responsible for vending the ELResolver. However, replacing
38      // the Application is harder... so for now...
39      _resolver = new MockELResolver(application.getVariableResolver(),
40                                     application.getPropertyResolver());
41    }
42  
43    public Object getContext(Class key)
44    {
45      return _contexts.get(key);
46    }
47    
48    public ELResolver getELResolver() 
49    {
50      return _resolver;
51    }
52  
53    public FunctionMapper getFunctionMapper()
54    {
55      return null;
56    }
57  
58    public Locale getLocale()
59    {
60      return _locale;
61    }
62  
63    public VariableMapper getVariableMapper()
64    {
65      throw new UnsupportedOperationException();
66    }
67  
68    public boolean isPropertyResolved()
69    {
70      return _propertyResolved;
71    }
72  
73    public void putContext(Class key, Object contextObject)
74    {
75      _contexts.put(key, contextObject);
76    }
77  
78    public void setLocale(Locale locale) 
79    {
80      _locale = locale;
81    }
82  
83    public void setPropertyResolved(boolean resolved)
84    {
85      _propertyResolved = resolved;
86    }
87  
88    private boolean _propertyResolved;
89    private Locale  _locale;
90    private final Map<Class<?>, Object> _contexts = new HashMap<Class<?>, Object>();
91    private final ELResolver _resolver;
92  }