001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.deploy.hot;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.plugin.PluginPackage;
020    import com.liferay.portal.kernel.util.PropertiesUtil;
021    import com.liferay.portal.kernel.util.StringUtil;
022    
023    import java.io.IOException;
024    import java.io.InputStream;
025    
026    import java.util.HashSet;
027    import java.util.Properties;
028    import java.util.Set;
029    
030    import javax.servlet.ServletContext;
031    
032    /**
033     * @author Ivica Cardic
034     * @author Brian Wing Shun Chan
035     * @author Raymond Augé
036     * @author Miguel Pastor
037     */
038    public class HotDeployEvent {
039    
040            public HotDeployEvent(
041                    ServletContext servletContext, ClassLoader contextClassLoader) {
042    
043                    _servletContext = servletContext;
044                    _contextClassLoader = contextClassLoader;
045    
046                    try {
047                            initDependentServletContextNames();
048                    }
049                    catch (IOException ioe) {
050                            _log.error(ioe, ioe);
051                    }
052            }
053    
054            public ClassLoader getContextClassLoader() {
055                    return _contextClassLoader;
056            }
057    
058            public Set<String> getDependentServletContextNames() {
059                    return _dependentServletContextNames;
060            }
061    
062            public PluginPackage getPluginPackage() {
063                    return _pluginPackage;
064            }
065    
066            public ServletContext getServletContext() {
067                    return _servletContext;
068            }
069    
070            public String getServletContextName() {
071                    return _servletContext.getServletContextName();
072            }
073    
074            public void setPluginPackage(PluginPackage pluginPackage) {
075                    _pluginPackage = pluginPackage;
076            }
077    
078            protected void initDependentServletContextNames() throws IOException {
079                    if (!DependencyManagementThreadLocal.isEnabled()) {
080                            return;
081                    }
082    
083                    InputStream is = _servletContext.getResourceAsStream(
084                            "/WEB-INF/liferay-plugin-package.properties");
085    
086                    if (is != null) {
087                            String propertiesString = StringUtil.read(is);
088    
089                            is.close();
090    
091                            Properties properties = PropertiesUtil.load(propertiesString);
092    
093                            String[] requiredDeploymentContexts = StringUtil.split(
094                                    properties.getProperty("required-deployment-contexts"));
095    
096                            if ((requiredDeploymentContexts.length > 0) &&
097                                    _log.isInfoEnabled()) {
098    
099                                    _log.info(
100                                            "Plugin " + _servletContext.getServletContextName() +
101                                                    " requires " +
102                                                    StringUtil.merge(requiredDeploymentContexts, ", "));
103                            }
104    
105                            for (String requiredDeploymentContext :
106                                            requiredDeploymentContexts) {
107    
108                                    _dependentServletContextNames.add(
109                                            requiredDeploymentContext.trim());
110                            }
111                    }
112            }
113    
114            private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
115    
116            private ClassLoader _contextClassLoader;
117            private Set<String> _dependentServletContextNames = new HashSet<String>();
118            private PluginPackage _pluginPackage;
119            private ServletContext _servletContext;
120    
121    }