1 5 6 package org.exoplatform.services.portletcontainer.impl; 7 8 import java.util.ArrayList ; 9 import java.util.Collection ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 import javax.servlet.ServletContext ; 14 15 import org.apache.commons.logging.Log; 16 import org.exoplatform.Constants; 17 import org.exoplatform.container.RootContainer; 18 import org.exoplatform.services.log.LogService; 19 import org.exoplatform.services.portletcontainer.*; 20 import org.exoplatform.services.portletcontainer.pci.model.*; 21 22 23 26 public class PortletApplicationRegisterImpl implements 27 PortletApplicationRegister { 28 29 private Collection listeners_; 30 private LogService logService_; 31 private Log log; 32 private PortletApplicationsHolder holder_; 33 34 public PortletApplicationRegisterImpl(PortletApplicationsHolder holder, 35 LogService logService) { 36 logService_ = logService ; 37 listeners_ = new ArrayList (); 38 holder_ = holder; 39 this.log = logService_.getLog(getClass()); 40 } 41 42 public void addPortletLyfecycleListener(PortletLifecycleListener listener) { 43 listeners_.add(listener); 44 } 45 46 public void registerPortletApplication(ServletContext servletContext, 47 PortletApp portletApp_, Collection roles) 48 throws PortletContainerException { 49 String portletAppName = servletContext.getServletContextName(); 50 log.debug("send pre deploy event for portlet app : " 51 + servletContext.getServletContextName()); 52 for (Iterator iterator = listeners_.iterator(); iterator.hasNext();) { 53 PortletLifecycleListener portletLifecycleListener = (PortletLifecycleListener) iterator 54 .next(); 55 portletLifecycleListener.preDeploy(portletAppName, portletApp_, 56 servletContext); 57 } 58 holder_.registerPortletApplication(portletAppName, portletApp_, roles); 59 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 60 RootContainer rootContainer = RootContainer.getInstance(); 61 try { 62 rootContainer 63 .registerComponentImplementation( 64 portletAppName, 65 cl 66 .loadClass("org.exoplatform.services.portletcontainer.impl.PortletApplicationProxy")); 67 } catch (ClassNotFoundException e) { 68 log.error("Class not found", e); 69 throw new PortletContainerException("Class not found", e); 70 } 71 PortletApplicationProxy proxy = (PortletApplicationProxy) rootContainer 72 .getComponentInstance(servletContext.getServletContextName()); 73 proxy.setApplicationName(servletContext.getServletContextName()); 74 proxy.load(); 75 log.debug("send post deploy event"); 76 for (Iterator iterator = listeners_.iterator(); iterator.hasNext();) { 77 PortletLifecycleListener portletLifecycleListener = (PortletLifecycleListener) iterator 78 .next(); 79 portletLifecycleListener.postDeploy(portletAppName, portletApp_, 80 servletContext); 81 } 82 } 83 84 public void removePortletApplication(ServletContext servletContext) 85 throws PortletContainerException { 86 PortletApp portletApp = holder_.getPortletApplication(servletContext 87 .getServletContextName()); 88 if (portletApp == null) 89 return; 90 String portletAppName = servletContext.getServletContextName(); 91 log.debug("send pre undeploy event"); 92 for (Iterator iterator = listeners_.iterator(); iterator.hasNext();) { 93 PortletLifecycleListener portletLifecycleListener = (PortletLifecycleListener) iterator 94 .next(); 95 portletLifecycleListener.preUndeploy(portletAppName, portletApp, 96 servletContext); 97 } 98 RootContainer.getInstance().unregisterComponent(portletAppName); 99 removeMessageListeners(portletAppName, portletApp); 100 removeFilters(portletAppName, portletApp); 101 holder_.removePortletApplication(portletAppName); 102 log.debug("send post undeploy event"); 103 for (Iterator iterator = listeners_.iterator(); iterator.hasNext();) { 104 PortletLifecycleListener portletLifecycleListener = (PortletLifecycleListener) iterator 105 .next(); 106 portletLifecycleListener.postUndeploy(portletAppName, portletApp, 107 servletContext); 108 } 109 } 110 111 private void removeMessageListeners(String portletAppName, 112 PortletApp portletApplication) { 113 log.debug("remove message listener entered"); 114 List portlets = portletApplication.getPortlet(); 115 for (Iterator iterator = portlets.iterator(); iterator.hasNext();) { 116 Portlet portlet = (Portlet) iterator.next(); 117 List listeners = portlet.getMessageListener(); 118 for (Iterator iterator1 = listeners.iterator(); iterator1.hasNext();) { 119 MessageListener messageListenerData = (MessageListener) iterator1 120 .next(); 121 String key = portletAppName + Constants.MESSAGE_LISTENER_ENCODER 122 + messageListenerData.getListenerName(); 123 RootContainer.getInstance().unregisterComponent(key); 124 } 125 } 126 } 127 128 private void removeFilters(String portletAppName, PortletApp portletApp) { 129 log.debug("remove filters entered"); 130 List portlets = portletApp.getPortlet(); 131 for (Iterator iterator = portlets.iterator(); iterator.hasNext();) { 132 Portlet portlet = (Portlet) iterator.next(); 133 List filters = portlet.getFilter(); 134 for (Iterator iterator1 = filters.iterator(); iterator1.hasNext();) { 135 Filter portletFilterData = (Filter) iterator1.next(); 136 String key = portletAppName + Constants.FILTER_ENCODER 137 + portletFilterData.getFilterName(); 138 RootContainer.getInstance().unregisterComponent(key); 139 } 140 } 141 } 142 143 } | Popular Tags |