View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans-Common.
5    *
6    * CosyBeans-Common 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 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans-Common is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans-Common.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.components.introspection;
21  
22  /**
23   * The bean information class for com.cosylab.gui.adapters.infobus.MethodSelectionPanel.
24   * 
25   * @author <a href="mailto:miha.kadunc@cosylab.com">Miha Kadunc</a>
26   * @version $id$
27   */
28  public class MethodSelectionPanelBeanInfo extends java.beans.SimpleBeanInfo {
29  
30  /**
31   * Find the method by comparing (name & parameter size) against the methods in the class.
32   * @param aClass java.lang.Class
33   * @param methodName java.lang.String
34   * @param parameterCount int
35   * @return java.lang.reflect.Method
36   */
37  public static java.lang.reflect.Method findMethod(java.lang.Class aClass, java.lang.String methodName, int parameterCount) {
38  	try {
39  		/* Since this method attempts to find a method by getting all methods from the class,
40  	this method should only be called if getMethod cannot find the method. */
41  		java.lang.reflect.Method methods[] = aClass.getMethods();
42  		for (int index = 0; index < methods.length; index++){
43  			java.lang.reflect.Method method = methods[index];
44  			if ((method.getParameterTypes().length == parameterCount) && (method.getName().equals(methodName))) {
45  				return method;
46  			}
47  		}
48  	} catch (java.lang.Throwable exception) {
49  		return null;
50  	}
51  	return null;
52  }
53  /**
54   * Returns the BeanInfo of the superclass of this bean to inherit its features.
55   * @return java.beans.BeanInfo[]
56   * @see java.beans.BeanInfo#getAdditionalBeanInfo()
57   */
58  public java.beans.BeanInfo[] getAdditionalBeanInfo() {
59  	java.lang.Class superClass;
60  	java.beans.BeanInfo superBeanInfo = null;
61  
62  	try {
63  		superClass = getBeanDescriptor().getBeanClass().getSuperclass();
64  	} catch (java.lang.Throwable exception) {
65  		return null;
66  	}
67  
68  	try {
69  		superBeanInfo = java.beans.Introspector.getBeanInfo(superClass);
70  	} catch (java.beans.IntrospectionException ie) {}
71  
72  	if (superBeanInfo != null) {
73  		java.beans.BeanInfo[] ret = new java.beans.BeanInfo[1];
74  		ret[0] = superBeanInfo;
75  		return ret;
76  	}
77  	return null;
78  }
79  /**
80   * Gets the bean class.
81   * @return java.lang.Class
82   */
83  public static java.lang.Class getBeanClass() {
84  	return com.cosylab.gui.components.introspection.MethodSelectionPanel.class;
85  }
86  /**
87   * Gets the bean class name.
88   * @return java.lang.String
89   */
90  public static java.lang.String getBeanClassName() {
91  	return "com.cosylab.gui.adapters.infobus.MethodSelectionPanel";
92  }
93  /**
94   * @return java.beans.BeanDescriptor
95   * @see java.beans.BeanInfo#getBeanDescriptor()
96   */
97  public java.beans.BeanDescriptor getBeanDescriptor() {
98  	java.beans.BeanDescriptor aDescriptor = null;
99  	try {
100 		/* Create and return the MethodSelectionPanelBeanInfo bean descriptor. */
101 		aDescriptor = new java.beans.BeanDescriptor(com.cosylab.gui.components.introspection.MethodSelectionPanel.class);
102 		/* aDescriptor.setExpert(false); */
103 		/* aDescriptor.setHidden(false); */
104 		/* aDescriptor.setValue("hidden-state", Boolean.FALSE); */
105 	} catch (Throwable exception) {
106 	};
107 	return aDescriptor;
108 }
109 /**
110  * Return the event set descriptors for this bean.
111  * @return java.beans.EventSetDescriptor[]
112  * @see java.beans.BeanInfo#getEventSetDescriptors()
113  */
114 public java.beans.EventSetDescriptor[] getEventSetDescriptors() {
115 	try {
116 		java.beans.EventSetDescriptor aDescriptorList[] = {};
117 		return aDescriptorList;
118 	} catch (Throwable exception) {
119 		handleException(exception);
120 	};
121 	return null;
122 }
123 /**
124  * Return the method descriptors for this bean.
125  * @return java.beans.MethodDescriptor[]
126  * @see java.beans.BeanInfo#getMethodDescriptors()
127  */
128 public java.beans.MethodDescriptor[] getMethodDescriptors() {
129 	try {
130 		java.beans.MethodDescriptor aDescriptorList[] = {
131 			main_javalangString__MethodDescriptor()
132 		};
133 		return aDescriptorList;
134 	} catch (Throwable exception) {
135 		handleException(exception);
136 	};
137 	return null;
138 }
139 /**
140  * Return the property descriptors for this bean.
141  * @return java.beans.PropertyDescriptor[]
142  * @see java.beans.BeanInfo#getPropertyDescriptors()
143  */
144 public java.beans.PropertyDescriptor[] getPropertyDescriptors() {
145 	try {
146 		java.beans.PropertyDescriptor aDescriptorList[] = {
147 			inspectedClassPropertyDescriptor()
148 			,memberFilterPropertyDescriptor()
149 			,modePropertyDescriptor()
150 			,selectedMemberPropertyDescriptor()
151 		};
152 		return aDescriptorList;
153 	} catch (Throwable exception) {
154 		handleException(exception);
155 	};
156 	return null;
157 }
158 /**
159  * Called whenever the bean information class throws an exception.
160  * @param exception java.lang.Throwable
161  */
162 private void handleException(java.lang.Throwable exception) {
163 
164 	/* Uncomment the following lines to print uncaught exceptions to stdout */
165 	// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
166 	// exception.printStackTrace(System.out);
167 }
168 /**
169  * Gets the inspectedClass property descriptor.
170  * @return java.beans.PropertyDescriptor
171  */
172 public java.beans.PropertyDescriptor inspectedClassPropertyDescriptor() {
173 	java.beans.PropertyDescriptor aDescriptor = null;
174 	try {
175 		try {
176 			/* Using methods via getMethod is the faster way to create the inspectedClass property descriptor. */
177 			java.lang.reflect.Method aGetMethod = null;
178 			try {
179 				/* Attempt to find the method using getMethod with parameter types. */
180 				java.lang.Class aGetMethodParameterTypes[] = {};
181 				aGetMethod = getBeanClass().getMethod("getInspectedClass", aGetMethodParameterTypes);
182 			} catch (Throwable exception) {
183 				/* Since getMethod failed, call findMethod. */
184 				handleException(exception);
185 				aGetMethod = findMethod(getBeanClass(), "getInspectedClass", 0);
186 			};
187 			java.lang.reflect.Method aSetMethod = null;
188 			try {
189 				/* Attempt to find the method using getMethod with parameter types. */
190 				java.lang.Class aSetMethodParameterTypes[] = {
191 					java.lang.Class.class
192 				};
193 				aSetMethod = getBeanClass().getMethod("setInspectedClass", aSetMethodParameterTypes);
194 			} catch (Throwable exception) {
195 				/* Since getMethod failed, call findMethod. */
196 				handleException(exception);
197 				aSetMethod = findMethod(getBeanClass(), "setInspectedClass", 1);
198 			};
199 			aDescriptor = new java.beans.PropertyDescriptor("inspectedClass"
200 			, aGetMethod, aSetMethod);
201 		} catch (Throwable exception) {
202 			/* Since we failed using methods, try creating a default property descriptor. */
203 			handleException(exception);
204 			aDescriptor = new java.beans.PropertyDescriptor("inspectedClass"
205 			, getBeanClass());
206 		};
207 		/* aDescriptor.setBound(false); */
208 		/* aDescriptor.setConstrained(false); */
209 		/* aDescriptor.setDisplayName("inspectedClass"); */
210 		aDescriptor.setShortDescription("the class that user selects methods from");
211 		/* aDescriptor.setExpert(false); */
212 		/* aDescriptor.setHidden(false); */
213 		aDescriptor.setValue("preferred", new Boolean(true));
214 		/* aDescriptor.setValue("ivjDesignTimeProperty", new Boolean(true)); */
215 	} catch (Throwable exception) {
216 		handleException(exception);
217 	};
218 	return aDescriptor;
219 }
220 /**
221  * Gets the main(java.lang.String[]) method descriptor.
222  * @return java.beans.MethodDescriptor
223  */
224 public java.beans.MethodDescriptor main_javalangString__MethodDescriptor() {
225 	java.beans.MethodDescriptor aDescriptor = null;
226 	try {
227 		/* Create and return the main(java.lang.String[]) method descriptor. */
228 		java.lang.reflect.Method aMethod = null;
229 		try {
230 			/* Attempt to find the method using getMethod with parameter types. */
231 			java.lang.Class aParameterTypes[] = {
232 				java.lang.String[].class
233 			};
234 			aMethod = getBeanClass().getMethod("main", aParameterTypes);
235 		} catch (Throwable exception) {
236 			/* Since getMethod failed, call findMethod. */
237 			handleException(exception);
238 			aMethod = findMethod(getBeanClass(), "main", 1);
239 		};
240 		try {
241 			/* Try creating the method descriptor with parameter descriptors. */
242 			java.beans.ParameterDescriptor aParameterDescriptor1 = new java.beans.ParameterDescriptor();
243 			aParameterDescriptor1.setName("arg1");
244 			aParameterDescriptor1.setDisplayName("args");
245 			java.beans.ParameterDescriptor aParameterDescriptors[] = {
246 				aParameterDescriptor1
247 			};
248 			aDescriptor = new java.beans.MethodDescriptor(aMethod, aParameterDescriptors);
249 		} catch (Throwable exception) {
250 			/* Try creating the method descriptor without parameter descriptors. */
251 			handleException(exception);
252 			aDescriptor = new java.beans.MethodDescriptor(aMethod);
253 		};
254 		/* aDescriptor.setDisplayName("main(java.lang.String[])"); */
255 		/* aDescriptor.setShortDescription("main(java.lang.String[])"); */
256 		/* aDescriptor.setExpert(false); */
257 		/* aDescriptor.setHidden(false); */
258 		/* aDescriptor.setValue("preferred", new Boolean(false)); */
259 	} catch (Throwable exception) {
260 		handleException(exception);
261 	};
262 	return aDescriptor;
263 }
264 /**
265  * Gets the mode property descriptor.
266  * @return java.beans.PropertyDescriptor
267  */
268 public java.beans.PropertyDescriptor modePropertyDescriptor() {
269 	java.beans.PropertyDescriptor aDescriptor = null;
270 	try {
271 		try {
272 			/* Using methods via getMethod is the faster way to create the mode property descriptor. */
273 			java.lang.reflect.Method aGetMethod = null;
274 			try {
275 				/* Attempt to find the method using getMethod with parameter types. */
276 				java.lang.Class aGetMethodParameterTypes[] = {};
277 				aGetMethod = getBeanClass().getMethod("getMode", aGetMethodParameterTypes);
278 			} catch (Throwable exception) {
279 				/* Since getMethod failed, call findMethod. */
280 				handleException(exception);
281 				aGetMethod = findMethod(getBeanClass(), "getMode", 0);
282 			};
283 			java.lang.reflect.Method aSetMethod = null;
284 			try {
285 				/* Attempt to find the method using getMethod with parameter types. */
286 				java.lang.Class aSetMethodParameterTypes[] = {
287 					short.class
288 				};
289 				aSetMethod = getBeanClass().getMethod("setMode", aSetMethodParameterTypes);
290 			} catch (Throwable exception) {
291 				/* Since getMethod failed, call findMethod. */
292 				handleException(exception);
293 				aSetMethod = findMethod(getBeanClass(), "setMode", 1);
294 			};
295 			aDescriptor = new java.beans.PropertyDescriptor("mode"
296 			, aGetMethod, aSetMethod);
297 		} catch (Throwable exception) {
298 			/* Since we failed using methods, try creating a default property descriptor. */
299 			handleException(exception);
300 			aDescriptor = new java.beans.PropertyDescriptor("mode"
301 			, getBeanClass());
302 		};
303 		aDescriptor.setBound(true);
304 		/* aDescriptor.setConstrained(false); */
305 		/* aDescriptor.setDisplayName("mode"); */
306 		/* aDescriptor.setShortDescription("mode"); */
307 		/* aDescriptor.setExpert(false); */
308 		/* aDescriptor.setHidden(false); */
309 		/* aDescriptor.setValue("preferred", new Boolean(false)); */
310 		/* aDescriptor.setValue("ivjDesignTimeProperty", new Boolean(true)); */
311 		aDescriptor.setValue("enumerationValues", new Object[] {
312 				"COMBO",new Short((short)0),"((short)0)",
313 				"LIST",new Short((short)1),"((short)1)",
314 		});
315 	} catch (Throwable exception) {
316 		handleException(exception);
317 	};
318 	return aDescriptor;
319 }
320 
321 /**
322  * Gets the memberFilter property descriptor.
323  * @return java.beans.PropertyDescriptor
324  */
325 public java.beans.PropertyDescriptor memberFilterPropertyDescriptor() {
326 	java.beans.PropertyDescriptor aDescriptor = null;
327 	try {
328 		try {
329 			/* Using methods via getMethod is the faster way to create the memberFilter property descriptor. */
330 			java.lang.reflect.Method aGetMethod = null;
331 			try {
332 				/* Attempt to find the method using getMethod with parameter types. */
333 				java.lang.Class aGetMethodParameterTypes[] = {};
334 				aGetMethod = getBeanClass().getMethod("getMemberFilter", aGetMethodParameterTypes);
335 			} catch (Throwable exception) {
336 				/* Since getMethod failed, call findMethod. */
337 				handleException(exception);
338 				aGetMethod = findMethod(getBeanClass(), "getMemberFilter", 0);
339 			};
340 			java.lang.reflect.Method aSetMethod = null;
341 			try {
342 				/* Attempt to find the method using getMethod with parameter types. */
343 				java.lang.Class aSetMethodParameterTypes[] = {
344 					com.cosylab.introspection.MemberFilter.class
345 				};
346 				aSetMethod = getBeanClass().getMethod("setMemberFilter", aSetMethodParameterTypes);
347 			} catch (Throwable exception) {
348 				/* Since getMethod failed, call findMethod. */
349 				handleException(exception);
350 				aSetMethod = findMethod(getBeanClass(), "setMemberFilter", 1);
351 			};
352 			aDescriptor = new java.beans.PropertyDescriptor("memberFilter"
353 			, aGetMethod, aSetMethod);
354 		} catch (Throwable exception) {
355 			/* Since we failed using methods, try creating a default property descriptor. */
356 			handleException(exception);
357 			aDescriptor = new java.beans.PropertyDescriptor("memberFilter"
358 			, getBeanClass());
359 		};
360 		/* aDescriptor.setBound(false); */
361 		/* aDescriptor.setConstrained(false); */
362 		/* aDescriptor.setDisplayName("memberFilter"); */
363 		/* aDescriptor.setShortDescription("memberFilter"); */
364 		/* aDescriptor.setExpert(false); */
365 		/* aDescriptor.setHidden(false); */
366 		/* aDescriptor.setValue("preferred", new Boolean(false)); */
367 		/* aDescriptor.setValue("ivjDesignTimeProperty", new Boolean(true)); */
368 	} catch (Throwable exception) {
369 		handleException(exception);
370 	};
371 	return aDescriptor;
372 }
373 
374 /**
375  * Gets the selectedMember property descriptor.
376  * @return java.beans.PropertyDescriptor
377  */
378 public java.beans.PropertyDescriptor selectedMemberPropertyDescriptor() {
379 	java.beans.PropertyDescriptor aDescriptor = null;
380 	try {
381 		try {
382 			/* Using methods via getMethod is the faster way to create the selectedMember property descriptor. */
383 			java.lang.reflect.Method aGetMethod = null;
384 			try {
385 				/* Attempt to find the method using getMethod with parameter types. */
386 				java.lang.Class aGetMethodParameterTypes[] = {};
387 				aGetMethod = getBeanClass().getMethod("getSelectedMember", aGetMethodParameterTypes);
388 			} catch (Throwable exception) {
389 				/* Since getMethod failed, call findMethod. */
390 				handleException(exception);
391 				aGetMethod = findMethod(getBeanClass(), "getSelectedMember", 0);
392 			};
393 			java.lang.reflect.Method aSetMethod = null;
394 			aDescriptor = new java.beans.PropertyDescriptor("selectedMember"
395 			, aGetMethod, aSetMethod);
396 		} catch (Throwable exception) {
397 			/* Since we failed using methods, try creating a default property descriptor. */
398 			handleException(exception);
399 			aDescriptor = new java.beans.PropertyDescriptor("selectedMember"
400 			, getBeanClass());
401 		};
402 		aDescriptor.setBound(true);
403 		/* aDescriptor.setConstrained(false); */
404 		/* aDescriptor.setDisplayName("selectedMember"); */
405 		/* aDescriptor.setShortDescription("selectedMember"); */
406 		/* aDescriptor.setExpert(false); */
407 		/* aDescriptor.setHidden(false); */
408 		/* aDescriptor.setValue("preferred", new Boolean(false)); */
409 		/* aDescriptor.setValue("ivjDesignTimeProperty", new Boolean(true)); */
410 	} catch (Throwable exception) {
411 		handleException(exception);
412 	};
413 	return aDescriptor;
414 }
415 }