Coverage Report - org.apache.myfaces.view.facelets.tag.jsf.ValueHolderRule
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueHolderRule
0%
0/13
0%
0/10
2
ValueHolderRule$DynamicConverterMetadata2
0%
0/5
N/A
2
ValueHolderRule$DynamicValueExpressionMetadata
0%
0/5
N/A
2
ValueHolderRule$LiteralConverterMetadata
0%
0/5
N/A
2
ValueHolderRule$LiteralValueMetadata
0%
0/5
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.component.ValueHolder;
 23  
 import javax.faces.convert.Converter;
 24  
 import javax.faces.view.facelets.FaceletContext;
 25  
 import javax.faces.view.facelets.MetaRule;
 26  
 import javax.faces.view.facelets.Metadata;
 27  
 import javax.faces.view.facelets.MetadataTarget;
 28  
 import javax.faces.view.facelets.TagAttribute;
 29  
 
 30  
 /**
 31  
  * 
 32  
  * @author Jacob Hookom
 33  
  * @version $Id$
 34  
  */
 35  0
 public final class ValueHolderRule extends MetaRule
 36  
 {
 37  
 
 38  
     final static class LiteralConverterMetadata extends Metadata
 39  
     {
 40  
 
 41  
         private final String converterId;
 42  
 
 43  
         public LiteralConverterMetadata(String converterId)
 44  0
         {
 45  0
             this.converterId = converterId;
 46  0
         }
 47  
 
 48  
         public void applyMetadata(FaceletContext ctx, Object instance)
 49  
         {
 50  0
             ((ValueHolder) instance).setConverter(ctx.getFacesContext().getApplication()
 51  
                     .createConverter(this.converterId));
 52  0
         }
 53  
     }
 54  
 
 55  
     final static class DynamicConverterMetadata2 extends Metadata
 56  
     {
 57  
 
 58  
         private final TagAttribute attr;
 59  
 
 60  
         public DynamicConverterMetadata2(TagAttribute attr)
 61  0
         {
 62  0
             this.attr = attr;
 63  0
         }
 64  
 
 65  
         public void applyMetadata(FaceletContext ctx, Object instance)
 66  
         {
 67  0
             ((UIComponent) instance).setValueExpression("converter", attr.getValueExpression(ctx, Converter.class));
 68  0
         }
 69  
     }
 70  
 
 71  
     final static class LiteralValueMetadata extends Metadata
 72  
     {
 73  
 
 74  
         private final String value;
 75  
 
 76  
         public LiteralValueMetadata(String value)
 77  0
         {
 78  0
             this.value = value;
 79  0
         }
 80  
 
 81  
         public void applyMetadata(FaceletContext ctx, Object instance)
 82  
         {
 83  0
             ((ValueHolder) instance).setValue(this.value);
 84  0
         }
 85  
     }
 86  
 
 87  0
     final static class DynamicValueExpressionMetadata extends Metadata
 88  
     {
 89  
 
 90  
         private final TagAttribute attr;
 91  
 
 92  
         public DynamicValueExpressionMetadata(TagAttribute attr)
 93  0
         {
 94  0
             this.attr = attr;
 95  0
         }
 96  
 
 97  
         public void applyMetadata(FaceletContext ctx, Object instance)
 98  
         {
 99  0
             ((UIComponent) instance).setValueExpression("value", attr.getValueExpression(ctx, Object.class));
 100  0
         }
 101  
     }
 102  
 
 103  0
     public final static ValueHolderRule INSTANCE = new ValueHolderRule();
 104  
 
 105  
     public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
 106  
     {
 107  0
         if (meta.isTargetInstanceOf(ValueHolder.class))
 108  
         {
 109  
 
 110  0
             if ("converter".equals(name))
 111  
             {
 112  0
                 if (attribute.isLiteral())
 113  
                 {
 114  0
                     return new LiteralConverterMetadata(attribute.getValue());
 115  
                 }
 116  
                 else
 117  
                 {
 118  0
                     return new DynamicConverterMetadata2(attribute);
 119  
                 }
 120  
             }
 121  
 
 122  0
             if ("value".equals(name))
 123  
             {
 124  0
                 if (attribute.isLiteral())
 125  
                 {
 126  0
                     return new LiteralValueMetadata(attribute.getValue());
 127  
                 }
 128  
                 else
 129  
                 {
 130  0
                     return new DynamicValueExpressionMetadata(attribute);
 131  
                 }
 132  
             }
 133  
         }
 134  0
         return null;
 135  
     }
 136  
 
 137  
 }