KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jndi > browser > web > action > ViewAction


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.jndi.browser.web.action;
8
9 import java.io.IOException JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Hashtable JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Locale JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import javax.servlet.ServletContext JavaDoc;
17 import javax.servlet.ServletException JavaDoc;
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20
21 import org.apache.log4j.Logger;
22 import org.apache.struts.action.Action;
23 import org.apache.struts.action.ActionError;
24 import org.apache.struts.action.ActionErrors;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.util.MessageResources;
29 import org.ejtools.jndi.browser.web.Constants;
30 import org.ejtools.jndi.browser.web.JNDIContainer;
31 import org.ejtools.jndi.browser.web.form.ViewForm;
32
33
34 /**
35  * Description of the Class
36  *
37  * @author letiemble
38  * @created 12 novembre 2001
39  * @version $Revision: 1.2 $
40  * @todo Javadoc to complete
41  */

42 public class ViewAction extends Action
43 {
44    /** Description of the Field */
45    private static Logger logger = Logger.getLogger(ViewAction.class);
46
47
48    /** Constructor for the ViewAction object */
49    public ViewAction() { }
50
51
52    /**
53     * Description of the Method
54     *
55     * @param mapping Description of Parameter
56     * @param form Description of Parameter
57     * @param request Description of Parameter
58     * @param response Description of Parameter
59     * @return Description of the Returned Value
60     * @exception IOException Description of Exception
61     * @exception ServletException Description of Exception
62     */

63    public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
64       throws IOException JavaDoc, ServletException JavaDoc
65    {
66       String JavaDoc name = null;
67       String JavaDoc type = null;
68
69       // Extract attributes we will need
70
Locale JavaDoc locale = getLocale(request);
71       MessageResources messages = getResources();
72
73       // Validate the request parameters specified by the user
74
ActionErrors errors = new ActionErrors();
75
76       if (form instanceof ViewForm)
77       {
78          name = ((ViewForm) form).getName();
79          type = ((ViewForm) form).getType();
80       }
81       else
82       {
83          errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.index.title"));
84       }
85
86       // Report any errors we have discovered back to the original form
87
if (!errors.empty())
88       {
89          this.saveErrors(request, errors);
90          return (new ActionForward(mapping.getInput()));
91       }
92
93       ServletContext JavaDoc context = this.getServlet().getServletContext();
94
95       if ("ejbmodule".equals(type))
96       {
97          Hashtable JavaDoc moduleTrees = (Hashtable JavaDoc) context.getAttribute(Constants.EJBMODULE_TREES);
98          logger.debug("Viewing JNDI for " + moduleTrees);
99          if (moduleTrees == null)
100          {
101             moduleTrees = new Hashtable JavaDoc();
102          }
103
104          Collection JavaDoc containers = (Collection JavaDoc) moduleTrees.get(name);
105          logger.debug("Viewing JNDI for " + containers);
106          if (containers != null)
107          {
108             context.setAttribute(Constants.EJBMODULE_TREE, containers);
109          }
110       }
111       if ("webapp".equals(type))
112       {
113          Vector JavaDoc applications = (Vector JavaDoc) context.getAttribute(Constants.WEBAPP_TREES);
114          if (applications == null)
115          {
116             applications = new Vector JavaDoc();
117          }
118
119          // Create a search table
120
Hashtable JavaDoc table = new Hashtable JavaDoc();
121          for (Iterator JavaDoc it = applications.iterator(); it.hasNext(); )
122          {
123             JNDIContainer container = (JNDIContainer) it.next();
124             table.put(container.getName(), container);
125          }
126
127          JNDIContainer container = (JNDIContainer) table.get(name);
128          if (container != null)
129          {
130             context.setAttribute(Constants.WEBAPP_TREE, container);
131          }
132       }
133
134       return (mapping.findForward("view"));
135    }
136 }
137
138
Popular Tags