1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.deploy.hot;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.plugin.PluginPackage;
28  import com.liferay.portal.kernel.util.PropertiesUtil;
29  import com.liferay.portal.kernel.util.SetUtil;
30  import com.liferay.portal.kernel.util.StringUtil;
31  
32  import java.io.IOException;
33  import java.io.InputStream;
34  
35  import java.util.HashSet;
36  import java.util.Properties;
37  import java.util.Set;
38  
39  import javax.servlet.ServletContext;
40  
41  /**
42   * <a href="HotDeployEvent.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Ivica Cardic
45   * @author Brian Wing Shun Chan
46   *
47   */
48  public class HotDeployEvent {
49  
50      public HotDeployEvent(
51          ServletContext servletContext, ClassLoader contextClassLoader) {
52  
53          _servletContext = servletContext;
54          _contextClassLoader = contextClassLoader;
55  
56          try {
57              initDependentServletContextNames();
58          }
59          catch (IOException ioe) {
60              _log.error(ioe, ioe);
61          }
62      }
63  
64      public ClassLoader getContextClassLoader() {
65          return _contextClassLoader;
66      }
67  
68      public Set<String> getDependentServletContextNames() {
69          return _dependentServletContextNames;
70      }
71  
72      public PluginPackage getPluginPackage() {
73          return _pluginPackage;
74      }
75  
76      public ServletContext getServletContext() {
77          return _servletContext;
78      }
79  
80      public String getServletContextName() {
81          return _servletContext.getServletContextName();
82      }
83  
84      public void setPluginPackage(PluginPackage pluginPackage) {
85          _pluginPackage = pluginPackage;
86      }
87  
88      protected void initDependentServletContextNames() throws IOException {
89          InputStream is = _servletContext.getResourceAsStream(
90              "/WEB-INF/liferay-plugin-package.properties");
91  
92          if (is == null) {
93              _dependentServletContextNames = new HashSet<String>();
94          }
95          else {
96              String propertiesString = StringUtil.read(is);
97  
98              is.close();
99  
100             Properties properties = PropertiesUtil.load(propertiesString);
101 
102             String[] requiredDeploymentContexts = StringUtil.split(
103                 properties.getProperty("required-deployment-contexts"));
104 
105             if ((requiredDeploymentContexts.length > 0) &&
106                 (_log.isInfoEnabled())) {
107 
108                 _log.info(
109                     "Plugin " + _servletContext.getServletContextName() +
110                         " requires " +
111                         StringUtil.merge(requiredDeploymentContexts, ", "));
112             }
113 
114             _dependentServletContextNames = SetUtil.fromArray(
115                 requiredDeploymentContexts);
116         }
117     }
118 
119     private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
120 
121     private ClassLoader _contextClassLoader;
122     private Set<String> _dependentServletContextNames;
123     private PluginPackage _pluginPackage;
124     private ServletContext _servletContext;
125 
126 }