Coverage Report - org.apache.myfaces.view.facelets.tag.jsf.PassthroughRuleImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PassthroughRuleImpl
0%
0/13
0%
0/8
2
PassthroughRuleImpl$LiteralAttributeMetadata
0%
0/6
N/A
2
PassthroughRuleImpl$ValueExpressionMetadata
0%
0/7
N/A
2
 
 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.jsf;
 20  
 
 21  
 import javax.faces.component.UIComponent;
 22  
 import javax.faces.view.facelets.FaceletContext;
 23  
 import javax.faces.view.facelets.MetaRule;
 24  
 import javax.faces.view.facelets.Metadata;
 25  
 import javax.faces.view.facelets.MetadataTarget;
 26  
 import javax.faces.view.facelets.TagAttribute;
 27  
 import org.apache.myfaces.view.facelets.PassthroughRule;
 28  
 
 29  
 /**
 30  
  *
 31  
  * @author Leonardo Uribe
 32  
  */
 33  
 final class PassthroughRuleImpl extends MetaRule implements PassthroughRule
 34  
 {
 35  
 
 36  
     final static class LiteralAttributeMetadata extends Metadata
 37  
     {
 38  
         private final String _name;
 39  
         private final String _value;
 40  
 
 41  
         public LiteralAttributeMetadata(String name, String value)
 42  0
         {
 43  0
             _name = name;
 44  0
             _value = value;
 45  0
         }
 46  
 
 47  
         public void applyMetadata(FaceletContext ctx, Object instance)
 48  
         {
 49  0
             ((UIComponent) instance).getPassThroughAttributes().put(_name, _value);
 50  0
         }
 51  
     }
 52  
 
 53  
     final static class ValueExpressionMetadata extends Metadata
 54  
     {
 55  
         private final String _name;
 56  
 
 57  
         private final TagAttribute _attr;
 58  
 
 59  
         private final Class<?> _type;
 60  
 
 61  
         public ValueExpressionMetadata(String name, Class<?> type, TagAttribute attr)
 62  0
         {
 63  0
             _name = name;
 64  0
             _attr = attr;
 65  0
             _type = type;
 66  0
         }
 67  
 
 68  
         public void applyMetadata(FaceletContext ctx, Object instance)
 69  
         {
 70  0
             ((UIComponent) instance).getPassThroughAttributes().put(
 71  
                 _name, _attr.getValueExpression(ctx, _type));
 72  0
         }
 73  
     }
 74  
 
 75  0
     public final static PassthroughRuleImpl INSTANCE = new PassthroughRuleImpl();
 76  
 
 77  
     public PassthroughRuleImpl()
 78  
     {
 79  0
         super();
 80  0
     }
 81  
 
 82  
     public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
 83  
     {
 84  0
         if (meta.isTargetInstanceOf(UIComponent.class))
 85  
         {
 86  
             // if component and dynamic, then must set expression
 87  0
             if (!attribute.isLiteral())
 88  
             {
 89  0
                 Class<?> type = meta.getPropertyType(name);
 90  0
                 if (type == null)
 91  
                 {
 92  0
                     type = Object.class;
 93  
                 }
 94  
                 // if "class" is used, set type as Object (do not confuse with getClass()). 
 95  0
                 if ("class".equalsIgnoreCase(name))
 96  
                 {
 97  0
                     type = Object.class;
 98  
                 }
 99  
                 
 100  0
                 return new ValueExpressionMetadata(name, type, attribute);
 101  
             }
 102  
             else
 103  
             {
 104  0
                 return new LiteralAttributeMetadata(name, attribute.getValue());
 105  
             }
 106  
         }
 107  0
         return null;
 108  
     }
 109  
 }