001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.deploy.sandbox;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    /**
021     * @author Igor Spasic
022     * @author Brian Wing Shun Chan
023     */
024    public class SandboxDeployUtil {
025    
026            public static SandboxDeployDir getDir(String name) {
027                    return _instance._getDir(name);
028            }
029    
030            public static void registerDir(SandboxDeployDir sandboxDeployDir) {
031                    _instance._registerDir(sandboxDeployDir);
032            }
033    
034            public static void unregisterDir(String name) {
035                    _instance._unregisterDir(name);
036            }
037    
038            private SandboxDeployUtil() {
039                    _sandboxDeployDirs = new HashMap<String, SandboxDeployDir>();
040            }
041    
042            private SandboxDeployDir _getDir(String name) {
043                    return _sandboxDeployDirs.get(name);
044            }
045    
046            private void _registerDir(SandboxDeployDir sandboxDeployDir) {
047                    _sandboxDeployDirs.put(sandboxDeployDir.getName(), sandboxDeployDir);
048    
049                    sandboxDeployDir.start();
050            }
051    
052            private void _unregisterDir(String name) {
053                    SandboxDeployDir sandboxDeployDir = _sandboxDeployDirs.remove(name);
054    
055                    if (sandboxDeployDir != null) {
056                            sandboxDeployDir.stop();
057                    }
058            }
059    
060            private static SandboxDeployUtil _instance = new SandboxDeployUtil();
061    
062            private Map<String, SandboxDeployDir> _sandboxDeployDirs;
063    
064    }