KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > DumpRegistryAction


1 /*
2  * Copyright 2001,2004 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
17
18 package org.apache.webapp.admin;
19
20
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import javax.servlet.http.HttpSession JavaDoc;
28 import org.apache.commons.modeler.ManagedBean;
29 import org.apache.commons.modeler.Registry;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionErrors;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36
37 /**
38  * Simple debugging action that dumps a list of the managed beans that are
39  * visible in our Registry.
40  *
41  * @author Craig R. McClanahan
42  * @version $Revision: 1.3 $ $Date: 2004/10/18 06:37:53 $
43  */

44
45 public final class DumpRegistryAction extends Action {
46
47
48     // --------------------------------------------------------- Public Methods
49

50
51     /**
52      * Process the specified HTTP request, and create the corresponding HTTP
53      * response (or forward to another web component that will create it).
54      * Return an <code>ActionForward</code> instance describing where and how
55      * control should be forwarded, or <code>null</code> if the response has
56      * already been completed.
57      *
58      * @param mapping The ActionMapping used to select this instance
59      * @param actionForm The optional ActionForm bean for this request (if any)
60      * @param request The HTTP request we are processing
61      * @param response The HTTP response we are creating
62      *
63      * @exception IOException if an input/output error occurs
64      * @exception ServletException if a servlet exception occurs
65      */

66     public ActionForward execute(ActionMapping mapping,
67                                  ActionForm form,
68                                  HttpServletRequest JavaDoc request,
69                                  HttpServletResponse JavaDoc response)
70         throws IOException JavaDoc, ServletException JavaDoc {
71
72         // Create a request attribute with our collection of beans
73
Registry registry = ((ApplicationServlet) getServlet()).getRegistry();
74         String JavaDoc names[] = registry.findManagedBeans();
75         Arrays.sort(names);
76         ManagedBean beans[] = new ManagedBean[names.length];
77         for (int i = 0; i < names.length; i++)
78             beans[i] = registry.findManagedBean(names[i]);
79         request.setAttribute("beans", beans);
80
81         // Forward to the corresponding display page
82
return (mapping.findForward("Dump Registry Results"));
83
84     }
85
86
87 }
88
Popular Tags