Coverage Report - org.apache.myfaces.view.facelets.tag.ui.RepeatHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
RepeatHandler
0%
0/8
0%
0/4
3
RepeatHandler$TagMetaData
0%
0/19
0%
0/10
3
 
 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.ui;
 20  
 
 21  
 import java.beans.Introspector;
 22  
 import java.beans.PropertyDescriptor;
 23  
 import java.util.HashSet;
 24  
 import java.util.Map;
 25  
 import java.util.Set;
 26  
 
 27  
 import javax.faces.component.UIComponent;
 28  
 import javax.faces.view.facelets.ComponentConfig;
 29  
 import javax.faces.view.facelets.ComponentHandler;
 30  
 import javax.faces.view.facelets.FaceletContext;
 31  
 import javax.faces.view.facelets.MetaRuleset;
 32  
 import javax.faces.view.facelets.Metadata;
 33  
 import javax.faces.view.facelets.TagAttribute;
 34  
 
 35  
 /**
 36  
  * Facelet alternative to c:forEach or h:dataTable
 37  
  *
 38  
  */
 39  0
 public class RepeatHandler extends ComponentHandler
 40  
 {
 41  
     
 42  
     public RepeatHandler(ComponentConfig config)
 43  
     {
 44  0
         super(config);
 45  0
     }
 46  
 
 47  
     protected MetaRuleset createMetaRuleset(Class type)
 48  
     {
 49  0
         MetaRuleset meta = super.createMetaRuleset(type);
 50  
 
 51  0
         if (!UILibrary.NAMESPACE.equals(this.tag.getNamespace()) &&
 52  
             !UILibrary.ALIAS_NAMESPACE.equals(this.tag.getNamespace()))
 53  
         {
 54  0
             meta.add(new TagMetaData(type));
 55  
         }
 56  
 
 57  0
         meta.alias("class", "styleClass");
 58  
 
 59  0
         return meta;
 60  
     }
 61  
 
 62  
     private class TagMetaData extends Metadata
 63  
     {
 64  
         private final String[] _attrs;
 65  
 
 66  
         public TagMetaData(Class<?> type)
 67  0
         {
 68  0
             Set<String> names = new HashSet<String>();
 69  0
             for (TagAttribute attribute : tag.getAttributes().getAll())
 70  
             {
 71  0
                 if ("class".equals(attribute.getLocalName()))
 72  
                 {
 73  0
                     names.add("styleClass");
 74  
                 }
 75  
                 else
 76  
                 {
 77  0
                     names.add(attribute.getLocalName());
 78  
                 }
 79  
             }
 80  
             
 81  
             try
 82  
             {
 83  0
                 for (PropertyDescriptor descriptor : Introspector.getBeanInfo(type).getPropertyDescriptors())
 84  
                 {
 85  0
                     if (descriptor.getWriteMethod() != null)
 86  
                     {
 87  0
                         names.remove(descriptor.getName());
 88  
                     }
 89  
                 }
 90  
             }
 91  0
             catch (Exception e)
 92  
             {
 93  
                 // do nothing
 94  0
             }
 95  
             
 96  0
             _attrs = names.toArray(new String[names.size()]);
 97  0
         }
 98  
 
 99  
         public void applyMetadata(FaceletContext ctx, Object instance)
 100  
         {
 101  0
             UIComponent component = (UIComponent) instance;
 102  0
             Map<String, Object> attrs = component.getAttributes();
 103  0
             attrs.put("alias.element", tag.getQName());
 104  0
             if (_attrs.length > 0)
 105  
             {
 106  0
                 attrs.put("alias.attributes", _attrs);
 107  
             }
 108  0
         }
 109  
     }
 110  
 }