org.mortbay.jetty.handler.HandlerCollection Maven / Gradle / Ivy
//========================================================================
//$Id: HandlerCollection.java,v 1.5 2005/11/11 22:55:39 gregwilkins Exp $
//Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.mortbay.jetty.handler;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mortbay.jetty.EofException;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.util.LazyList;
import org.mortbay.util.MultiException;
/* ------------------------------------------------------------ */
/** A collection of handlers.
* For each request, all handler are called, regardless of
* the response status or exceptions.
*
* @author gregw
* @org.apache.xbean.XBean
*/
public class HandlerCollection extends AbstractHandlerContainer
{
private Handler[] _handlers;
/* ------------------------------------------------------------ */
public HandlerCollection()
{
super();
}
/* ------------------------------------------------------------ */
/**
* @return Returns the handlers.
*/
public Handler[] getHandlers()
{
return _handlers;
}
/* ------------------------------------------------------------ */
/**
*
* @param handlers The handlers to set.
*/
public void setHandlers(Handler[] handlers)
{
Handler [] old_handlers = _handlers==null?null:(Handler[])_handlers.clone();
if (getServer()!=null)
getServer().getContainer().update(this, old_handlers, handlers, "handler");
Server server = getServer();
MultiException mex = new MultiException();
for (int i=0;handlers!=null && i0;)
try{_handlers[i].stop();}catch(Throwable e){mex.add(e);}
}
mex.ifExceptionThrow();
}
/* ------------------------------------------------------------ */
public void setServer(Server server)
{
Server old_server=getServer();
super.setServer(server);
Handler[] h=getHandlers();
for (int i=0;h!=null && i0 )
setHandlers((Handler[])LazyList.removeFromArray(handlers, handler));
}
/* ------------------------------------------------------------ */
protected Object expandChildren(Object list, Class byClass)
{
Handler[] handlers = getHandlers();
for (int i=0;handlers!=null && i