    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.ioc.services;
    014
    015import java.lang.annotation.Annotation;
    016import java.util.List;
    017
    018/**
    019 * Organizes all {@link org.apache.tapestry5.ioc.services.PropertyAdapter}s for a particular class.
    020 *
    021 * Only provides access to <em>simple</em> properties. Indexed properties are ignored.
    022 *
    023 * When accessing properties by name, the case of the name is ignored.
    024 */
    025public interface ClassPropertyAdapter
    026{
    027    /**
    028     * Returns the names of all properties, sorted into alphabetic order. This includes true properties
    029     * (as defined in the JavaBeans specification), but also public fields. Starting in Tapestry 5.3, even public static fields are included.
    030     */
    031    List<String> getPropertyNames();
    032
    033    /**
    034     * Returns the type of bean this adapter provides properties for.
    035     */
    036    Class getBeanType();
    037
    038    /**
    039     * Returns the property adapter with the given name, or null if no such adapter exists.
    040     *
    041     * @param name of the property (case is ignored)
    042     */
    043    PropertyAdapter getPropertyAdapter(String name);
    044
    045    /**
    046     * Reads the value of a property.
    047     *
    048     * @param instance     the object to read a value from
    049     * @param propertyName the name of the property to read (case is ignored)
    050     * @throws UnsupportedOperationException if the property is write only
    051     * @throws IllegalArgumentException      if property does not exist
    052     */
    053    Object get(Object instance, String propertyName);
    054
    055    /**
    056     * Updates the value of a property.
    057     *
    058     * @param instance     the object to update
    059     * @param propertyName the name of the property to update (case is ignored)
    060     * @throws UnsupportedOperationException if the property is read only
    061     * @throws IllegalArgumentException      if property does not exist
    062     */
    063    void set(Object instance, String propertyName, Object value);
    064
    065    /**
    066     * Returns the annotation of a given property for the specified type if such an annotation is present, else null.
    067     *
    068     * @param instance     the object to read a value from
    069     * @param propertyName the name of the property to read (case is ignored)
    070     * @param annotationClass the type of annotation to return
    071     *
    072     * @throws IllegalArgumentException      if property does not exist
    073     *
    074     * @since 5.4
    075     */
    076    Annotation getAnnotation(Object instance, String propertyName, Class<? extends Annotation> annotationClass);
    077}