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 * https://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.beanutils2;
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 property descriptors.
25 * </p>
26 * <p>
27 * An implementation of this interface is passed to {@link BeanIntrospector} objects during processing of a bean class. It allows the {@code BeanIntrospector}
28 * to deliver descriptors for properties it has detected. It is also possible to find out which properties have already been found by another
29 * {@code BeanIntrospector}; this allows multiple {@code BeanIntrospector} instances to collaborate.
30 * </p>
31 *
32 * @since 1.9
33 */
34 public interface IntrospectionContext {
35
36 /**
37 * Adds the given property descriptor to this context. This method is called by a {@code BeanIntrospector} during introspection for each detected property.
38 * If this context already contains a descriptor for the affected property, it is overridden.
39 *
40 * @param desc the property descriptor
41 */
42 void addPropertyDescriptor(PropertyDescriptor desc);
43
44 /**
45 * Adds an array of property descriptors to this context. Using this method multiple descriptors can be added at once.
46 *
47 * @param descriptors the array of descriptors to be added
48 */
49 void addPropertyDescriptors(PropertyDescriptor[] descriptors);
50
51 /**
52 * Returns the descriptor for the property with the given name or <strong>null</strong> if this property is unknown.
53 *
54 * @param name the name of the property in question
55 * @return the descriptor for this property or <strong>null</strong> if this property is unknown
56 */
57 PropertyDescriptor getPropertyDescriptor(String name);
58
59 /**
60 * Returns the class that is subject of introspection.
61 *
62 * @return the current class
63 */
64 Class<?> getTargetClass();
65
66 /**
67 * 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
68 * that an already existing property descriptor is overridden.
69 *
70 * @param name the name of the property in question
71 * @return <strong>true</strong> if a descriptor for this property has already been added, <strong>false</strong> otherwise
72 */
73 boolean hasProperty(String name);
74
75 /**
76 * Returns a set with the names of all properties known to this context.
77 *
78 * @return a set with the known property names
79 */
80 Set<String> propertyNames();
81
82 /**
83 * Removes the descriptor for the property with the given name.
84 *
85 * @param name the name of the affected property
86 */
87 void removePropertyDescriptor(String name);
88 }