removed confusing addHandler form HandlerWrappers

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@56 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-03-31 22:14:29 +00:00
parent a52c01804a
commit afa399375a
15 changed files with 52 additions and 63 deletions

View File

@ -19,6 +19,7 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.resource.Resource;
@ -42,7 +43,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class WebAppDeployer extends AbstractLifeCycle
{
private HandlerContainer _contexts;
private HandlerCollection _contexts;
private String _webAppDir;
private String _defaultsDescriptor;
private String[] _configurationClasses;
@ -66,7 +67,7 @@ public class WebAppDeployer extends AbstractLifeCycle
return _contexts;
}
public void setContexts(HandlerContainer contexts)
public void setContexts(HandlerCollection contexts)
{
_contexts=contexts;
}

View File

@ -90,7 +90,7 @@ public class ManyHandlers
HandlerList list = new HandlerList();
// link them all together
wrapper.addHandler(hello);
wrapper.setHandler(hello);
list.setHandlers(new Handler[]{param,wrapper,dft});
handlers.setHandlers(new Handler[]{list,log});

View File

@ -24,9 +24,6 @@ import org.eclipse.jetty.util.component.LifeCycle;
*/
public interface HandlerContainer extends LifeCycle
{
public void addHandler(Handler handler);
public void removeHandler(Handler handler);
public Handler[] getChildHandlers();
public Handler[] getChildHandlersByClass(Class<?> byclass);
public Handler getChildHandlerByClass(Class<?> byclass);

View File

@ -634,35 +634,28 @@ public class Server extends HandlerWrapper implements Attributes
}
}
/* ------------------------------------------------------------ */
/**
/** Append a handler.
* If the handler is null, set it as the passed handler.
* If the handler is a HandlerWrapper, append it to the handler
* If the handler is a HandlerCollection, add it to the handler
* else throw an {@link IllegalStateException}
*
* @param handler
*/
public void addHandler(Handler handler)
public void appendHandler(Handler handler)
{
if (getHandler() == null)
Handler old = getHandler();
if (old==null)
setHandler(handler);
else if (getHandler() instanceof HandlerCollection)
((HandlerCollection)getHandler()).addHandler(handler);
else if (old instanceof HandlerWrapper)
((HandlerWrapper)old).appendHandler(handler);
else if (old instanceof HandlerCollection)
((HandlerCollection)old).addHandler(handler);
else
{
HandlerCollection collection=new HandlerCollection();
collection.setHandlers(new Handler[]{getHandler(),handler});
setHandler(collection);
}
throw new IllegalStateException();
}
/* ------------------------------------------------------------ */
/**
*/
public void removeHandler(Handler handler)
{
if (getHandler() instanceof HandlerCollection)
((HandlerCollection)getHandler()).removeHandler(handler);
}
/* ------------------------------------------------------------ */
/**
*/

View File

@ -171,7 +171,10 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
{
this();
setContextPath(contextPath);
parent.addHandler(this);
if (parent instanceof HandlerWrapper)
((HandlerWrapper)parent).appendHandler(this);
else if (parent instanceof HandlerCollection)
((HandlerCollection)parent).addHandler(this);
}
/* ------------------------------------------------------------ */

View File

@ -86,38 +86,29 @@ public class HandlerWrapper extends AbstractHandlerContainer
}
/* ------------------------------------------------------------ */
/** Add a handler.
* This implementation of addHandler calls setHandler with the
* passed handler. If this HandlerWrapper had a previous wrapped
* handler, then it is passed to a call to addHandler on the passed
* handler. Thus this call can add a handler in a chain of
* wrapped handlers.
/** Append a handler.
* If the handler is null, set it as the passed handler.
* If the handler is a HandlerWrapper, append it to the handler
* If the handler is a HandlerCollection, add it to the handler
* else throw an {@link IllegalStateException}
*
* @param handler
*/
public void addHandler(Handler handler)
public void appendHandler(Handler handler)
{
Handler old = getHandler();
if (old!=null && !(handler instanceof HandlerContainer))
throw new IllegalArgumentException("Cannot add");
setHandler(handler);
if (old!=null)
((HandlerContainer)handler).addHandler(old);
}
public void removeHandler (Handler handler)
{
Handler old = getHandler();
if (old!=null && (old instanceof HandlerContainer))
((HandlerContainer)old).removeHandler(handler);
else if (old!=null && handler==old)
setHandler(null);
if (old==null)
setHandler(handler);
else if (old instanceof HandlerWrapper)
((HandlerWrapper)old).appendHandler(handler);
else if (old instanceof HandlerCollection)
((HandlerCollection)old).addHandler(handler);
else
throw new IllegalStateException("Cannot remove");
throw new IllegalStateException();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStart()

View File

@ -43,7 +43,7 @@ public class MovedContextHandler extends ContextHandler
public MovedContextHandler()
{
_redirector=new Redirector();
addHandler(_redirector);
setHandler(_redirector);
setAllowNullPathInfo(true);
}
@ -52,7 +52,7 @@ public class MovedContextHandler extends ContextHandler
super(parent,contextPath);
_newContextURL=newContextURL;
_redirector=new Redirector();
addHandler(_redirector);
setHandler(_redirector);
}
public boolean isDiscardPathInfo()

View File

@ -363,7 +363,7 @@ public class ResponseTest extends TestCase
SocketConnector socketConnector = new SocketConnector();
socketConnector.setPort(0);
server.addConnector(socketConnector);
server.addHandler(new AbstractHandler()
server.setHandler(new AbstractHandler()
{
public void handle(String string, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{

View File

@ -34,7 +34,7 @@ public class ServerTest extends TestCase
DefaultHandler handler=new DefaultHandler();
try
{
server.addHandler(handler);
server.setHandler(handler);
}
catch (Exception e)
{

View File

@ -155,7 +155,7 @@ public class ContextHandlerTest extends TestCase
IsHandledHandler handler = new IsHandledHandler();
context.setHandler(handler);
server.addHandler(context);
server.setHandler(context);
try
{

View File

@ -60,7 +60,7 @@ public class ServletTester
{
_server.setSendServerVersion(false);
_server.addConnector(_connector);
_server.addHandler(_context);
_server.setHandler(_context);
}
catch (Error e)
{

View File

@ -27,6 +27,8 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.session.SessionHandler;
@ -106,8 +108,10 @@ public class ServletContextHandler extends ContextHandler
if (contextPath!=null)
setContextPath(contextPath);
if (parent!=null)
parent.addHandler(this);
if (parent instanceof HandlerWrapper)
((HandlerWrapper)parent).appendHandler(this);
else if (parent instanceof HandlerCollection)
((HandlerCollection)parent).addHandler(this);
}

View File

@ -57,7 +57,7 @@ public class StatisticsServlet extends HttpServlet
{
Log.info("Installing Statistics Handler");
_statsHandler = new StatisticsHandler();
_server.addHandler(_statsHandler);
_server.setHandler(_statsHandler);
}

View File

@ -45,7 +45,7 @@ public class DispatcherTest extends TestCase
_connector = new LocalConnector();
_context = new ServletContextHandler();
_context.setContextPath("/context");
_server.addHandler(_context);
_server.setHandler(_context);
_server.addConnector( _connector );
_server.start();

View File

@ -45,7 +45,7 @@ public class InvokerTest extends TestCase
_server.setSendServerVersion(false);
_server.addConnector(_connector);
_server.addHandler(_context);
_server.setHandler(_context);
_context.setContextPath("/");