001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.commons.services; 014 015import java.lang.annotation.Annotation; 016 017/** 018 * A wrapper around the JavaBean Introspector that allows more manageable access to JavaBean properties of objects. 019 * 020 * Only provides access to <em>simple</em> properties. Indexed properties are ignored. 021 * 022 * Starting in Tapestry 5.2, public fields can now be accessed as if they were properly JavaBean properties. Where there 023 * is a name conflict, the true property will be favored over the field access. 024 */ 025public interface PropertyAccess 026{ 027 /** 028 * Reads the value of a property. 029 * 030 * @throws UnsupportedOperationException 031 * if the property is write only 032 * @throws IllegalArgumentException 033 * if property does not exist 034 */ 035 Object get(Object instance, String propertyName); 036 037 /** 038 * Updates the value of a property. 039 * 040 * @throws UnsupportedOperationException 041 * if the property is read only 042 * @throws IllegalArgumentException 043 * if property does not exist 044 */ 045 void set(Object instance, String propertyName, Object value); 046 047 /** 048 * Returns the annotation of a given property for the specified type if such an annotation is present, else null. 049 * A convenience over invoking {@link #getAdapter(Object)}.{@link ClassPropertyAdapter#getPropertyAdapter(String)}.{@link PropertyAdapter#getAnnotation(Class)} 050 * 051 * @param instance the object to read a value from 052 * @param propertyName the name of the property to read (case is ignored) 053 * @param annotationClass the type of annotation to return 054 * @throws IllegalArgumentException 055 * if property does not exist 056 * 057 * @since 5.4 058 */ 059 Annotation getAnnotation(Object instance, String propertyName, Class<? extends Annotation> annotationClass); 060 061 /** 062 * Returns the adapter for a particular object instance. A convienience over invoking {@link #getAdapter(Class)}. 063 */ 064 ClassPropertyAdapter getAdapter(Object instance); 065 066 /** 067 * Returns the adapter used to access properties within the indicated class. 068 */ 069 ClassPropertyAdapter getAdapter(Class forClass); 070 071 /** 072 * Discards all stored property access information, discarding all created class adapters. 073 */ 074 void clearCache(); 075}