Coverage Report - org.apache.myfaces.view.facelets.tag.TagHandlerUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
TagHandlerUtils
0%
0/39
0%
0/44
5.8
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.view.facelets.tag;
 20  
 
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 import java.util.List;
 24  
 
 25  
 import javax.faces.view.facelets.FaceletHandler;
 26  
 
 27  
 /**
 28  
  * This class was created to gather some code from latest Facelets not existing in latest JSF 2.0 spec.
 29  
  * Also, since it was created on the fly while converting, it's highly possible that methods in this class
 30  
  * should be moved in a more logical location and/or removed.
 31  
  *
 32  
  * @author Simon Lessard (latest modification by $Author$)
 33  
  * @version $Revision$ $Date$
 34  
  *
 35  
  * @since 2.0
 36  
  */
 37  
 public final class TagHandlerUtils
 38  
 {
 39  
 
 40  
     /**
 41  
      * Find the first occurence of a tag handler that is instanceof T
 42  
      *
 43  
      * @since 2.0.1
 44  
      * @param <T>
 45  
      * @param nextHandler
 46  
      * @param type
 47  
      * @return
 48  
      */
 49  
     public static <T> T findFirstNextByType(FaceletHandler nextHandler, Class<T> type)
 50  
     {
 51  0
         if (type.isAssignableFrom(nextHandler.getClass()))
 52  
         {
 53  0
             return (T)nextHandler;
 54  
         }
 55  0
         else if (nextHandler instanceof javax.faces.view.facelets.CompositeFaceletHandler)
 56  
         {
 57  
             for (FaceletHandler handler :
 58  0
                     ((javax.faces.view.facelets.CompositeFaceletHandler)nextHandler).getHandlers())
 59  
             {
 60  0
                 if (type.isAssignableFrom(handler.getClass()))
 61  
                 {
 62  0
                     return (T)handler;
 63  
                 }
 64  
             }
 65  
         }
 66  0
         return null;
 67  
     }
 68  
 
 69  
     /**
 70  
      * From TagHandler:
 71  
      * protected final <T> Iterator<T> findNextByType(Class<T> type)
 72  
      *
 73  
      * @param type
 74  
      * @return
 75  
      */
 76  
     @SuppressWarnings("unchecked")
 77  
     public static <T> Collection<T> findNextByType(FaceletHandler nextHandler, Class<T> type)
 78  
     {
 79  0
         List<T> found = new ArrayList<T>();
 80  0
         if (type.isAssignableFrom(nextHandler.getClass()))
 81  
         {
 82  0
             found.add((T)nextHandler);
 83  
         }
 84  0
         else if (nextHandler instanceof javax.faces.view.facelets.CompositeFaceletHandler)
 85  
         {
 86  
             for (FaceletHandler handler :
 87  0
                     ((javax.faces.view.facelets.CompositeFaceletHandler)nextHandler).getHandlers())
 88  
             {
 89  0
                 if (type.isAssignableFrom(handler.getClass()))
 90  
                 {
 91  0
                     found.add((T)handler);
 92  
                 }
 93  
             }
 94  
         }
 95  
 
 96  0
         return found;
 97  
     }
 98  
 
 99  
     private TagHandlerUtils()
 100  0
     {
 101  
 
 102  0
     }
 103  
 
 104  
     public static  Collection<FaceletHandler> findNextByType(FaceletHandler nextHandler, Class<?> ... type1)
 105  
     {
 106  0
         List<FaceletHandler> found = new ArrayList<FaceletHandler>();
 107  0
         boolean isAssignable = false;
 108  0
         for (int i = 0; i < type1.length && !isAssignable; i++)
 109  
         {
 110  0
             isAssignable = type1[i].isAssignableFrom(nextHandler.getClass());
 111  
         }
 112  0
         if (isAssignable)
 113  
         {
 114  0
             found.add((FaceletHandler)nextHandler);
 115  
         }
 116  0
         else if (nextHandler instanceof javax.faces.view.facelets.CompositeFaceletHandler)
 117  
         {
 118  
             for (FaceletHandler handler :
 119  0
                     ((javax.faces.view.facelets.CompositeFaceletHandler)nextHandler).getHandlers())
 120  
             {
 121  0
                 isAssignable = false;
 122  0
                 for (int i = 0; i < type1.length && !isAssignable; i++)
 123  
                 {
 124  0
                     isAssignable = type1[i].isAssignableFrom(handler.getClass());
 125  
                 }
 126  0
                 if (isAssignable)
 127  
                 {
 128  0
                     found.add((FaceletHandler)handler);
 129  
                 }
 130  
             }
 131  
         }
 132  
 
 133  0
         return found;
 134  
     }
 135  
 
 136  
     public static  Collection<FaceletHandler> findNextByType(FaceletHandler nextHandler, Class<?> type1, Class<?> type2)
 137  
     {
 138  0
         List<FaceletHandler> found = new ArrayList<FaceletHandler>();
 139  0
         if (type1.isAssignableFrom(nextHandler.getClass()) || type2.isAssignableFrom(nextHandler.getClass()))
 140  
         {
 141  0
             found.add((FaceletHandler)nextHandler);
 142  
         }
 143  0
         else if (nextHandler instanceof javax.faces.view.facelets.CompositeFaceletHandler)
 144  
         {
 145  
             for (FaceletHandler handler :
 146  0
                     ((javax.faces.view.facelets.CompositeFaceletHandler)nextHandler).getHandlers())
 147  
             {
 148  0
                 if (type1.isAssignableFrom(handler.getClass()) || type2.isAssignableFrom(handler.getClass()))
 149  
                 {
 150  0
                     found.add((FaceletHandler)handler);
 151  
                 }
 152  
             }
 153  
         }
 154  
         
 155  0
         return found;
 156  
     }
 157  
 }