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.util.GetterUtil;
018    import com.liferay.portal.server.DeepNamedValueScanner;
019    
020    import javax.servlet.ServletContext;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     * @author Igor Spasic
025     */
026    public class GlassfishServerCapabilities implements ServerCapabilities {
027    
028            @Override
029            public void determine(ServletContext servletContext) throws Exception {
030                    determineSupportsHotDeploy(servletContext);
031            }
032    
033            @Override
034            public boolean isSupportsHotDeploy() {
035                    return _supportsHotDeploy;
036            }
037    
038            protected void determineSupportsHotDeploy(ServletContext servletContext)
039                    throws Exception {
040    
041                    DeepNamedValueScanner deepNamedValueScanner = new DeepNamedValueScanner(
042                            "masterView");
043    
044                    deepNamedValueScanner.setExcludedClassNames("org.apache.felix.");
045                    deepNamedValueScanner.setSkipFirstCount(4);
046    
047                    deepNamedValueScanner.scan(servletContext);
048    
049                    if (deepNamedValueScanner.isScanning()) {
050                            _supportsHotDeploy = false;
051    
052                            return;
053                    }
054    
055                    Object masterViewObject = deepNamedValueScanner.getMatchedValue();
056    
057                    deepNamedValueScanner = new DeepNamedValueScanner("autodeploy-enabled");
058    
059                    deepNamedValueScanner.setExcludedClassNames(
060                            "org.apache.felix.", "CountStatisticImpl");
061                    deepNamedValueScanner.setSkipFirstCount(2);
062                    deepNamedValueScanner.setVisitMaps(true);
063    
064                    deepNamedValueScanner.scan(masterViewObject);
065    
066                    boolean autoDeployEnabled = true;
067    
068                    if (!deepNamedValueScanner.isScanning()) {
069                            autoDeployEnabled = GetterUtil.getBoolean(
070                                    deepNamedValueScanner.getMatchedValue());
071                    }
072    
073                    _supportsHotDeploy = autoDeployEnabled;
074            }
075    
076            private boolean _supportsHotDeploy;
077    
078    }