KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > property > ChainedPropertyAccessor


1 /*
2  * Created on 28-Jan-2005
3  *
4  */

5 package org.hibernate.property;
6
7 import org.hibernate.PropertyAccessException;
8 import org.hibernate.PropertyNotFoundException;
9
10 /**
11  * @author max
12  *
13  */

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 JavaDoc theClass, String JavaDoc 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                 // ignore
32
}
33         }
34         throw new PropertyNotFoundException("Could not find Getter ");
35     }
36
37     public Setter getSetter(Class JavaDoc theClass, String JavaDoc 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                 //
47
}
48         }
49         throw new PropertyAccessException(null, "could not find a property " , false, theClass, propertyName);
50     }
51
52 }
53
Popular Tags