Coverage Report - javax.faces.view.ViewMetadata
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewMetadata
0%
0/35
0%
0/28
4.4
 
 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 javax.faces.view;
 20  
 
 21  
 import java.util.Collection;
 22  
 import java.util.Collections;
 23  
 import java.util.Iterator;
 24  
 import java.util.LinkedList;
 25  
 
 26  
 import javax.faces.component.UIComponent;
 27  
 import javax.faces.component.UIViewAction;
 28  
 import javax.faces.component.UIViewParameter;
 29  
 import javax.faces.component.UIViewRoot;
 30  
 import javax.faces.context.FacesContext;
 31  
 
 32  
 /**
 33  
  * @since 2.0
 34  
  */
 35  0
 public abstract class ViewMetadata
 36  
 {
 37  
     public abstract UIViewRoot createMetadataView(FacesContext context);
 38  
     
 39  
     public abstract String getViewId();
 40  
     
 41  
     public static Collection<UIViewParameter> getViewParameters(UIViewRoot root)
 42  
     {
 43  0
         LinkedList<UIViewParameter> result = null;
 44  0
         UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
 45  
         Iterator<UIComponent> children;
 46  
         
 47  0
         if (metadataFacet == null)
 48  
         {
 49  
              // No metadata, so return an empty collection.
 50  
              
 51  0
              return Collections.emptyList();
 52  
         }
 53  
         
 54  
         // Iterate over all the children, keep only the view parameters.
 55  
         
 56  0
         if (metadataFacet.getChildCount() > 0)
 57  
         {
 58  0
             children = metadataFacet.getChildren().iterator();
 59  
             
 60  0
             while (children.hasNext())
 61  
             {
 62  0
                  UIComponent component = children.next();
 63  
                  
 64  0
                  if (result == null)
 65  
                  {
 66  0
                      result = new LinkedList<UIViewParameter>();
 67  
                  }
 68  
                  
 69  0
                  if (component instanceof UIViewParameter)
 70  
                  {
 71  0
                       result.add ((UIViewParameter) component);
 72  
                  }
 73  0
             }
 74  
         }
 75  
         
 76  
         // TODO: does this need to be immutable?  Spec does not indicate either
 77  
         // way.
 78  0
         if (result == null)
 79  
         {
 80  0
             return Collections.emptyList();
 81  
         }
 82  
         else
 83  
         {
 84  0
             return Collections.unmodifiableCollection (result);
 85  
         }
 86  
     }
 87  
     
 88  
     /**
 89  
      * @since 2.2
 90  
      * @param root
 91  
      * @return 
 92  
      */
 93  
     public static Collection<UIViewAction> getViewActions(UIViewRoot root)
 94  
     {
 95  0
         LinkedList<UIViewAction> result = null;
 96  0
         UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
 97  
         Iterator<UIComponent> children;
 98  
         
 99  0
         if (metadataFacet == null)
 100  
         {
 101  
              // No metadata, so return an empty collection.
 102  
              
 103  0
              return Collections.emptyList();
 104  
         }
 105  
         
 106  
         // Iterate over all the children, keep only the view parameters.
 107  
         
 108  0
         if (metadataFacet.getChildCount() > 0)
 109  
         {
 110  0
             children = metadataFacet.getChildren().iterator();
 111  
             
 112  0
             while (children.hasNext())
 113  
             {
 114  0
                  UIComponent component = children.next();
 115  
                  
 116  0
                  if (result == null)
 117  
                  {
 118  0
                      result = new LinkedList<UIViewAction>();
 119  
                  }
 120  
                  
 121  0
                  if (component instanceof UIViewAction)
 122  
                  {
 123  0
                       result.add ((UIViewAction) component);
 124  
                  }
 125  0
             }
 126  
         }
 127  
         
 128  
         // TODO: does this need to be immutable?  Spec does not indicate either
 129  
         // way.
 130  0
         if (result == null)
 131  
         {
 132  0
             return Collections.emptyList();
 133  
         }
 134  
         else
 135  
         {
 136  0
             return Collections.unmodifiableCollection (result);
 137  
         }
 138  
     }
 139  
     
 140  
     /**
 141  
      * @since 2.2
 142  
      * @param root
 143  
      * @return 
 144  
      */
 145  
     public static boolean hasMetadata(UIViewRoot root)
 146  
     {
 147  0
         UIComponent metadataFacet = root.getFacet(UIViewRoot.METADATA_FACET_NAME);
 148  0
         return metadataFacet != null ? metadataFacet.getChildCount() > 0 : false;
 149  
     }
 150  
 }