Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.server.handler;
 
 
 
 
 
 /* ------------------------------------------------------------ */
Abstract Handler Container. This is the base class for handlers that may contain other handlers.
 
 public abstract class AbstractHandlerContainer extends AbstractHandler implements HandlerContainer
 {
     /* ------------------------------------------------------------ */
     public AbstractHandlerContainer()
     {
     }
     
     /* ------------------------------------------------------------ */
     public Handler[] getChildHandlers()
     {
         Object list = expandChildren(null,null);
         return (Handler[])LazyList.toArray(listHandler.class);
     }
         
     /* ------------------------------------------------------------ */
     public Handler[] getChildHandlersByClass(Class<?> byclass)
     {
         Object list = expandChildren(null,byclass);
         return (Handler[])LazyList.toArray(listbyclass);
     }
     
     /* ------------------------------------------------------------ */
     public <T extends Handler> T getChildHandlerByClass(Class<T> byclass)
     {
         // TODO this can be more efficient?
         Object list = expandChildren(null,byclass);
         if (list==null)
             return null;
         return (T)LazyList.get(list, 0);
     }
     
     /* ------------------------------------------------------------ */
     protected Object expandChildren(Object listClass<?> byClass)
     {
         return list;
     }
 
     /* ------------------------------------------------------------ */
     protected Object expandHandler(Handler handlerObject listClass<HandlerbyClass)
     {
         if (handler==null)
             return list;
         
         if (byClass==null || byClass.isAssignableFrom(handler.getClass()))
             list=LazyList.add(listhandler);
 
         if (handler instanceof AbstractHandlerContainer)
             list=((AbstractHandlerContainer)handler).expandChildren(listbyClass);
         else if (handler instanceof HandlerContainer)
         {
             HandlerContainer container = (HandlerContainer)handler;
             Handler[] handlers=byClass==null?container.getChildHandlers():container.getChildHandlersByClass(byClass);
             list=LazyList.addArray(listhandlers);
         }
         
         return list;
     }
     
     /* ------------------------------------------------------------ */
     public static <T extends HandlerContainer> T findContainerOf(HandlerContainer root,Class<T>typeHandler handler)
     {
         if (root==null || handler==null)
             return null;
         
         Handler[] branches=root.getChildHandlersByClass(type);
        if (branches!=null)
        {
            for (Handler h:branches)
            {
                T container = (T)h;
                Handler[] candidates = container.getChildHandlersByClass(handler.getClass());
                if (candidates!=null)
                {
                    for (Handler c:candidates)
                        if (c==handler)
                            return container;
                }
            }
        }
        return null;
    }
    
    /* ------------------------------------------------------------ */
    public void dump(Appendable out,String indentthrows IOException
    {
        dumpThis(out);
        dump(out,indent,getBeans(),TypeUtil.asList(getHandlers()));
    }
New to GrepCode? Check out our FAQ X