[Ejtools-cvs] applications/jndi.browser/src/main/org/ejtools/jndi/browser/web/action RefreshAction.j
Brought to you by:
letiemble
From: <let...@us...> - 2003-12-14 08:40:47
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/web/action In directory sc8-pr-cvs1:/tmp/cvs-serv20500/jndi.browser/src/main/org/ejtools/jndi/browser/web/action Modified Files: RefreshAction.java Log Message: Add more javadocs. Adjust workspace persistence. Index: RefreshAction.java =================================================================== RCS file: /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/web/action/RefreshAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RefreshAction.java 27 Nov 2003 01:30:30 -0000 1.5 --- RefreshAction.java 13 Dec 2003 22:29:07 -0000 1.6 *************** *** 1,268 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.web.action; ! ! import java.io.IOException; ! import java.util.ArrayList; ! import java.util.Collection; ! import java.util.Hashtable; ! import java.util.Iterator; ! import java.util.Locale; ! import java.util.Vector; ! ! import javax.management.MBeanServer; ! import javax.management.MBeanServerFactory; ! import javax.management.ObjectName; ! import javax.servlet.ServletContext; ! import javax.servlet.ServletException; ! import javax.servlet.http.HttpServletRequest; ! import javax.servlet.http.HttpServletResponse; ! ! import org.apache.log4j.Logger; ! import org.apache.struts.action.Action; ! import org.apache.struts.action.ActionErrors; ! import org.apache.struts.action.ActionForm; ! import org.apache.struts.action.ActionForward; ! import org.apache.struts.action.ActionMapping; ! import org.apache.struts.util.MessageResources; ! import org.apache.struts.util.ResponseUtils; ! import org.ejtools.jndi.browser.web.Constants; ! import org.ejtools.jndi.browser.web.JNDIContainer; ! import org.jboss.ejb.Container; ! import org.jboss.ejb.EjbModule; ! import org.jboss.web.WebApplication; ! ! ! /** ! * Description of the Class ! * ! * @author letiemble ! * @created 12 novembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class RefreshAction extends Action ! { ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(RefreshAction.class); ! ! ! /** Constructor for the ViewAction object */ ! public RefreshAction() { } ! ! ! /** ! * Description of the Method ! * ! * @param mapping Description of Parameter ! * @param form Description of Parameter ! * @param request Description of Parameter ! * @param response Description of Parameter ! * @return Description of the Returned Value ! * @exception IOException Description of Exception ! * @exception ServletException Description of Exception ! */ ! public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) ! throws IOException, ServletException ! { ! // Extract attributes we will need ! Locale locale = getLocale(request); ! MessageResources messages = getResources(); ! ! // Validate the request parameters specified by the user ! ActionErrors errors = new ActionErrors(); ! ! logger.debug("Connecting to JNDI..."); ! ! // Report any errors we have discovered back to the original form ! if (!errors.empty()) ! { ! saveErrors(request, errors); ! return (new ActionForward(mapping.getInput())); ! } ! ! ServletContext context = this.getServlet().getServletContext(); ! ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); ! ! // ======================================== ! // Refresh the global jndi tree ! // ======================================== ! JNDIContainer globalTree = (JNDIContainer) context.getAttribute(Constants.GLOBAL_TREE); ! logger.debug("globalTree=" + globalTree); ! if (globalTree == null) ! { ! globalTree = new JNDIContainer(); ! globalTree.setClassLoader(currentClassLoader); ! globalTree.setContext(""); ! context.setAttribute(Constants.GLOBAL_TREE, globalTree); ! } ! logger.debug("refresh globalTree"); ! globalTree.refresh(); ! ! // ======================================== ! // Refresh the global jndi tree ! // ======================================== ! JNDIContainer localTree = (JNDIContainer) context.getAttribute(Constants.LOCAL_TREE); ! logger.debug("localTree=" + localTree); ! if (localTree == null) ! { ! localTree = new JNDIContainer(); ! localTree.setClassLoader(currentClassLoader); ! localTree.setContext("java:/"); ! context.setAttribute(Constants.LOCAL_TREE, localTree); ! } ! logger.debug("refresh localTree"); ! localTree.refresh(); ! ! // **************************************** ! // JBoss specific code ! // **************************************** ! ArrayList list = MBeanServerFactory.findMBeanServer(null); ! if ((list != null) && (list.size() > 0)) ! { ! Iterator iterator = null; ! MBeanServer server = (MBeanServer) list.get(0); ! logger.debug("server=" + server); ! ! try ! { ! // ======================================== ! // Refresh the ejb modules ! // ======================================== ! Vector moduleNames = new Vector(); ! Hashtable moduleTrees = (Hashtable) context.getAttribute(Constants.EJBMODULE_TREES); ! if (moduleTrees == null) ! { ! moduleTrees = new Hashtable(); ! } ! Hashtable newModuleTrees = new Hashtable(); ! ! // @todo Get from an env-entry ! iterator = server.queryNames(EjbModule.EJB_MODULE_QUERY_NAME, null).iterator(); ! while (iterator.hasNext()) ! { ! try ! { ! ObjectName module = (ObjectName) iterator.next(); ! logger.debug("module=" + module); ! String moduleName = (String) module.getKeyProperty("module"); ! String moduleUid = (String) module.getKeyProperty("uid"); ! if ((moduleUid != null) && (!"".equals(moduleUid))) ! { ! moduleName = moduleName + " (" + moduleUid + ")"; ! } ! moduleNames.add(ResponseUtils.filter(moduleName)); ! logger.debug("moduleName=" + moduleName); ! ! // Get the containes from the module ! Vector containers = (Vector) moduleTrees.get(moduleName); ! if (containers == null) ! { ! containers = new Vector(); ! } ! Vector newContainers = new Vector(); ! ! // Create a search table ! Hashtable ejbTable = new Hashtable(); ! for (Iterator it = containers.iterator(); it.hasNext(); ) ! { ! JNDIContainer container = (JNDIContainer) it.next(); ! ejbTable.put(container.getName(), container); ! } ! ! Collection moduleContainers = (Collection) server.getAttribute(module, "Containers"); ! for (Iterator iter = moduleContainers.iterator(); iter.hasNext(); ) ! { ! Container ejbContainer = (Container) iter.next(); ! String ejbName = ejbContainer.getBeanMetaData().getEjbName(); ! JNDIContainer container = (JNDIContainer) ejbTable.get(ejbName); ! logger.debug("container=" + container); ! if (container == null) ! { ! container = new JNDIContainer(); ! container.setName(ejbName); ! container.setClassLoader(ejbContainer.getClassLoader()); ! container.setContext("java:/comp"); ! } ! logger.debug("refresh container"); ! newContainers.add(container); ! container.refresh(); ! } ! newModuleTrees.put(ResponseUtils.filter(moduleName), newContainers); ! containers.clear(); ! } ! catch (Exception e) ! { ! logger.error("Error while refreshing getting module", e); ! } ! } ! context.setAttribute(Constants.EJBMODULE_NAMES, moduleNames); ! context.setAttribute(Constants.EJBMODULE_TREES, newModuleTrees); ! context.setAttribute(Constants.EJBMODULE_TREE, newModuleTrees.get(moduleNames.get(0))); ! moduleTrees.clear(); ! } ! catch (Exception e) ! { ! logger.error("Error while refreshing EJB modules", e); ! } ! ! try ! { ! // ======================================== ! // Refresh the webapps ! // ======================================== ! Vector applications = (Vector) context.getAttribute(Constants.WEBAPP_TREES); ! if (applications == null) ! { ! applications = new Vector(); ! } ! Vector newApplications = new Vector(); ! ! // Create a search table ! Hashtable appTable = new Hashtable(); ! for (Iterator it = applications.iterator(); it.hasNext(); ) ! { ! JNDIContainer container = (JNDIContainer) it.next(); ! appTable.put(container.getName(), container); ! } ! ! // @todo Get from an env-entry ! ObjectName webService = new ObjectName(Constants.WEBSERVER_OBJECTNAME); ! iterator = (Iterator) server.getAttribute(webService, "DeployedApplications"); ! while (iterator.hasNext()) ! { ! WebApplication application = (WebApplication) iterator.next(); ! String applicationName = application.getName(); ! logger.debug("applicationName=" + applicationName); ! ! JNDIContainer container = (JNDIContainer) appTable.get(applicationName); ! logger.debug("container=" + container); ! if (container == null) ! { ! container = new JNDIContainer(); ! container.setName(application.getName()); ! container.setClassLoader(application.getClassLoader()); ! container.setContext("java:/comp"); ! } ! logger.debug("refresh container"); ! newApplications.add(container); ! container.refresh(); ! } ! context.setAttribute(Constants.WEBAPP_TREES, newApplications); ! context.setAttribute(Constants.WEBAPP_TREE, newApplications.get(0)); ! applications.clear(); ! } ! catch (Exception e) ! { ! logger.error("Error while refreshing Web modules", e); ! } ! } ! ! return (mapping.findForward("view")); ! } ! } ! --- 1,268 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jndi.browser.web.action; ! ! import java.io.IOException; ! import java.util.ArrayList; ! import java.util.Collection; ! import java.util.Hashtable; ! import java.util.Iterator; ! import java.util.Locale; ! import java.util.Vector; ! ! import javax.management.MBeanServer; ! import javax.management.MBeanServerFactory; ! import javax.management.ObjectName; ! import javax.servlet.ServletContext; ! import javax.servlet.ServletException; ! import javax.servlet.http.HttpServletRequest; ! import javax.servlet.http.HttpServletResponse; ! ! import org.apache.log4j.Logger; ! import org.apache.struts.action.Action; ! import org.apache.struts.action.ActionErrors; ! import org.apache.struts.action.ActionForm; ! import org.apache.struts.action.ActionForward; ! import org.apache.struts.action.ActionMapping; ! import org.apache.struts.util.MessageResources; ! import org.apache.struts.util.ResponseUtils; ! import org.ejtools.jndi.browser.web.Constants; ! import org.ejtools.jndi.browser.web.JNDIContainer; ! import org.jboss.ejb.Container; ! import org.jboss.ejb.EjbModule; ! import org.jboss.web.WebApplication; ! ! ! /** ! * Description of the Class ! * ! * @author letiemble ! * @created 12 novembre 2001 ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class RefreshAction extends Action ! { ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(RefreshAction.class); ! ! ! /** Constructor for the ViewAction object */ ! public RefreshAction() { } ! ! ! /** ! * Description of the Method ! * ! * @param mapping Description of Parameter ! * @param form Description of Parameter ! * @param request Description of Parameter ! * @param response Description of Parameter ! * @return Description of the Returned Value ! * @exception IOException Description of Exception ! * @exception ServletException Description of Exception ! */ ! public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) ! throws IOException, ServletException ! { ! // Extract attributes we will need ! Locale locale = getLocale(request); ! MessageResources messages = getResources(); ! ! // Validate the request parameters specified by the user ! ActionErrors errors = new ActionErrors(); ! ! logger.debug("Connecting to JNDI..."); ! ! // Report any errors we have discovered back to the original form ! if (!errors.empty()) ! { ! saveErrors(request, errors); ! return (new ActionForward(mapping.getInput())); ! } ! ! ServletContext context = this.getServlet().getServletContext(); ! ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); ! ! // ======================================== ! // Refresh the global jndi tree ! // ======================================== ! JNDIContainer globalTree = (JNDIContainer) context.getAttribute(Constants.GLOBAL_TREE); ! logger.debug("globalTree=" + globalTree); ! if (globalTree == null) ! { ! globalTree = new JNDIContainer(); ! globalTree.setClassLoader(currentClassLoader); ! globalTree.setContext(""); ! context.setAttribute(Constants.GLOBAL_TREE, globalTree); ! } ! logger.debug("refresh globalTree"); ! globalTree.refresh(); ! ! // ======================================== ! // Refresh the global jndi tree ! // ======================================== ! JNDIContainer localTree = (JNDIContainer) context.getAttribute(Constants.LOCAL_TREE); ! logger.debug("localTree=" + localTree); ! if (localTree == null) ! { ! localTree = new JNDIContainer(); ! localTree.setClassLoader(currentClassLoader); ! localTree.setContext("java:/"); ! context.setAttribute(Constants.LOCAL_TREE, localTree); ! } ! logger.debug("refresh localTree"); ! localTree.refresh(); ! ! // **************************************** ! // JBoss specific code ! // **************************************** ! ArrayList list = MBeanServerFactory.findMBeanServer(null); ! if ((list != null) && (list.size() > 0)) ! { ! Iterator iterator = null; ! MBeanServer server = (MBeanServer) list.get(0); ! logger.debug("server=" + server); ! ! try ! { ! // ======================================== ! // Refresh the ejb modules ! // ======================================== ! Vector moduleNames = new Vector(); ! Hashtable moduleTrees = (Hashtable) context.getAttribute(Constants.EJBMODULE_TREES); ! if (moduleTrees == null) ! { ! moduleTrees = new Hashtable(); ! } ! Hashtable newModuleTrees = new Hashtable(); ! ! // @todo Get from an env-entry ! iterator = server.queryNames(EjbModule.EJB_MODULE_QUERY_NAME, null).iterator(); ! while (iterator.hasNext()) ! { ! try ! { ! ObjectName module = (ObjectName) iterator.next(); ! logger.debug("module=" + module); ! String moduleName = (String) module.getKeyProperty("module"); ! String moduleUid = (String) module.getKeyProperty("uid"); ! if ((moduleUid != null) && (!"".equals(moduleUid))) ! { ! moduleName = moduleName + " (" + moduleUid + ")"; ! } ! moduleNames.add(ResponseUtils.filter(moduleName)); ! logger.debug("moduleName=" + moduleName); ! ! // Get the containes from the module ! Vector containers = (Vector) moduleTrees.get(moduleName); ! if (containers == null) ! { ! containers = new Vector(); ! } ! Vector newContainers = new Vector(); ! ! // Create a search table ! Hashtable ejbTable = new Hashtable(); ! for (Iterator it = containers.iterator(); it.hasNext(); ) ! { ! JNDIContainer container = (JNDIContainer) it.next(); ! ejbTable.put(container.getName(), container); ! } ! ! Collection moduleContainers = (Collection) server.getAttribute(module, "Containers"); ! for (Iterator iter = moduleContainers.iterator(); iter.hasNext(); ) ! { ! Container ejbContainer = (Container) iter.next(); ! String ejbName = ejbContainer.getBeanMetaData().getEjbName(); ! JNDIContainer container = (JNDIContainer) ejbTable.get(ejbName); ! logger.debug("container=" + container); ! if (container == null) ! { ! container = new JNDIContainer(); ! container.setName(ejbName); ! container.setClassLoader(ejbContainer.getClassLoader()); ! container.setContext("java:/comp"); ! } ! logger.debug("refresh container"); ! newContainers.add(container); ! container.refresh(); ! } ! newModuleTrees.put(ResponseUtils.filter(moduleName), newContainers); ! containers.clear(); ! } ! catch (Exception e) ! { ! logger.error("Error while refreshing getting module", e); ! } ! } ! context.setAttribute(Constants.EJBMODULE_NAMES, moduleNames); ! context.setAttribute(Constants.EJBMODULE_TREES, newModuleTrees); ! context.setAttribute(Constants.EJBMODULE_TREE, newModuleTrees.get(moduleNames.get(0))); ! moduleTrees.clear(); ! } ! catch (Exception e) ! { ! logger.error("Error while refreshing EJB modules", e); ! } ! ! try ! { ! // ======================================== ! // Refresh the webapps ! // ======================================== ! Vector applications = (Vector) context.getAttribute(Constants.WEBAPP_TREES); ! if (applications == null) ! { ! applications = new Vector(); ! } ! Vector newApplications = new Vector(); ! ! // Create a search table ! Hashtable appTable = new Hashtable(); ! for (Iterator it = applications.iterator(); it.hasNext(); ) ! { ! JNDIContainer container = (JNDIContainer) it.next(); ! appTable.put(container.getName(), container); ! } ! ! // @todo Get from an env-entry ! ObjectName webService = new ObjectName(Constants.WEBSERVER_OBJECTNAME); ! iterator = (Iterator) server.getAttribute(webService, "DeployedApplications"); ! while (iterator.hasNext()) ! { ! WebApplication application = (WebApplication) iterator.next(); ! String applicationName = application.getName(); ! logger.debug("applicationName=" + applicationName); ! ! JNDIContainer container = (JNDIContainer) appTable.get(applicationName); ! logger.debug("container=" + container); ! if (container == null) ! { ! container = new JNDIContainer(); ! container.setName(application.getName()); ! container.setClassLoader(application.getClassLoader()); ! container.setContext("java:/comp"); ! } ! logger.debug("refresh container"); ! newApplications.add(container); ! container.refresh(); ! } ! context.setAttribute(Constants.WEBAPP_TREES, newApplications); ! context.setAttribute(Constants.WEBAPP_TREE, newApplications.get(0)); ! applications.clear(); ! } ! catch (Exception e) ! { ! logger.error("Error while refreshing Web modules", e); ! } ! } ! ! return (mapping.findForward("view")); ! } ! } ! |