1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.deploy.hot;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.kernel.plugin.PluginPackage;
25  import com.liferay.portal.kernel.util.PropertiesUtil;
26  import com.liferay.portal.kernel.util.SetUtil;
27  import com.liferay.portal.kernel.util.StringUtil;
28  
29  import java.io.IOException;
30  import java.io.InputStream;
31  
32  import java.util.HashSet;
33  import java.util.Properties;
34  import java.util.Set;
35  
36  import javax.servlet.ServletContext;
37  
38  /**
39   * <a href="HotDeployEvent.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Ivica Cardic
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class HotDeployEvent {
46  
47      public HotDeployEvent(
48          ServletContext servletContext, ClassLoader contextClassLoader) {
49  
50          _servletContext = servletContext;
51          _contextClassLoader = contextClassLoader;
52  
53          try {
54              initDependentServletContextNames();
55          }
56          catch (IOException ioe) {
57              _log.error(ioe, ioe);
58          }
59      }
60  
61      public ClassLoader getContextClassLoader() {
62          return _contextClassLoader;
63      }
64  
65      public Set<String> getDependentServletContextNames() {
66          return _dependentServletContextNames;
67      }
68  
69      public PluginPackage getPluginPackage() {
70          return _pluginPackage;
71      }
72  
73      public ServletContext getServletContext() {
74          return _servletContext;
75      }
76  
77      public String getServletContextName() {
78          return _servletContext.getServletContextName();
79      }
80  
81      public void setPluginPackage(PluginPackage pluginPackage) {
82          _pluginPackage = pluginPackage;
83      }
84  
85      protected void initDependentServletContextNames() throws IOException {
86          InputStream is = _servletContext.getResourceAsStream(
87              "/WEB-INF/liferay-plugin-package.properties");
88  
89          if (is == null) {
90              _dependentServletContextNames = new HashSet<String>();
91          }
92          else {
93              String propertiesString = StringUtil.read(is);
94  
95              is.close();
96  
97              Properties properties = PropertiesUtil.load(propertiesString);
98  
99              String[] requiredDeploymentContexts = StringUtil.split(
100                 properties.getProperty("required-deployment-contexts"));
101 
102             if ((requiredDeploymentContexts.length > 0) &&
103                 (_log.isInfoEnabled())) {
104 
105                 _log.info(
106                     "Plugin " + _servletContext.getServletContextName() +
107                         " requires " +
108                         StringUtil.merge(requiredDeploymentContexts, ", "));
109             }
110 
111             _dependentServletContextNames = SetUtil.fromArray(
112                 requiredDeploymentContexts);
113         }
114     }
115 
116     private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
117 
118     private ClassLoader _contextClassLoader;
119     private Set<String> _dependentServletContextNames;
120     private PluginPackage _pluginPackage;
121     private ServletContext _servletContext;
122 
123 }