001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.deploy.hot;
016    
017    import com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener;
018    import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
019    import com.liferay.portal.kernel.deploy.hot.HotDeployException;
020    import com.liferay.portal.kernel.servlet.SecurePluginContextListener;
021    
022    import java.lang.reflect.Method;
023    
024    import javax.servlet.ServletContext;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ServletContextListenerHotDeployListener
030            extends BaseHotDeployListener {
031    
032            @Override
033            public void invokeDeploy(HotDeployEvent hotDeployEvent)
034                    throws HotDeployException {
035    
036                    try {
037                            doInvokeDeploy(hotDeployEvent);
038                    }
039                    catch (Throwable t) {
040                            throwHotDeployException(
041                                    hotDeployEvent,
042                                    "Error registering servlet context listeners for ", t);
043                    }
044            }
045    
046            @Override
047            public void invokeUndeploy(HotDeployEvent hotDeployEvent)
048                    throws HotDeployException {
049    
050                    try {
051                            doInvokeUndeploy(hotDeployEvent);
052                    }
053                    catch (Throwable t) {
054                            throwHotDeployException(
055                                    hotDeployEvent,
056                                    "Error unregistering servlet context listeners for ", t);
057                    }
058            }
059    
060            protected void doInvokeDeploy(HotDeployEvent hotDeployEvent)
061                    throws Exception {
062    
063                    ServletContext servletContext = hotDeployEvent.getServletContext();
064    
065                    Object securePluginContextListener = servletContext.getAttribute(
066                            SecurePluginContextListener.class.getName());
067    
068                    if (securePluginContextListener != null) {
069                            Class<?> clazz = securePluginContextListener.getClass();
070    
071                            Method method = clazz.getMethod("instantiatingListeners");
072    
073                            method.invoke(securePluginContextListener);
074                    }
075            }
076    
077            protected void doInvokeUndeploy(HotDeployEvent hotDeployEvent)
078                    throws Exception {
079            }
080    
081    }