Coverage Report - org.apache.myfaces.view.facelets.tag.jsf.ComponentRule
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentRule
0%
0/17
0%
0/10
2
ComponentRule$LiteralAttributeMetadata
0%
0/6
N/A
2
ComponentRule$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 java.util.logging.Level;
 22  
 import java.util.logging.Logger;
 23  
 
 24  
 import javax.faces.component.UIComponent;
 25  
 import javax.faces.view.facelets.FaceletContext;
 26  
 import javax.faces.view.facelets.MetaRule;
 27  
 import javax.faces.view.facelets.Metadata;
 28  
 import javax.faces.view.facelets.MetadataTarget;
 29  
 import javax.faces.view.facelets.TagAttribute;
 30  
 
 31  
 /**
 32  
  * 
 33  
  * @author Jacob Hookom
 34  
  * @version $Id$
 35  
  */
 36  
 final class ComponentRule extends MetaRule
 37  
 {
 38  
 
 39  
     final class LiteralAttributeMetadata extends Metadata
 40  
     {
 41  
         private final String _name;
 42  
         private final String _value;
 43  
 
 44  
         public LiteralAttributeMetadata(String name, String value)
 45  0
         {
 46  0
             _name = name;
 47  0
             _value = value;
 48  0
         }
 49  
 
 50  
         public void applyMetadata(FaceletContext ctx, Object instance)
 51  
         {
 52  0
             ((UIComponent) instance).getAttributes().put(_name, _value);
 53  0
         }
 54  
     }
 55  
 
 56  
     final static class ValueExpressionMetadata extends Metadata
 57  
     {
 58  
         private final String _name;
 59  
 
 60  
         private final TagAttribute _attr;
 61  
 
 62  
         private final Class<?> _type;
 63  
 
 64  
         public ValueExpressionMetadata(String name, Class<?> type, TagAttribute attr)
 65  0
         {
 66  0
             _name = name;
 67  0
             _attr = attr;
 68  0
             _type = type;
 69  0
         }
 70  
 
 71  
         public void applyMetadata(FaceletContext ctx, Object instance)
 72  
         {
 73  0
             ((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _type));
 74  0
         }
 75  
     }
 76  
 
 77  
     //private final static Logger log = Logger.getLogger("facelets.tag.component");
 78  0
     private final static Logger log = Logger.getLogger(ComponentRule.class.getName());
 79  
 
 80  0
     public final static ComponentRule INSTANCE = new ComponentRule();
 81  
 
 82  
     public ComponentRule()
 83  
     {
 84  0
         super();
 85  0
     }
 86  
 
 87  
     public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
 88  
     {
 89  0
         if (meta.isTargetInstanceOf(UIComponent.class))
 90  
         {
 91  
             // if component and dynamic, then must set expression
 92  0
             if (!attribute.isLiteral())
 93  
             {
 94  0
                 Class<?> type = meta.getPropertyType(name);
 95  0
                 if (type == null)
 96  
                 {
 97  0
                     type = Object.class;
 98  
                 }
 99  
                 
 100  0
                 return new ValueExpressionMetadata(name, type, attribute);
 101  
             }
 102  0
             else if (meta.getWriteMethod(name) == null)
 103  
             {
 104  
 
 105  
                 // this was an attribute literal, but not property
 106  0
                 warnAttr(attribute, meta.getTargetClass(), name);
 107  
 
 108  0
                 return new LiteralAttributeMetadata(name, attribute.getValue());
 109  
             }
 110  
         }
 111  0
         return null;
 112  
     }
 113  
 
 114  
     private static void warnAttr(TagAttribute attr, Class<?> type, String n)
 115  
     {
 116  0
         if (log.isLoggable(Level.FINER))
 117  
         {
 118  0
             log.finer(attr + " Property '" + n + "' is not on type: " + type.getName());
 119  
         }
 120  0
     }
 121  
 
 122  
 }