001    /**
002     * Copyright (c) 2000-2012 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.server.capabilities;
016    
017    import com.liferay.portal.kernel.util.ReflectionUtil;
018    
019    import java.lang.reflect.Field;
020    
021    import javax.servlet.ServletContext;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Igor Spasic
026     */
027    public class TomcatServerCapabilities implements ServerCapabilities {
028    
029            public void determine(ServletContext servletContext) throws Exception {
030                    determineSupportsHotDeploy(servletContext);
031            }
032    
033            public boolean isSupportsHotDeploy() {
034                    return _supportsHotDeploy;
035            }
036    
037            protected void determineSupportsHotDeploy(ServletContext servletContext)
038                    throws Exception {
039    
040                    // org.apache.catalina.core.ApplicationContextFacade
041    
042                    Class<?> applicationContextFacadeClass = servletContext.getClass();
043    
044                    Field contextField1 = ReflectionUtil.getDeclaredField(
045                            applicationContextFacadeClass, "context");
046    
047                    Object contextValue1 = contextField1.get(servletContext);
048    
049                    // org.apache.catalina.core.ApplicationContext
050    
051                    Class<?> applicationContextClass = contextField1.getType();
052    
053                    Field contextField2 = ReflectionUtil.getDeclaredField(
054                            applicationContextClass, "context");
055    
056                    Object contextValue2 = contextField2.get(contextValue1);
057    
058                    // org.apache.catalina.core.StandardContext
059    
060                    Class<?> standardContextClass = contextField2.getType();
061    
062                    // org.apache.catalina.core.ContainerBase
063    
064                    Class<?> containerBaseClass = standardContextClass.getSuperclass();
065    
066                    Field parentField = ReflectionUtil.getDeclaredField(
067                            containerBaseClass, "parent");
068    
069                    Object parentValue = parentField.get(contextValue2);
070    
071                    Field autoDeployField = ReflectionUtil.getDeclaredField(
072                            parentValue.getClass(), "autoDeploy");
073    
074                    Boolean autoDeployValue = (Boolean)autoDeployField.get(parentValue);
075    
076                    _supportsHotDeploy = autoDeployValue;
077            }
078    
079            private boolean _supportsHotDeploy;
080    
081    }