Coverage Report - javax.faces.component._PropertyDescriptorHolder
 
Classes in this File Line Coverage Branch Coverage Complexity
_PropertyDescriptorHolder
57%
11/19
33%
2/6
1.5
 
 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 javax.faces.component;
 20  
 
 21  
 import java.beans.PropertyDescriptor;
 22  
 import java.lang.ref.Reference;
 23  
 import java.lang.ref.SoftReference;
 24  
 import java.lang.reflect.Method;
 25  
 
 26  
 class _PropertyDescriptorHolder
 27  
 {
 28  
     private final PropertyDescriptor _descriptor;
 29  
     private Reference<Method> _readMethodRef;
 30  
     private Reference<Method> _writeMethodRef;
 31  
 
 32  
     public _PropertyDescriptorHolder(PropertyDescriptor descriptor)
 33  0
     {
 34  0
         _descriptor = descriptor;
 35  0
         _readMethodRef = new SoftReference<Method>(_descriptor.getReadMethod());
 36  0
     }
 37  
 
 38  
     public _PropertyDescriptorHolder(PropertyDescriptor descriptor, Method readMethod)
 39  726
     {
 40  726
         _descriptor = descriptor;
 41  726
         _readMethodRef = new SoftReference<Method>(readMethod);
 42  726
     }
 43  
     
 44  
     public String getName()
 45  
     {
 46  0
         return _descriptor.getName();
 47  
     }
 48  
     
 49  
     public Method getReadMethod()
 50  
     {
 51  14
         Method readMethod = _readMethodRef.get();
 52  14
         if (readMethod == null)
 53  
         {
 54  0
             readMethod = _descriptor.getReadMethod();
 55  0
             _readMethodRef = new SoftReference<Method>(readMethod);
 56  
         }
 57  14
         return readMethod;
 58  
     }
 59  
     
 60  
     public Method getWriteMethod()
 61  
     {
 62  4
         if (_writeMethodRef == null || _writeMethodRef.get() == null)
 63  
         {
 64  
             // In facelets, the Method instance used to write the variable is stored
 65  
             // in a variable (see org.apache.myfaces.view.facelets.tag.BeanPropertyTagRule),
 66  
             // so the impact of this synchronized call at the end is minimal compared with 
 67  
             // getReadMethod. That's the reason why cache it here in a lazy way is enough
 68  
             // instead retrieve it as soon as this holder is created.
 69  4
             Method writeMethod = _descriptor.getWriteMethod();
 70  4
             _writeMethodRef = new SoftReference<Method>(writeMethod);
 71  
         }
 72  4
         return _writeMethodRef.get();
 73  
     }
 74  
     
 75  
     public PropertyDescriptor getPropertyDescriptor()
 76  
     {
 77  0
         return _descriptor;
 78  
     }
 79  
 }