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