01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.tapestry.ioc.services;
16:
17: import java.lang.annotation.Annotation;
18: import java.lang.reflect.Method;
19:
20: /**
21: * Provides access to a single property within a class.
22: *
23: * @see org.apache.tapestry.ioc.services.ClassPropertyAdapter
24: */
25: public interface PropertyAdapter {
26: /**
27: * Returns the name of the property.
28: */
29: String getName();
30:
31: /**
32: * Returns true if the property is readable (i.e., has a getter method).
33: */
34: boolean isRead();
35:
36: /**
37: * Returns the method used to read the property, or null if the property is not readable.
38: */
39: public Method getReadMethod();
40:
41: /**
42: * Returns true if the property is writeable (i.e., has a setter method).
43: */
44: boolean isUpdate();
45:
46: /**
47: * Returns the method used to update the property, or null if the property is not writeable.
48: */
49: public Method getWriteMethod();
50:
51: /**
52: * Reads the property value.
53: *
54: * @param instance
55: * to read from
56: * @throws UnsupportedOperationException
57: * if the property is write only
58: */
59: Object get(Object instance);
60:
61: /**
62: * Updates the property value. The provided value must not be null if the property type is
63: * primitive, and must otherwise be of the proper type.
64: *
65: * @param instance
66: * to update
67: * @param value
68: * new value for the property
69: * @throws UnsupportedOperationException
70: * if the property is read only
71: */
72: void set(Object instance, Object value);
73:
74: /**
75: * Returns the type of the property.
76: */
77: Class getType();
78:
79: /**
80: * Returns an annotation on the property. The read method (if present) is checked first,
81: * followed by the write method.
82: *
83: * @param <T>
84: * @param annotationClass
85: * the annotation to retrieve
86: * @return the annotation on the read or write method, or null if not present on either method
87: */
88: <T extends Annotation> T getAnnotation(Class<T> annotationClass);
89: }
|