Coverage Report - org.apache.myfaces.view.facelets.tag.composite.CompositeMetadataTargetImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CompositeMetadataTargetImpl
0%
0/34
0%
0/14
2.714
 
 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.BeanInfo;
 22  
 import java.beans.IntrospectionException;
 23  
 import java.beans.PropertyDescriptor;
 24  
 import java.lang.reflect.Method;
 25  
 import java.util.HashMap;
 26  
 import java.util.Map;
 27  
 
 28  
 import javax.el.ValueExpression;
 29  
 import javax.faces.view.facelets.MetadataTarget;
 30  
 import javax.faces.context.FacesContext;
 31  
 import org.apache.myfaces.shared.util.ClassUtils;
 32  
 
 33  
 
 34  
 /**
 35  
  * Like MetadataTargetImpl but integrate composite component bean info
 36  
  * with it.
 37  
  * 
 38  
  * @author Leonardo Uribe (latest modification by $Author$)
 39  
  * @version $Revision$ $Date$
 40  
  */
 41  
 final class CompositeMetadataTargetImpl extends MetadataTarget
 42  
 {
 43  
     private final Map<String, PropertyDescriptor> _pd;
 44  
     
 45  
     private final MetadataTarget _delegate;
 46  
     
 47  
     private final BeanInfo _beanInfo;
 48  
 
 49  
     public CompositeMetadataTargetImpl(MetadataTarget delegate, BeanInfo beanInfo) throws IntrospectionException
 50  0
     {
 51  0
         _delegate = delegate;
 52  0
         _beanInfo = beanInfo;
 53  
         
 54  0
         _pd = new HashMap<String, PropertyDescriptor>();
 55  
         
 56  0
         for (PropertyDescriptor descriptor : _beanInfo.getPropertyDescriptors())
 57  
         {
 58  0
             _pd.put(descriptor.getName(), descriptor);
 59  
         }
 60  0
     }
 61  
 
 62  
     public PropertyDescriptor getProperty(String name)
 63  
     {
 64  0
         PropertyDescriptor pd = _delegate.getProperty(name); 
 65  0
         if (pd == null)
 66  
         {
 67  0
             pd = _pd.get(name);
 68  
         }
 69  0
         return pd;
 70  
     }
 71  
 
 72  
     public Class<?> getPropertyType(String name)
 73  
     {
 74  0
         PropertyDescriptor pd = getProperty(name);
 75  0
         if (pd != null)
 76  
         {
 77  0
             Object type = pd.getValue("type");
 78  0
             if (type != null)
 79  
             {
 80  0
                 type = ((ValueExpression)type).getValue(FacesContext.getCurrentInstance().getELContext());
 81  0
                 if (type instanceof String)
 82  
                 {
 83  
                     try
 84  
                     {
 85  0
                         type = ClassUtils.javaDefaultTypeToClass((String)type);
 86  
                     }
 87  0
                     catch (ClassNotFoundException e)
 88  
                     {
 89  0
                         type = Object.class;
 90  0
                     }
 91  
                 }
 92  0
                 return (Class<?>) type;
 93  
             }
 94  0
             return pd.getPropertyType();
 95  
         }
 96  
         
 97  0
         return null;
 98  
     }
 99  
 
 100  
     public Method getReadMethod(String name)
 101  
     {
 102  0
         PropertyDescriptor pd = getProperty(name);
 103  0
         if (pd != null)
 104  
         {
 105  0
             return pd.getReadMethod();
 106  
         }
 107  
         
 108  0
         return null;
 109  
     }
 110  
 
 111  
     public Class<?> getTargetClass()
 112  
     {
 113  0
         return _delegate.getTargetClass();
 114  
     }
 115  
 
 116  
     public Method getWriteMethod(String name)
 117  
     {
 118  0
         PropertyDescriptor pd = getProperty(name);
 119  0
         if (pd != null)
 120  
         {
 121  0
             return pd.getWriteMethod();
 122  
         }
 123  
         
 124  0
         return null;
 125  
     }
 126  
 
 127  
     public boolean isTargetInstanceOf(Class type)
 128  
     {
 129  0
         return _delegate.isTargetInstanceOf(type);
 130  
     }
 131  
 }