1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class HotDeployEvent {
48  
49      public HotDeployEvent(
50          ServletContext servletContext, ClassLoader contextClassLoader) {
51  
52          _servletContext = servletContext;
53          _contextClassLoader = contextClassLoader;
54  
55          try {
56              initDependentServletContextNames();
57          }
58          catch (IOException ioe) {
59              _log.error(ioe, ioe);
60          }
61      }
62  
63      public ClassLoader getContextClassLoader() {
64          return _contextClassLoader;
65      }
66  
67      public Set<String> getDependentServletContextNames() {
68          return _dependentServletContextNames;
69      }
70  
71      public PluginPackage getPluginPackage() {
72          return _pluginPackage;
73      }
74  
75      public ServletContext getServletContext() {
76          return _servletContext;
77      }
78  
79      public String getServletContextName() {
80          return _servletContext.getServletContextName();
81      }
82  
83      public void setPluginPackage(PluginPackage pluginPackage) {
84          _pluginPackage = pluginPackage;
85      }
86  
87      protected void initDependentServletContextNames() throws IOException {
88          InputStream is = _servletContext.getResourceAsStream(
89              "/WEB-INF/liferay-plugin-package.properties");
90  
91          if (is == null) {
92              _dependentServletContextNames = new HashSet<String>();
93          }
94          else {
95              String propertiesString = StringUtil.read(is);
96  
97              is.close();
98  
99              Properties properties = PropertiesUtil.load(propertiesString);
100 
101             String[] requiredDeploymentContexts = StringUtil.split(
102                 properties.getProperty("required-deployment-contexts"));
103 
104             if ((requiredDeploymentContexts.length > 0) &&
105                 (_log.isInfoEnabled())) {
106 
107                 _log.info(
108                     "Plugin " + _servletContext.getServletContextName() +
109                         " requires " +
110                         StringUtil.merge(requiredDeploymentContexts, ", "));
111             }
112 
113             _dependentServletContextNames = SetUtil.fromArray(
114                 requiredDeploymentContexts);
115         }
116     }
117 
118     private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
119 
120     private ClassLoader _contextClassLoader;
121     private Set<String> _dependentServletContextNames;
122     private PluginPackage _pluginPackage;
123     private ServletContext _servletContext;
124 
125 }