Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / gnu / java / beans / BeanInfoEmbryo.java
blob7c60e7cd39b1bbb0881002e006fce86bc1db027e
1 /* gnu.java.beans.BeanInfoEmbryo
2 Copyright (C) 1998, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.beans;
41 import java.beans.BeanDescriptor;
42 import java.beans.BeanInfo;
43 import java.beans.EventSetDescriptor;
44 import java.beans.IndexedPropertyDescriptor;
45 import java.beans.MethodDescriptor;
46 import java.beans.PropertyDescriptor;
47 import java.lang.reflect.Method;
48 import java.util.Arrays;
49 import java.util.Enumeration;
50 import java.util.Hashtable;
51 import java.util.Iterator;
52 import java.util.Map;
53 import java.util.TreeMap;
54 import java.util.Vector;
56 /**
57 ** A BeanInfoEmbryo accumulates information about a Bean
58 ** while it is in the process of being created, and then
59 ** when you are done accumulating the information, the
60 ** getBeanInfo() method may be called to create a BeanInfo
61 ** object based on the information.<P>
63 ** This class is not well-synchronized. (It can be, it
64 ** just isn't yet.)
66 ** @author John Keiser
67 ** @version 1.1.0, 30 Jul 1998
68 ** @see java.beans.BeanInfo
69 **/
71 public class BeanInfoEmbryo {
73 // by using a TreeMap the properties will be sorted alphabetically by name
74 // which matches the (undocumented) behavior of jdk
75 TreeMap properties = new TreeMap();
76 Hashtable events = new Hashtable();
77 Vector methods = new Vector();
79 BeanDescriptor beanDescriptor;
80 BeanInfo[] additionalBeanInfo;
81 java.awt.Image[] im;
82 String defaultPropertyName;
83 String defaultEventName;
85 public BeanInfoEmbryo() {
88 public BeanInfo getBeanInfo() {
89 int defaultProperty = -1;
90 int defaultEvent = -1;
92 PropertyDescriptor[] Aproperties = new PropertyDescriptor[properties.size()];
93 int i = 0;
94 Iterator it = properties.entrySet().iterator();
95 while (it.hasNext()) {
96 Aproperties[i] = (PropertyDescriptor) (((Map.Entry)it.next()).getValue());
97 if(defaultPropertyName != null && Aproperties[i].getName().equals(defaultPropertyName)) {
98 defaultProperty = i;
100 i++;
103 EventSetDescriptor[] Aevents = new EventSetDescriptor[events.size()];
104 i = 0;
105 Enumeration e = events.elements();
106 while (e.hasMoreElements()) {
107 Aevents[i] = (EventSetDescriptor) e.nextElement();
108 if(defaultEventName != null && Aevents[i].getName().equals(defaultEventName)) {
109 defaultEvent = i;
111 i++;
114 MethodDescriptor[] Amethods = new MethodDescriptor[methods.size()];
115 methods.copyInto(Amethods);
117 return new ExplicitBeanInfo(beanDescriptor,additionalBeanInfo,Aproperties,defaultProperty,Aevents,defaultEvent,Amethods,im);
120 public void setBeanDescriptor(BeanDescriptor b) {
121 beanDescriptor = b;
124 public void setAdditionalBeanInfo(BeanInfo[] b) {
125 additionalBeanInfo = b;
128 public boolean hasProperty(PropertyDescriptor p) {
129 return properties.get(p.getName()) != null;
131 public void addProperty(PropertyDescriptor p) {
132 properties.put(p.getName(),p);
134 public void addIndexedProperty(IndexedPropertyDescriptor p) {
135 properties.put(p.getName(),p);
138 public boolean hasEvent(EventSetDescriptor e) {
139 return events.get(e.getName()) != null;
141 public void addEvent(EventSetDescriptor e) {
142 events.put(e.getName(),e);
145 public boolean hasMethod(MethodDescriptor m) {
146 for(int i=0;i<methods.size();i++) {
147 Method thisMethod = ((MethodDescriptor)methods.elementAt(i)).getMethod();
148 if(m.getMethod().getName().equals(thisMethod.getName())
149 && Arrays.equals(m.getMethod().getParameterTypes(),
150 thisMethod.getParameterTypes())) {
151 return true;
154 return false;
156 public void addMethod(MethodDescriptor m) {
157 methods.addElement(m);
160 public void setDefaultPropertyName(String defaultPropertyName) {
161 this.defaultPropertyName = defaultPropertyName;
164 public void setDefaultEventName(String defaultEventName) {
165 this.defaultEventName = defaultEventName;
168 public void setIcons(java.awt.Image[] im) {
169 this.im = im;