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                            Properties properties = PropertiesUtil.load(propertiesString);
090    
091                            String[] requiredDeploymentContexts = StringUtil.split(
092                                    properties.getProperty("required-deployment-contexts"));
093    
094                            if ((requiredDeploymentContexts.length > 0) &&
095                                    _log.isInfoEnabled()) {
096    
097                                    _log.info(
098                                            "Plugin " + _servletContext.getServletContextName() +
099                                                    " requires " +
100                                                    StringUtil.merge(requiredDeploymentContexts, ", "));
101                            }
102    
103                            for (String requiredDeploymentContext :
104                                            requiredDeploymentContexts) {
105    
106                                    _dependentServletContextNames.add(
107                                            requiredDeploymentContext.trim());
108                            }
109                    }
110            }
111    
112            private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
113    
114            private ClassLoader _contextClassLoader;
115            private Set<String> _dependentServletContextNames = new HashSet<String>();
116            private PluginPackage _pluginPackage;
117            private ServletContext _servletContext;
118    
119    }