001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.deploy.sandbox;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    /**
023     * @author Igor Spasic
024     * @author Brian Wing Shun Chan
025     * @author Raymond Aug??
026     */
027    public class SandboxDeployUtil {
028    
029            public static SandboxDeployDir getDir(String name) {
030                    return getInstance()._getDir(name);
031            }
032    
033            public static SandboxDeployUtil getInstance() {
034                    PortalRuntimePermission.checkGetBeanProperty(SandboxDeployUtil.class);
035    
036                    return _instance;
037            }
038    
039            public static void registerDir(SandboxDeployDir sandboxDeployDir) {
040                    getInstance()._registerDir(sandboxDeployDir);
041            }
042    
043            public static void unregisterDir(String name) {
044                    getInstance()._unregisterDir(name);
045            }
046    
047            private SandboxDeployUtil() {
048                    _sandboxDeployDirs = new HashMap<String, SandboxDeployDir>();
049            }
050    
051            private SandboxDeployDir _getDir(String name) {
052                    return _sandboxDeployDirs.get(name);
053            }
054    
055            private void _registerDir(SandboxDeployDir sandboxDeployDir) {
056                    _sandboxDeployDirs.put(sandboxDeployDir.getName(), sandboxDeployDir);
057    
058                    sandboxDeployDir.start();
059            }
060    
061            private void _unregisterDir(String name) {
062                    SandboxDeployDir sandboxDeployDir = _sandboxDeployDirs.remove(name);
063    
064                    if (sandboxDeployDir != null) {
065                            sandboxDeployDir.stop();
066                    }
067            }
068    
069            private static SandboxDeployUtil _instance = new SandboxDeployUtil();
070    
071            private Map<String, SandboxDeployDir> _sandboxDeployDirs;
072    
073    }