    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.beanutils2;
    018
    019import java.beans.PropertyDescriptor;
    020import java.util.Set;
    021
    022/**
    023 * <p>
    024 * A context interface used during introspection for querying and setting property descriptors.
    025 * </p>
    026 * <p>
    027 * An implementation of this interface is passed to {@link BeanIntrospector} objects during processing of a bean class. It allows the {@code BeanIntrospector}
    028 * to deliver descriptors for properties it has detected. It is also possible to find out which properties have already been found by another
    029 * {@code BeanIntrospector}; this allows multiple {@code BeanIntrospector} instances to collaborate.
    030 * </p>
    031 *
    032 * @since 1.9
    033 */
    034public interface IntrospectionContext {
    035
    036    /**
    037     * Adds the given property descriptor to this context. This method is called by a {@code BeanIntrospector} during introspection for each detected property.
    038     * If this context already contains a descriptor for the affected property, it is overridden.
    039     *
    040     * @param desc the property descriptor
    041     */
    042    void addPropertyDescriptor(PropertyDescriptor desc);
    043
    044    /**
    045     * Adds an array of property descriptors to this context. Using this method multiple descriptors can be added at once.
    046     *
    047     * @param descriptors the array of descriptors to be added
    048     */
    049    void addPropertyDescriptors(PropertyDescriptor[] descriptors);
    050
    051    /**
    052     * Returns the descriptor for the property with the given name or <strong>null</strong> if this property is unknown.
    053     *
    054     * @param name the name of the property in question
    055     * @return the descriptor for this property or <strong>null</strong> if this property is unknown
    056     */
    057    PropertyDescriptor getPropertyDescriptor(String name);
    058
    059    /**
    060     * Returns the class that is subject of introspection.
    061     *
    062     * @return the current class
    063     */
    064    Class<?> getTargetClass();
    065
    066    /**
    067     * Tests whether a descriptor for the property with the given name is already contained in this context. This method can be used for instance to prevent
    068     * that an already existing property descriptor is overridden.
    069     *
    070     * @param name the name of the property in question
    071     * @return <strong>true</strong> if a descriptor for this property has already been added, <strong>false</strong> otherwise
    072     */
    073    boolean hasProperty(String name);
    074
    075    /**
    076     * Returns a set with the names of all properties known to this context.
    077     *
    078     * @return a set with the known property names
    079     */
    080    Set<String> propertyNames();
    081
    082    /**
    083     * Removes the descriptor for the property with the given name.
    084     *
    085     * @param name the name of the affected property
    086     */
    087    void removePropertyDescriptor(String name);
    088}