001    /**
002     * Copyright (c) 2000-2013 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.auto;
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 Ivica Cardic
024     * @author Brian Wing Shun Chan
025     * @author Raymond Aug??
026     */
027    public class AutoDeployUtil {
028    
029            public static AutoDeployDir getDir(String name) {
030                    return getInstance()._getDir(name);
031            }
032    
033            public static AutoDeployUtil getInstance() {
034                    PortalRuntimePermission.checkGetBeanProperty(AutoDeployUtil.class);
035    
036                    return _instance;
037            }
038    
039            public static void registerDir(AutoDeployDir autoDeployDir) {
040                    getInstance()._registerDir(autoDeployDir);
041            }
042    
043            public static void unregisterDir(String name) {
044                    getInstance()._unregisterDir(name);
045            }
046    
047            private AutoDeployUtil() {
048                    _autoDeployDirs = new HashMap<String, AutoDeployDir>();
049            }
050    
051            private AutoDeployDir _getDir(String name) {
052                    return _autoDeployDirs.get(name);
053            }
054    
055            private void _registerDir(AutoDeployDir autoDeployDir) {
056                    _autoDeployDirs.put(autoDeployDir.getName(), autoDeployDir);
057    
058                    autoDeployDir.start();
059            }
060    
061            private void _unregisterDir(String name) {
062                    AutoDeployDir autoDeployDir = _autoDeployDirs.remove(name);
063    
064                    if (autoDeployDir != null) {
065                            autoDeployDir.stop();
066                    }
067            }
068    
069            private static AutoDeployUtil _instance = new AutoDeployUtil();
070    
071            private Map<String, AutoDeployDir> _autoDeployDirs;
072    
073    }