View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.beanutils;
18  
19  import java.beans.PropertyDescriptor;
20  import java.util.Set;
21  
22  /**
23   * <p>
24   * A context interface used during introspection for querying and setting
25   * property descriptors.
26   * </p>
27   * <p>
28   * An implementation of this interface is passed to {@link BeanIntrospector}
29   * objects during processing of a bean class. It allows the
30   * {@code BeanIntrospector} to deliver descriptors for properties it has
31   * detected. It is also possible to find out which properties have already been
32   * found by another {@code BeanIntrospector}; this allows multiple
33   * {@code BeanIntrospector} instances to collaborate.
34   * </p>
35   *
36   * @version $Id$
37   * @since 1.9
38   */
39  public interface IntrospectionContext {
40      /**
41       * Returns the class that is subject of introspection.
42       *
43       * @return the current class
44       */
45      Class<?> getTargetClass();
46  
47      /**
48       * Adds the given property descriptor to this context. This method is called
49       * by a {@code BeanIntrospector} during introspection for each detected
50       * property. If this context already contains a descriptor for the affected
51       * property, it is overridden.
52       *
53       * @param desc the property descriptor
54       */
55      void addPropertyDescriptor(PropertyDescriptor desc);
56  
57      /**
58       * Adds an array of property descriptors to this context. Using this method
59       * multiple descriptors can be added at once.
60       *
61       * @param descriptors the array of descriptors to be added
62       */
63      void addPropertyDescriptors(PropertyDescriptor[] descriptors);
64  
65      /**
66       * Tests whether a descriptor for the property with the given name is
67       * already contained in this context. This method can be used for instance
68       * to prevent that an already existing property descriptor is overridden.
69       *
70       * @param name the name of the property in question
71       * @return <b>true</b> if a descriptor for this property has already been
72       *         added, <b>false</b> otherwise
73       */
74      boolean hasProperty(String name);
75  
76      /**
77       * Returns the descriptor for the property with the given name or
78       * <b>null</b> if this property is unknown.
79       *
80       * @param name the name of the property in question
81       * @return the descriptor for this property or <b>null</b> if this property
82       *         is unknown
83       */
84      PropertyDescriptor getPropertyDescriptor(String name);
85  
86      /**
87       * Removes the descriptor for the property with the given name.
88       *
89       * @param name the name of the affected property
90       */
91      void removePropertyDescriptor(String name);
92  
93      /**
94       * Returns a set with the names of all properties known to this context.
95       *
96       * @return a set with the known property names
97       */
98      Set<String> propertyNames();
99  }