001    /**
002     * Copyright (c) 2000-present 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.deploy.hot;
016    
017    import com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener;
018    import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
019    import com.liferay.portal.kernel.deploy.hot.HotDeployException;
020    import com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionsManagerUtil;
021    
022    import javax.servlet.ServletContext;
023    
024    /**
025     * @author Igor Spasic
026     */
027    public class JSONWebServiceHotDeployListener extends BaseHotDeployListener {
028    
029            @Override
030            public void invokeDeploy(HotDeployEvent hotDeployEvent)
031                    throws HotDeployException {
032    
033                    try {
034                            doInvokeDeploy(hotDeployEvent);
035                    }
036                    catch (Throwable t) {
037                            throwHotDeployException(
038                                    hotDeployEvent, "Error registering JSONWebServices for ", t);
039                    }
040            }
041    
042            @Override
043            public void invokeUndeploy(HotDeployEvent hotDeployEvent)
044                    throws HotDeployException {
045    
046                    try {
047                            doInvokeUndeploy(hotDeployEvent);
048                    }
049                    catch (Throwable t) {
050                            throwHotDeployException(
051                                    hotDeployEvent, "Error unregistering JSONWebServices for ", t);
052                    }
053            }
054    
055            protected void doInvokeDeploy(HotDeployEvent hotDeployEvent)
056                    throws Exception {
057    
058                    ServletContext servletContext = hotDeployEvent.getServletContext();
059    
060                    JSONWebServiceActionsManagerUtil.registerServletContext(servletContext);
061            }
062    
063            protected void doInvokeUndeploy(HotDeployEvent hotDeployEvent)
064                    throws Exception {
065    
066                    ServletContext servletContext = hotDeployEvent.getServletContext();
067    
068                    JSONWebServiceActionsManagerUtil.unregisterServletContext(
069                            servletContext);
070            }
071    
072    }