1 /* -------------------------------------------------------------------
2 * Java source file for the class BeanUtil
3 *
4 * Copyright (c), 2002, Masahiro Takatsuka.
5 * All Rights Researved.
6 *
7 * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8 * $Author: takatsukam $
9 *
10 * $Date: 2003/07/25 04:51:44 $
11 *
12 * $Id: BeanUtil.java,v 1.1.1.1 2003/07/25 04:51:44 takatsukam Exp $
13 *
14 * Reference: Document no:
15 * ___ ___
16 *
17 * To Do:
18 * ___
19 *
20 ------------------------------------------------------------------- */
21
22 /* --------------------------- Package ---------------------------- */
23 package net.jbeans.bean;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */
26 import java.beans.*;
27 import java.lang.reflect.*;
28 import java.util.*;
29
30 import net.jbeans.lang.*;
31 import net.jbeans.util.debug.*;
32
33 /*====================================================================
34 Implementation of class BeanUtil
35 ====================================================================*/
36 /***
37 * BeanUtil provides various useful static methods handling beans.
38 *
39 * @version $Revision: 1.1.1.1 $
40 * @author Masahiro Takatsuka (masa@jbeans.net)
41 */
42
43 public final class BeanUtil {
44 private static final boolean DEBUG = Debug.getDebugFlag(BeanUtil.class);
45
46 private BeanUtil() {
47 super();
48 }
49
50 /***
51 * Returns a localized display name of a bean.
52 */
53 public static String getDisplayName(Class beanClass) {
54 String displayName;
55 try {
56 BeanInfo bi = BeanInfoFinder.getBeanInfo(beanClass);
57 displayName = bi.getBeanDescriptor().getDisplayName();
58 } catch (Exception ex) {
59 ex.printStackTrace();
60 System.out.println("Continuing...");
61 displayName = "";
62 }
63 return displayName;
64 }
65
66 /***
67 * If the specified "src" object implements "addPropertyChangeListener",
68 * this method adds the object "o" to it.
69 */
70 public static void makeObjectListenToPropertyChange(Object o, Object src) {
71 try {
72 Class[] argTypes = {PropertyChangeListener.class};
73 if (ClassUtil.respondsToMethod(src, "addPropertyChangeListener", argTypes)) {
74 Class c = src.getClass();
75 Method m = c.getMethod("addPropertyChangeListener", argTypes);
76 Object[] args = {o};
77 m.invoke(src, args);
78 }
79 } catch (Exception e) {
80 if (DEBUG) {
81 e.printStackTrace();
82 }
83 }
84 }
85
86 /***
87 * If the specified "src" object implements "removePropertyChangeListener",
88 * this method removes the object "o" from it.
89 */
90 public static void makeObjectUnListenToPropertyChange(Object o, Object src) {
91 try {
92 Class[] argTypes = {PropertyChangeListener.class};
93 if (ClassUtil.respondsToMethod(src, "removePropertyChangeListener", argTypes)) {
94 Class c = src.getClass();
95 Method m = c.getMethod("removePropertyChangeListener", argTypes);
96 Object[] args = {o};
97 m.invoke(src, args);
98 }
99 } catch (Exception e) {
100 if (DEBUG) {
101 e.printStackTrace();
102 }
103 }
104 }
105 }
This page was automatically generated by Maven