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.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,
039                                    "Error registering JSONWebServices for " +
040                                            hotDeployEvent.getServletContextName(),
041                                    t);
042                    }
043            }
044    
045            @Override
046            public void invokeUndeploy(HotDeployEvent hotDeployEvent)
047                    throws HotDeployException {
048    
049                    try {
050                            doInvokeUndeploy(hotDeployEvent);
051                    }
052                    catch (Throwable t) {
053                            throwHotDeployException(
054                                    hotDeployEvent,
055                                    "Error unregistering JSONWebServices for " +
056                                            hotDeployEvent.getServletContextName(),
057                                    t);
058                    }
059            }
060    
061            protected void doInvokeDeploy(HotDeployEvent hotDeployEvent)
062                    throws Exception {
063    
064                    ServletContext servletContext = hotDeployEvent.getServletContext();
065    
066                    JSONWebServiceActionsManagerUtil.registerServletContext(servletContext);
067            }
068    
069            protected void doInvokeUndeploy(HotDeployEvent hotDeployEvent)
070                    throws Exception {
071    
072                    ServletContext servletContext = hotDeployEvent.getServletContext();
073    
074                    JSONWebServiceActionsManagerUtil.unregisterServletContext(
075                            servletContext);
076            }
077    
078    }