Coverage Report - org.apache.myfaces.view.facelets.tag.MetadataTargetImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MetadataTargetImpl
0%
0/21
0%
0/8
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;
 20  
 
 21  
 import java.beans.IntrospectionException;
 22  
 import java.beans.Introspector;
 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.faces.view.facelets.MetadataTarget;
 29  
 
 30  
 /**
 31  
  * 
 32  
  * @author Jacob Hookom
 33  
  * @version $Id$
 34  
  */
 35  
 public final class MetadataTargetImpl extends MetadataTarget
 36  
 {
 37  
     private final Map<String, PropertyDescriptor> _pd;
 38  
     
 39  
     private final Class<?> _type;
 40  
 
 41  
     public MetadataTargetImpl(Class<?> type) throws IntrospectionException
 42  0
     {
 43  0
         _type = type;
 44  
         
 45  0
         _pd = new HashMap<String, PropertyDescriptor>();
 46  0
         for (PropertyDescriptor descriptor : Introspector.getBeanInfo(type).getPropertyDescriptors())
 47  
         {
 48  0
             _pd.put(descriptor.getName(), descriptor);
 49  
         }
 50  0
     }
 51  
 
 52  
     public PropertyDescriptor getProperty(String name)
 53  
     {
 54  0
         return _pd.get(name);
 55  
     }
 56  
 
 57  
     public Class<?> getPropertyType(String name)
 58  
     {
 59  0
         PropertyDescriptor pd = getProperty(name);
 60  0
         if (pd != null)
 61  
         {
 62  0
             return pd.getPropertyType();
 63  
         }
 64  
         
 65  0
         return null;
 66  
     }
 67  
 
 68  
     public Method getReadMethod(String name)
 69  
     {
 70  0
         PropertyDescriptor pd = getProperty(name);
 71  0
         if (pd != null)
 72  
         {
 73  0
             return pd.getReadMethod();
 74  
         }
 75  
         
 76  0
         return null;
 77  
     }
 78  
 
 79  
     public Class<?> getTargetClass()
 80  
     {
 81  0
         return _type;
 82  
     }
 83  
 
 84  
     public Method getWriteMethod(String name)
 85  
     {
 86  0
         PropertyDescriptor pd = getProperty(name);
 87  0
         if (pd != null)
 88  
         {
 89  0
             return pd.getWriteMethod();
 90  
         }
 91  
         
 92  0
         return null;
 93  
     }
 94  
 
 95  
     public boolean isTargetInstanceOf(Class type)
 96  
     {
 97  0
         return type.isAssignableFrom(_type);
 98  
     }
 99  
 }