001: /*
002: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package de.odysseus.calyxo.base.test;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import javax.servlet.ServletContext;
022: import javax.servlet.jsp.el.ExpressionEvaluator;
023:
024: import org.apache.commons.el.ExpressionEvaluatorImpl;
025:
026: import de.odysseus.calyxo.base.ModuleContext;
027:
028: /**
029: *
030: * @author Christoph Beck
031: */
032: public class TestModuleContext implements ModuleContext {
033: private ExpressionEvaluator evaluator = new ExpressionEvaluatorImpl();
034: private ServletContext context;
035: private Map attributes;
036: private String name;
037:
038: /**
039: * Creates a new instance.
040: * @param name The module name.
041: */
042: public TestModuleContext(String name) {
043: this (name, new TestServletContext(), new HashMap());
044: }
045:
046: /**
047: * Creates a new instance.
048: * @param name The module name.
049: * @param context The servlet context we're in
050: */
051: public TestModuleContext(String name, ServletContext context) {
052: this (name, context, new HashMap());
053: }
054:
055: /**
056: * Creates a new instance.
057: * @param name The module name.
058: * @param attributes A java.util.Map containing entries whose
059: * keys are strings and whose values are objects.
060: * It represents the mapping from attribute names
061: * to attribute values.
062: */
063: public TestModuleContext(String name, Map attributes) {
064: this (name, new TestServletContext(), attributes);
065: }
066:
067: /**
068: * Creates a new instance.
069: *
070: * @param name The module name.
071: * @param context The servlet context we're in
072: * @param attributes A java.util.Map containing entries whose
073: * keys are strings and whose values are objects.
074: * It represents the mapping from attribute names
075: * to attribute values.
076: */
077: public TestModuleContext(String name, ServletContext context,
078: Map attributes) {
079: super ();
080:
081: this .name = name;
082: this .context = context;
083: this .attributes = attributes;
084: }
085:
086: /* (non-Javadoc)
087: * @see de.odysseus.calyxo.base.ModuleContext#getName()
088: */
089: public String getName() {
090: return name;
091: }
092:
093: /**
094: * @return <code>"/" + name + action</code>
095: * @see de.odysseus.calyxo.base.ModuleContext#getPath(java.lang.String)
096: */
097: public String getPath(String action) {
098: return "/" + name + action;
099: }
100:
101: /* (non-Javadoc)
102: * @see de.odysseus.calyxo.base.ModuleContext#getAttribute(java.lang.String)
103: */
104: public Object getAttribute(String name) {
105: return attributes.get(name);
106: }
107:
108: /* (non-Javadoc)
109: * @see de.odysseus.calyxo.base.ModuleContext#setAttribute(java.lang.String, java.lang.Object)
110: */
111: public void setAttribute(String name, Object value) {
112: attributes.put(name, value);
113: }
114:
115: /* (non-Javadoc)
116: * @see de.odysseus.calyxo.base.ModuleContext#removeAttribute(java.lang.String)
117: */
118: public void removeAttribute(String name) {
119: attributes.remove(name);
120: }
121:
122: /* (non-Javadoc)
123: * @see de.odysseus.calyxo.base.ModuleContext#getServletContext()
124: */
125: public ServletContext getServletContext() {
126: return context;
127: }
128:
129: /**
130: * Answer <code>null</code>.
131: * @see de.odysseus.calyxo.base.ModuleContext#getInitParameter(java.lang.String)
132: */
133: public String getInitParameter(String name) {
134: return null;
135: }
136:
137: public ClassLoader getClassLoader() {
138: return getClass().getClassLoader();
139: }
140:
141: public ExpressionEvaluator getExpressionEvaluator() {
142: return evaluator;
143: }
144: }
|