1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.StringUtil;
22  
23  import java.io.IOException;
24  import java.io.InputStream;
25  
26  import java.util.HashSet;
27  import java.util.Properties;
28  import java.util.Set;
29  
30  import javax.servlet.ServletContext;
31  
32  /**
33   * <a href="HotDeployEvent.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Ivica Cardic
36   * @author Brian Wing Shun Chan
37   */
38  public class HotDeployEvent {
39  
40      public HotDeployEvent(
41          ServletContext servletContext, ClassLoader contextClassLoader) {
42  
43          _servletContext = servletContext;
44          _contextClassLoader = contextClassLoader;
45  
46          try {
47              initDependentServletContextNames();
48          }
49          catch (IOException ioe) {
50              _log.error(ioe, ioe);
51          }
52      }
53  
54      public ClassLoader getContextClassLoader() {
55          return _contextClassLoader;
56      }
57  
58      public Set<String> getDependentServletContextNames() {
59          return _dependentServletContextNames;
60      }
61  
62      public PluginPackage getPluginPackage() {
63          return _pluginPackage;
64      }
65  
66      public ServletContext getServletContext() {
67          return _servletContext;
68      }
69  
70      public String getServletContextName() {
71          return _servletContext.getServletContextName();
72      }
73  
74      public void setPluginPackage(PluginPackage pluginPackage) {
75          _pluginPackage = pluginPackage;
76      }
77  
78      protected void initDependentServletContextNames() throws IOException {
79          InputStream is = _servletContext.getResourceAsStream(
80              "/WEB-INF/liferay-plugin-package.properties");
81  
82          _dependentServletContextNames = new HashSet<String>();
83  
84          if (is != null) {
85              String propertiesString = StringUtil.read(is);
86  
87              is.close();
88  
89              Properties properties = PropertiesUtil.load(propertiesString);
90  
91              String[] requiredDeploymentContexts = StringUtil.split(
92                  properties.getProperty("required-deployment-contexts"));
93  
94              if ((requiredDeploymentContexts.length > 0) &&
95                  (_log.isInfoEnabled())) {
96  
97                  _log.info(
98                      "Plugin " + _servletContext.getServletContextName() +
99                          " 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;
116     private PluginPackage _pluginPackage;
117     private ServletContext _servletContext;
118 
119 }