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.server.capabilities;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.ServerDetector;
020    
021    import javax.servlet.ServletContext;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Igor Spasic
026     */
027    public class ServerCapabilitiesUtil {
028    
029            public static void determineServerCapabilities(
030                    ServletContext servletContext) {
031    
032                    ServerCapabilities serverCapabilities = null;
033    
034                    if (ServerDetector.isGlassfish()) {
035                            serverCapabilities = new GlassfishServerCapabilities();
036                    }
037                    else if (ServerDetector.isJBoss()) {
038                            serverCapabilities = new JBossServerCapabilities();
039                    }
040                    else if (ServerDetector.isJetty()) {
041                            serverCapabilities = new JettyServerCapabilities();
042                    }
043                    else if (ServerDetector.isTomcat()) {
044                            serverCapabilities = new TomcatServerCapabilities();
045                    }
046    
047                    if (serverCapabilities == null) {
048                            serverCapabilities = new DefaultServerCapabilities();
049                    }
050    
051                    if (_log.isInfoEnabled()) {
052                            Class<?> clazz = serverCapabilities.getClass();
053    
054                            _log.info("Using " + clazz.getName());
055                    }
056    
057                    try {
058                            serverCapabilities.determine(servletContext);
059                    }
060                    catch (Exception e) {
061                            _log.error("Unable to determine server capabilities", e);
062                    }
063    
064                    ServerDetector.setSupportsHotDeploy(
065                            serverCapabilities.isSupportsHotDeploy());
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    ServerCapabilitiesUtil.class);
070    
071    }