1 5 package org.hibernate.property; 6 7 import org.hibernate.PropertyAccessException; 8 import org.hibernate.PropertyNotFoundException; 9 10 14 public class ChainedPropertyAccessor implements PropertyAccessor { 15 16 final PropertyAccessor[] chain; 17 18 public ChainedPropertyAccessor(PropertyAccessor[] chain) { 19 this.chain = chain; 20 } 21 22 public Getter getGetter(Class theClass, String propertyName) 23 throws PropertyNotFoundException { 24 Getter result = null; 25 for (int i = 0; i < chain.length; i++) { 26 PropertyAccessor candidate = chain[i]; 27 try { 28 result = candidate.getGetter(theClass, propertyName); 29 return result; 30 } catch (PropertyNotFoundException pnfe) { 31 } 33 } 34 throw new PropertyNotFoundException("Could not find Getter "); 35 } 36 37 public Setter getSetter(Class theClass, String propertyName) 38 throws PropertyNotFoundException { 39 Setter result = null; 40 for (int i = 0; i < chain.length; i++) { 41 PropertyAccessor candidate = chain[i]; 42 try { 43 result = candidate.getSetter(theClass, propertyName); 44 return result; 45 } catch (PropertyNotFoundException pnfe) { 46 } 48 } 49 throw new PropertyAccessException(null, "could not find a property " , false, theClass, propertyName); 50 } 51 52 } 53 | Popular Tags |