Coverage Report - org.apache.tapestry5.internal.bindings.PropBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
PropBinding
100%
18/18
100%
2/2
0
 
 1  
 // Copyright 2006, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.internal.bindings;
 16  
 
 17  
 import org.apache.tapestry5.PropertyConduit;
 18  
 import org.apache.tapestry5.internal.services.Invariant;
 19  
 import org.apache.tapestry5.ioc.Location;
 20  
 import org.apache.tapestry5.ioc.internal.util.TapestryException;
 21  
 
 22  
 import java.lang.annotation.Annotation;
 23  
 
 24  
 /**
 25  
  * Base class for bindings created by the {@link org.apache.tapestry5.internal.bindings.PropBindingFactory}. A subclass
 26  
  * of this is created at runtime.
 27  
  */
 28  
 public class PropBinding extends AbstractBinding
 29  
 {
 30  
     private final Object root;
 31  
 
 32  
     private final PropertyConduit conduit;
 33  
 
 34  
     private final String toString;
 35  
 
 36  
     private boolean invariant;
 37  
 
 38  
     public PropBinding(final Location location, final Object root, final PropertyConduit conduit, final String toString
 39  
     )
 40  
     {
 41  7077
         super(location);
 42  
 
 43  7077
         this.root = root;
 44  7077
         this.conduit = conduit;
 45  7077
         this.toString = toString;
 46  
 
 47  7077
         invariant = conduit.getAnnotation(Invariant.class) != null;
 48  7077
     }
 49  
 
 50  
     /**
 51  
      * The default implementation of get() will throw a TapestryException (binding is write only). The fabricated
 52  
      * subclass <em>may</em> override this method (as well as set()).
 53  
      */
 54  
     public Object get()
 55  
     {
 56  
         try
 57  
         {
 58  208123
             return conduit.get(root);
 59  
         }
 60  4
         catch (Exception ex)
 61  
         {
 62  4
             throw new TapestryException(ex.getMessage(), getLocation(), ex);
 63  
         }
 64  
     }
 65  
 
 66  
     @Override
 67  
     public void set(Object value)
 68  
     {
 69  
         try
 70  
         {
 71  77704
             conduit.set(root, value);
 72  
         }
 73  4
         catch (Exception ex)
 74  
         {
 75  4
             throw new TapestryException(ex.getMessage(), getLocation(), ex);
 76  77700
         }
 77  77700
     }
 78  
 
 79  
     @Override
 80  
     public String toString()
 81  
     {
 82  6
         return toString;
 83  
     }
 84  
 
 85  
     /**
 86  
      * Almost always returns false, unless the conduit provides the {@link org.apache.tapestry5.internal.services.Invariant}
 87  
      * annotation.
 88  
      */
 89  
     @Override
 90  
     public boolean isInvariant()
 91  
     {
 92  293295
         return invariant;
 93  
     }
 94  
 
 95  
     @Override
 96  
     public Class getBindingType()
 97  
     {
 98  78248
         return conduit.getPropertyType();
 99  
     }
 100  
 
 101  
     @Override
 102  
     public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
 103  
     {
 104  488
         return conduit.getAnnotation(annotationClass);
 105  
     }
 106  
 }