1 7 package org.ejtools.jndi.browser.web.action; 8 9 import java.io.IOException ; 10 import java.util.Collection ; 11 import java.util.Hashtable ; 12 import java.util.Iterator ; 13 import java.util.Locale ; 14 import java.util.Vector ; 15 16 import javax.servlet.ServletContext ; 17 import javax.servlet.ServletException ; 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 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 42 public class ViewAction extends Action 43 { 44 45 private static Logger logger = Logger.getLogger(ViewAction.class); 46 47 48 49 public ViewAction() { } 50 51 52 63 public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 64 throws IOException , ServletException 65 { 66 String name = null; 67 String type = null; 68 69 Locale locale = getLocale(request); 71 MessageResources messages = getResources(); 72 73 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 if (!errors.empty()) 88 { 89 this.saveErrors(request, errors); 90 return (new ActionForward(mapping.getInput())); 91 } 92 93 ServletContext context = this.getServlet().getServletContext(); 94 95 if ("ejbmodule".equals(type)) 96 { 97 Hashtable moduleTrees = (Hashtable ) context.getAttribute(Constants.EJBMODULE_TREES); 98 logger.debug("Viewing JNDI for " + moduleTrees); 99 if (moduleTrees == null) 100 { 101 moduleTrees = new Hashtable (); 102 } 103 104 Collection containers = (Collection ) 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 applications = (Vector ) context.getAttribute(Constants.WEBAPP_TREES); 114 if (applications == null) 115 { 116 applications = new Vector (); 117 } 118 119 Hashtable table = new Hashtable (); 121 for (Iterator 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 |