KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > junit > invocation > ViewInterceptor


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under LGPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portal.junit.invocation;
12
13 import org.jboss.portal.server.invocation.Interceptor;
14 import org.jboss.portal.server.invocation.Invocation;
15 import org.jboss.portal.server.invocation.AttachmentKey;
16 import org.jboss.portal.server.PortalRequest;
17 import org.jboss.portal.server.PortalServer;
18 import org.jboss.portal.server.Portal;
19 import org.jboss.portal.server.Window;
20 import org.jboss.portal.junit.TestAttachmentKey;
21 import org.apache.log4j.Logger;
22
23 import java.util.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25
26 /**
27  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
28  * @version $Revision: 1.3 $
29  */

30 public class ViewInterceptor implements Interceptor
31 {
32    private static Logger log = Logger.getLogger(ViewInterceptor.class);
33
34    private List JavaDoc windows = new ArrayList JavaDoc();
35
36    public Object JavaDoc invoke(Invocation invocation)
37    {
38       try
39       {
40          // The target portal
41
PortalRequest req = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST);
42          PortalServer container = req.getServer();
43          Portal portal = container.getDefaultPortal();
44
45          // Compute the list of windows for this test
46
String JavaDoc[] values = (String JavaDoc[])invocation.getAttachment(TestAttachmentKey.TEST_WINDOWS);
47          if (values != null)
48          {
49             // Clear the previous list
50
windows.clear();
51
52             // If there is a list of window name, that means we begin a test
53
StringBuffer JavaDoc tmp = new StringBuffer JavaDoc("Window request list [");
54             for (int i = 0; i < values.length; i++)
55             {
56                tmp.append(i == 0 ? "" : ",").append(values[i]);
57             }
58             tmp.append("]");
59             log.info(tmp);
60
61             for (int i = 0; i < values.length; i++)
62             {
63                String JavaDoc windowName = values[i];
64                Window window = portal.getWindow(windowName);
65                if (window != null)
66                {
67                   windows.add(window);
68                }
69                else
70                {
71                   log.error("Cannot find window " + windowName);
72                }
73             }
74          }
75
76          // Add all the found windows and follow the invocation path
77
invocation.setAttachment(AttachmentKey.VIEW, new ArrayList JavaDoc(windows));
78          invocation.setAttachment(AttachmentKey.PORTAL, portal);
79          return invocation.invokeNext();
80       }
81       finally
82       {
83          invocation.removeAttachment(AttachmentKey.VIEW);
84       }
85    }
86 }
87
Popular Tags