01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.util;
28:
29: import java.beans.BeanDescriptor;
30: import java.beans.BeanInfo;
31: import java.beans.EventSetDescriptor;
32: import java.beans.IntrospectionException;
33: import java.beans.MethodDescriptor;
34: import java.beans.PropertyDescriptor;
35: import java.util.ArrayList;
36: import java.util.Collection;
37:
38: /** A useful base class which allows an object to be it's own BeanInfo
39: * class. The defaults just implement the BeanInfo interface with
40: * null return values except that we also provides a simple API for
41: * recursive construction of PropertyDescriptor arrays.
42: **/
43:
44: public class SelfDescribingBeanInfo implements BeanInfo {
45: public BeanDescriptor getBeanDescriptor() {
46: return null;
47: }
48:
49: public int getDefaultPropertyIndex() {
50: return -1;
51: }
52:
53: public EventSetDescriptor[] getEventSetDescriptors() {
54: return null;
55: }
56:
57: public int getDefaultEventIndex() {
58: return -1;
59: }
60:
61: public MethodDescriptor[] getMethodDescriptors() {
62: return null;
63: }
64:
65: public BeanInfo[] getAdditionalBeanInfo() {
66: return null;
67: }
68:
69: public java.awt.Image getIcon(int iconKind) {
70: return null;
71: }
72:
73: private static final PropertyDescriptor[] _emptyPD = new PropertyDescriptor[0];
74:
75: public PropertyDescriptor[] getPropertyDescriptors() {
76: Collection pds = new ArrayList();
77: try {
78: addPropertyDescriptors(pds);
79: } catch (IntrospectionException ie) {
80: System.err
81: .println("Warning: Caught exception while introspecting on "
82: + this .getClass());
83: ie.printStackTrace();
84: }
85: return (PropertyDescriptor[]) pds.toArray(_emptyPD);
86: }
87:
88: /** Override this to add class-local PropertyDescriptor instances
89: * to the collection c. Make sure that overridden methods call super
90: * as appropriate.
91: **/
92: protected void addPropertyDescriptors(Collection c)
93: throws IntrospectionException {
94: }
95:
96: }
|