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.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    }