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.sandbox;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  /**
21   * <a href="SandboxDeployUtil.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Igor Spasic
24   * @author Brian Wing Shun Chan
25   */
26  public class SandboxDeployUtil {
27  
28      public static SandboxDeployDir getDir(String name) {
29          return _instance._getDir(name);
30      }
31  
32      public static void registerDir(SandboxDeployDir sandboxDeployDir) {
33          _instance._registerDir(sandboxDeployDir);
34      }
35  
36      public static void unregisterDir(String name) {
37          _instance._unregisterDir(name);
38      }
39  
40      private SandboxDeployUtil() {
41          _sandboxDeployDirs = new HashMap<String, SandboxDeployDir>();
42      }
43  
44      private SandboxDeployDir _getDir(String name) {
45          return _sandboxDeployDirs.get(name);
46      }
47  
48      private void _registerDir(SandboxDeployDir sandboxDeployDir) {
49          _sandboxDeployDirs.put(sandboxDeployDir.getName(), sandboxDeployDir);
50  
51          sandboxDeployDir.start();
52      }
53  
54      private void _unregisterDir(String name) {
55          SandboxDeployDir sandboxDeployDir = _sandboxDeployDirs.remove(name);
56  
57          if (sandboxDeployDir != null) {
58              sandboxDeployDir.stop();
59          }
60      }
61  
62      private static SandboxDeployUtil _instance = new SandboxDeployUtil();
63  
64      private Map<String, SandboxDeployDir> _sandboxDeployDirs;
65  
66  }