39
40 /**
41 * The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
42 * EventSetDescriptor, and MethodDescriptor, etc.
43 * <p>
44 * It supports some common information that can be set and retrieved for
45 * any of the introspection descriptors.
46 * <p>
47 * In addition it provides an extension mechanism so that arbitrary
48 * attribute/value pairs can be associated with a design feature.
49 *
50 * @since 1.1
51 */
52
53 public class FeatureDescriptor {
54 private static final String TRANSIENT = "transient";
55
56 private Reference<? extends Class<?>> classRef;
57
58 /**
59 * Constructs a <code>FeatureDescriptor</code>.
60 */
61 public FeatureDescriptor() {
62 }
63
64 /**
65 * Gets the programmatic name of this feature.
66 *
67 * @return The programmatic name of the property/method/event
68 */
69 public String getName() {
70 return name;
71 }
72
73 /**
74 * Sets the programmatic name of this feature.
75 *
76 * @param name The programmatic name of the property/method/event
77 */
78 public void setName(String name) {
79 this.name = name;
317 return (value instanceof Boolean)
318 ? (Boolean) value
319 : false;
320 }
321
322 // Package private methods for recreating the weak/soft referent
323
324 void setClass0(Class<?> cls) {
325 this.classRef = getWeakReference(cls);
326 }
327
328 Class<?> getClass0() {
329 return (this.classRef != null)
330 ? this.classRef.get()
331 : null;
332 }
333
334 /**
335 * Creates a new soft reference that refers to the given object.
336 *
337 * @return a new soft reference or <code>null</code> if object is <code>null</code>
338 *
339 * @see SoftReference
340 */
341 static <T> Reference<T> getSoftReference(T object) {
342 return (object != null)
343 ? new SoftReference<>(object)
344 : null;
345 }
346
347 /**
348 * Creates a new weak reference that refers to the given object.
349 *
350 * @return a new weak reference or <code>null</code> if object is <code>null</code>
351 *
352 * @see WeakReference
353 */
354 static <T> Reference<T> getWeakReference(T object) {
355 return (object != null)
356 ? new WeakReference<>(object)
357 : null;
358 }
359
360 /**
361 * Resolves the return type of the method.
362 *
363 * @param base the class that contains the method in the hierarchy
364 * @param method the object that represents the method
365 * @return a class identifying the return type of the method
366 *
367 * @see Method#getGenericReturnType
368 * @see Method#getReturnType
369 */
370 static Class<?> getReturnType(Class<?> base, Method method) {
|
39
40 /**
41 * The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
42 * EventSetDescriptor, and MethodDescriptor, etc.
43 * <p>
44 * It supports some common information that can be set and retrieved for
45 * any of the introspection descriptors.
46 * <p>
47 * In addition it provides an extension mechanism so that arbitrary
48 * attribute/value pairs can be associated with a design feature.
49 *
50 * @since 1.1
51 */
52
53 public class FeatureDescriptor {
54 private static final String TRANSIENT = "transient";
55
56 private Reference<? extends Class<?>> classRef;
57
58 /**
59 * Constructs a {@code FeatureDescriptor}.
60 */
61 public FeatureDescriptor() {
62 }
63
64 /**
65 * Gets the programmatic name of this feature.
66 *
67 * @return The programmatic name of the property/method/event
68 */
69 public String getName() {
70 return name;
71 }
72
73 /**
74 * Sets the programmatic name of this feature.
75 *
76 * @param name The programmatic name of the property/method/event
77 */
78 public void setName(String name) {
79 this.name = name;
317 return (value instanceof Boolean)
318 ? (Boolean) value
319 : false;
320 }
321
322 // Package private methods for recreating the weak/soft referent
323
324 void setClass0(Class<?> cls) {
325 this.classRef = getWeakReference(cls);
326 }
327
328 Class<?> getClass0() {
329 return (this.classRef != null)
330 ? this.classRef.get()
331 : null;
332 }
333
334 /**
335 * Creates a new soft reference that refers to the given object.
336 *
337 * @return a new soft reference or {@code null} if object is {@code null}
338 *
339 * @see SoftReference
340 */
341 static <T> Reference<T> getSoftReference(T object) {
342 return (object != null)
343 ? new SoftReference<>(object)
344 : null;
345 }
346
347 /**
348 * Creates a new weak reference that refers to the given object.
349 *
350 * @return a new weak reference or {@code null} if object is {@code null}
351 *
352 * @see WeakReference
353 */
354 static <T> Reference<T> getWeakReference(T object) {
355 return (object != null)
356 ? new WeakReference<>(object)
357 : null;
358 }
359
360 /**
361 * Resolves the return type of the method.
362 *
363 * @param base the class that contains the method in the hierarchy
364 * @param method the object that represents the method
365 * @return a class identifying the return type of the method
366 *
367 * @see Method#getGenericReturnType
368 * @see Method#getReturnType
369 */
370 static Class<?> getReturnType(Class<?> base, Method method) {
|