1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.deploy.hot;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.plugin.PluginPackage;
20  import com.liferay.portal.kernel.util.PropertiesUtil;
21  import com.liferay.portal.kernel.util.SetUtil;
22  import com.liferay.portal.kernel.util.StringUtil;
23  
24  import java.io.IOException;
25  import java.io.InputStream;
26  
27  import java.util.HashSet;
28  import java.util.Properties;
29  import java.util.Set;
30  
31  import javax.servlet.ServletContext;
32  
33  /**
34   * <a href="HotDeployEvent.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Ivica Cardic
37   * @author Brian Wing Shun Chan
38   */
39  public class HotDeployEvent {
40  
41      public HotDeployEvent(
42          ServletContext servletContext, ClassLoader contextClassLoader) {
43  
44          _servletContext = servletContext;
45          _contextClassLoader = contextClassLoader;
46  
47          try {
48              initDependentServletContextNames();
49          }
50          catch (IOException ioe) {
51              _log.error(ioe, ioe);
52          }
53      }
54  
55      public ClassLoader getContextClassLoader() {
56          return _contextClassLoader;
57      }
58  
59      public Set<String> getDependentServletContextNames() {
60          return _dependentServletContextNames;
61      }
62  
63      public PluginPackage getPluginPackage() {
64          return _pluginPackage;
65      }
66  
67      public ServletContext getServletContext() {
68          return _servletContext;
69      }
70  
71      public String getServletContextName() {
72          return _servletContext.getServletContextName();
73      }
74  
75      public void setPluginPackage(PluginPackage pluginPackage) {
76          _pluginPackage = pluginPackage;
77      }
78  
79      protected void initDependentServletContextNames() throws IOException {
80          InputStream is = _servletContext.getResourceAsStream(
81              "/WEB-INF/liferay-plugin-package.properties");
82  
83          if (is == null) {
84              _dependentServletContextNames = new HashSet<String>();
85          }
86          else {
87              String propertiesString = StringUtil.read(is);
88  
89              is.close();
90  
91              Properties properties = PropertiesUtil.load(propertiesString);
92  
93              String[] requiredDeploymentContexts = StringUtil.split(
94                  properties.getProperty("required-deployment-contexts"));
95  
96              if ((requiredDeploymentContexts.length > 0) &&
97                  (_log.isInfoEnabled())) {
98  
99                  _log.info(
100                     "Plugin " + _servletContext.getServletContextName() +
101                         " requires " +
102                         StringUtil.merge(requiredDeploymentContexts, ", "));
103             }
104 
105             _dependentServletContextNames = SetUtil.fromArray(
106                 requiredDeploymentContexts);
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 }