| 1 | /* gnu.java.beans.BeanInfoEmbryo
|
|---|
| 2 | Copyright (C) 1998, 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 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.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package gnu.java.beans;
|
|---|
| 40 |
|
|---|
| 41 | import java.beans.*;
|
|---|
| 42 | import java.util.*;
|
|---|
| 43 | import gnu.java.lang.*;
|
|---|
| 44 | import java.lang.reflect.*;
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | ** A BeanInfoEmbryo accumulates information about a Bean
|
|---|
| 48 | ** while it is in the process of being created, and then
|
|---|
| 49 | ** when you are done accumulating the information, the
|
|---|
| 50 | ** getBeanInfo() method may be called to create a BeanInfo
|
|---|
| 51 | ** object based on the information.<P>
|
|---|
| 52 | **
|
|---|
| 53 | ** This class is not well-synchronized. (It can be, it
|
|---|
| 54 | ** just isn't yet.)
|
|---|
| 55 | **
|
|---|
| 56 | ** @author John Keiser
|
|---|
| 57 | ** @version 1.1.0, 30 Jul 1998
|
|---|
| 58 | ** @see java.beans.BeanInfo
|
|---|
| 59 | **/
|
|---|
| 60 |
|
|---|
| 61 | public class BeanInfoEmbryo {
|
|---|
| 62 | Hashtable properties = new Hashtable();
|
|---|
| 63 | Hashtable events = new Hashtable();
|
|---|
| 64 | Vector methods = new Vector();
|
|---|
| 65 |
|
|---|
| 66 | BeanDescriptor beanDescriptor;
|
|---|
| 67 | BeanInfo[] additionalBeanInfo;
|
|---|
| 68 | java.awt.Image[] im;
|
|---|
| 69 | String defaultPropertyName;
|
|---|
| 70 | String defaultEventName;
|
|---|
| 71 |
|
|---|
| 72 | public BeanInfoEmbryo() {
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | public BeanInfo getBeanInfo() {
|
|---|
| 76 | int defaultProperty = -1;
|
|---|
| 77 | int defaultEvent = -1;
|
|---|
| 78 |
|
|---|
| 79 | PropertyDescriptor[] Aproperties = new PropertyDescriptor[properties.size()];
|
|---|
| 80 | int i = 0;
|
|---|
| 81 | Enumeration enum = properties.elements();
|
|---|
| 82 | while(enum.hasMoreElements()) {
|
|---|
| 83 | Aproperties[i] = (PropertyDescriptor)enum.nextElement();
|
|---|
| 84 | if(defaultPropertyName != null && Aproperties[i].getName().equals(defaultPropertyName)) {
|
|---|
| 85 | defaultProperty = i;
|
|---|
| 86 | }
|
|---|
| 87 | i++;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | EventSetDescriptor[] Aevents = new EventSetDescriptor[events.size()];
|
|---|
| 91 | i = 0;
|
|---|
| 92 | enum = events.elements();
|
|---|
| 93 | while(enum.hasMoreElements()) {
|
|---|
| 94 | Aevents[i] = (EventSetDescriptor)enum.nextElement();
|
|---|
| 95 | if(defaultEventName != null && Aevents[i].getName().equals(defaultEventName)) {
|
|---|
| 96 | defaultEvent = i;
|
|---|
| 97 | }
|
|---|
| 98 | i++;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | MethodDescriptor[] Amethods = new MethodDescriptor[methods.size()];
|
|---|
| 102 | methods.copyInto(Amethods);
|
|---|
| 103 |
|
|---|
| 104 | return new ExplicitBeanInfo(beanDescriptor,additionalBeanInfo,Aproperties,defaultProperty,Aevents,defaultEvent,Amethods,im);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | public void setBeanDescriptor(BeanDescriptor b) {
|
|---|
| 108 | beanDescriptor = b;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | public void setAdditionalBeanInfo(BeanInfo[] b) {
|
|---|
| 112 | additionalBeanInfo = b;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | public boolean hasProperty(PropertyDescriptor p) {
|
|---|
| 116 | return properties.get(p.getName()) != null;
|
|---|
| 117 | }
|
|---|
| 118 | public void addProperty(PropertyDescriptor p) {
|
|---|
| 119 | properties.put(p.getName(),p);
|
|---|
| 120 | }
|
|---|
| 121 | public void addIndexedProperty(IndexedPropertyDescriptor p) {
|
|---|
| 122 | properties.put(p.getName(),p);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | public boolean hasEvent(EventSetDescriptor e) {
|
|---|
| 126 | return events.get(e.getName()) != null;
|
|---|
| 127 | }
|
|---|
| 128 | public void addEvent(EventSetDescriptor e) {
|
|---|
| 129 | events.put(e.getName(),e);
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | public boolean hasMethod(MethodDescriptor m) {
|
|---|
| 133 | for(int i=0;i<methods.size();i++) {
|
|---|
| 134 | Method thisMethod = ((MethodDescriptor)methods.elementAt(i)).getMethod();
|
|---|
| 135 | if(m.getMethod().getName().equals(thisMethod.getName())
|
|---|
| 136 | && Arrays.equals(m.getMethod().getParameterTypes(),
|
|---|
| 137 | thisMethod.getParameterTypes())) {
|
|---|
| 138 | return true;
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | return false;
|
|---|
| 142 | }
|
|---|
| 143 | public void addMethod(MethodDescriptor m) {
|
|---|
| 144 | methods.addElement(m);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | public void setDefaultPropertyName(String defaultPropertyName) {
|
|---|
| 148 | this.defaultPropertyName = defaultPropertyName;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | public void setDefaultEventName(String defaultEventName) {
|
|---|
| 152 | this.defaultEventName = defaultEventName;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | public void setIcons(java.awt.Image[] im) {
|
|---|
| 156 | this.im = im;
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|