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.module.framework;
016    
017    import com.liferay.portal.util.PortalUtil;
018    import com.liferay.registry.collections.ServiceTrackerCollections;
019    
020    import java.io.IOException;
021    
022    import java.util.List;
023    
024    import javax.servlet.ServletException;
025    import javax.servlet.http.HttpServlet;
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Miguel Pastor
031     * @author Raymond Aug??
032     */
033    public class ModuleFrameworkServletAdapter extends HttpServlet {
034    
035            @Override
036            protected void service(
037                            HttpServletRequest request, HttpServletResponse response)
038                    throws IOException, ServletException {
039    
040                    if (_servlets.isEmpty()) {
041                            PortalUtil.sendError(
042                                    HttpServletResponse.SC_SERVICE_UNAVAILABLE,
043                                    new ServletException("Module framework is unavailable"),
044                                    request, response);
045    
046                            return;
047                    }
048    
049                    HttpServlet httpServlet = _servlets.get(0);
050    
051                    httpServlet.service(request, response);
052            }
053    
054            private final List<HttpServlet> _servlets =
055                    ServiceTrackerCollections.openList(
056                            HttpServlet.class,
057                            "(&(bean.id=" + HttpServlet.class.getName() +
058                                    ")(original.bean=*))");
059    
060    }