001    /**
002     * Copyright (c) 2000-2010 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.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     */
036    public class HotDeployEvent {
037    
038            public HotDeployEvent(
039                    ServletContext servletContext, ClassLoader contextClassLoader) {
040    
041                    _servletContext = servletContext;
042                    _contextClassLoader = contextClassLoader;
043    
044                    try {
045                            initDependentServletContextNames();
046                    }
047                    catch (IOException ioe) {
048                            _log.error(ioe, ioe);
049                    }
050            }
051    
052            public ClassLoader getContextClassLoader() {
053                    return _contextClassLoader;
054            }
055    
056            public Set<String> getDependentServletContextNames() {
057                    return _dependentServletContextNames;
058            }
059    
060            public PluginPackage getPluginPackage() {
061                    return _pluginPackage;
062            }
063    
064            public ServletContext getServletContext() {
065                    return _servletContext;
066            }
067    
068            public String getServletContextName() {
069                    return _servletContext.getServletContextName();
070            }
071    
072            public void setPluginPackage(PluginPackage pluginPackage) {
073                    _pluginPackage = pluginPackage;
074            }
075    
076            protected void initDependentServletContextNames() throws IOException {
077                    InputStream is = _servletContext.getResourceAsStream(
078                            "/WEB-INF/liferay-plugin-package.properties");
079    
080                    _dependentServletContextNames = new HashSet<String>();
081    
082                    if (is != null) {
083                            String propertiesString = StringUtil.read(is);
084    
085                            is.close();
086    
087                            Properties properties = PropertiesUtil.load(propertiesString);
088    
089                            String[] requiredDeploymentContexts = StringUtil.split(
090                                    properties.getProperty("required-deployment-contexts"));
091    
092                            if ((requiredDeploymentContexts.length > 0) &&
093                                    (_log.isInfoEnabled())) {
094    
095                                    _log.info(
096                                            "Plugin " + _servletContext.getServletContextName() +
097                                                    " requires " +
098                                                    StringUtil.merge(requiredDeploymentContexts, ", "));
099                            }
100    
101                            for (String requiredDeploymentContext :
102                                            requiredDeploymentContexts) {
103    
104                                    _dependentServletContextNames.add(
105                                            requiredDeploymentContext.trim());
106                            }
107                    }
108            }
109    
110            private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
111    
112            private ClassLoader _contextClassLoader;
113            private Set<String> _dependentServletContextNames;
114            private PluginPackage _pluginPackage;
115            private ServletContext _servletContext;
116    
117    }