Coverage Report - org.apache.myfaces.view.facelets.tag.composite.RetargetMethodExpressionRule
 
Classes in this File Line Coverage Branch Coverage Complexity
RetargetMethodExpressionRule
0%
0/17
0%
0/18
4.25
RetargetMethodExpressionRule$RetargetValueExpressionMapper
0%
0/7
N/A
4.25
 
 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.composite;
 20  
 
 21  
 import java.beans.PropertyDescriptor;
 22  
 
 23  
 import javax.el.ValueExpression;
 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  
  * Rule used to wire ValueExpressions retrieved by ViewDeclarationLanguage.retargetMethodExpressions 
 33  
  * 
 34  
  * @author Leonardo Uribe (latest modification by $Author$)
 35  
  * @version $Revision$ $Date$
 36  
  */
 37  
 final class RetargetMethodExpressionRule extends MetaRule
 38  
 {
 39  
     final static class RetargetValueExpressionMapper extends Metadata
 40  
     {
 41  
         private final TagAttribute _attr;
 42  
         
 43  
         private final String _name;
 44  
 
 45  
         public RetargetValueExpressionMapper(TagAttribute attr, String name)
 46  0
         {
 47  0
             this._attr = attr;
 48  0
             this._name = name;
 49  0
         }
 50  
 
 51  
         public void applyMetadata(FaceletContext ctx, Object instance)
 52  
         {
 53  0
             ValueExpression expr = _attr.getValueExpression(ctx, Object.class);
 54  0
             ((UIComponent) instance).getAttributes().put(_name, expr);
 55  0
         }
 56  
     }
 57  
 
 58  0
     public final static RetargetMethodExpressionRule INSTANCE = new RetargetMethodExpressionRule();
 59  
 
 60  
     public RetargetMethodExpressionRule()
 61  
     {
 62  0
         super();
 63  0
     }
 64  
 
 65  
     public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
 66  
     {
 67  
         // ViewDeclarationLanguage.retargetMethodExpressions only works when a method-signature 
 68  
         // is defined, so we just have to apply this rule on that case. 
 69  0
         if ("action".equals(name) || 
 70  
             "actionListener".equals(name) ||
 71  
             "validator".equals(name) ||
 72  
             "valueChangeListener".equals(name))
 73  
         {
 74  0
             return new RetargetValueExpressionMapper(attribute, name);
 75  
         }
 76  
         else
 77  
         {
 78  0
             PropertyDescriptor propertyDescriptor = meta.getProperty(name);
 79  
             //Type takes precedence over method-signature
 80  0
             if (propertyDescriptor != null && 
 81  
                     propertyDescriptor.getValue("type") == null)
 82  
             {
 83  0
                 ValueExpression methodSignatureExpression = 
 84  
                     (ValueExpression) propertyDescriptor.getValue("method-signature");
 85  
                 
 86  0
                 if (methodSignatureExpression != null)
 87  
                 {
 88  0
                     return new RetargetValueExpressionMapper(attribute, name);
 89  
                 }
 90  
                 
 91  0
                 ValueExpression targetAttributeNameVE = 
 92  
                     (ValueExpression)propertyDescriptor.getValue("targetAttributeName");
 93  0
                 if (targetAttributeNameVE != null)
 94  
                 {
 95  0
                     return new RetargetValueExpressionMapper(attribute, name);
 96  
                 }
 97  
                 
 98  
                 //if there is a targets declaration, is a retarget without doubt
 99  0
                 ValueExpression targets = 
 100  
                     (ValueExpression)propertyDescriptor.getValue("targets");
 101  
                 
 102  0
                 if (targets != null)
 103  
                 {
 104  0
                     return new RetargetValueExpressionMapper(attribute, name);
 105  
                 }
 106  
             }
 107  
         }
 108  0
         return null;
 109  
     }
 110  
 }