View Javadoc

1   package org.astrogrid.portal.myspace.acting.framework;
2   
3   import java.io.IOException;
4   import java.util.Stack;
5   
6   import org.apache.avalon.framework.parameters.Parameters;
7   import org.apache.cocoon.environment.Request;
8   import org.apache.cocoon.environment.Session;
9   import org.astrogrid.portal.utils.acting.ActionUtils;
10  
11  /***
12   * Create a new environment context based on a given protocol.
13   * 
14   * @author peter.shillan
15   */
16  public class ContextWrapperFactory {
17    private static Stack MOCK_STACK = new Stack();
18    
19    /***
20     * Create a new environment context based on a given protocol.
21     * 
22     * @param protocol context wrapper protocol
23     * @param utils action utilities
24     * @param params sitemap parameters
25     * @param request <b>Cocoon</b> request
26     * @param session <b>Cocoon</b> session
27     * @return environment context
28     * @throws IOException
29     */
30    public static ContextWrapper getContextWrapper(
31        String protocol,
32        ActionUtils utils,
33        Parameters params,
34        Request request,
35        Session session) throws IOException {
36      if(MOCK_STACK.size() == 0) {
37        return new ContextWrapperImpl(utils, params, request, session);
38      }
39      
40      return (ContextWrapper) MOCK_STACK.pop(); 
41    }
42    
43    /***
44     * Facilitates unit testing.
45     * <b>DO NOT USE</b> outside of a test case.
46     */
47    public static void addMock(ContextWrapper mockContext) {
48      MOCK_STACK.add(mockContext);
49    }
50  
51    /***
52     * No instances allowed.
53     */
54    private ContextWrapperFactory() {
55    }
56  }