001    /**
002     * Copyright (c) 2000-2012 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            public void determine(ServletContext servletContext) throws Exception {
029                    determineSupportsHotDeploy(servletContext);
030            }
031    
032            public boolean isSupportsHotDeploy() {
033                    return _supportsHotDeploy;
034            }
035    
036            protected void determineSupportsHotDeploy(ServletContext servletContext)
037                    throws Exception {
038    
039                    DeepNamedValueScanner deepNamedValueScanner = new DeepNamedValueScanner(
040                            "masterView");
041    
042                    deepNamedValueScanner.setExcludedClassNames("org.apache.felix.");
043                    deepNamedValueScanner.setSkipFirstCount(4);
044    
045                    deepNamedValueScanner.scan(servletContext);
046    
047                    if (deepNamedValueScanner.isScanning()) {
048                            _supportsHotDeploy = false;
049    
050                            return;
051                    }
052    
053                    Object masterViewObject = deepNamedValueScanner.getMatchedValue();
054    
055                    deepNamedValueScanner = new DeepNamedValueScanner("autodeploy-enabled");
056    
057                    deepNamedValueScanner.setExcludedClassNames(
058                            "org.apache.felix.", "CountStatisticImpl");
059                    deepNamedValueScanner.setSkipFirstCount(2);
060                    deepNamedValueScanner.setVisitMaps(true);
061    
062                    deepNamedValueScanner.scan(masterViewObject);
063    
064                    boolean autoDeployEnabled = true;
065    
066                    if (!deepNamedValueScanner.isScanning()) {
067                            autoDeployEnabled = GetterUtil.getBoolean(
068                                    deepNamedValueScanner.getMatchedValue());
069                    }
070    
071                    _supportsHotDeploy = autoDeployEnabled;
072            }
073    
074            private boolean _supportsHotDeploy;
075    
076    }