KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form;
21
22 import java.awt.*;
23 import java.beans.*;
24 import java.io.*;
25 import java.util.*;
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.List JavaDoc;
28 import javax.swing.border.TitledBorder JavaDoc;
29 import java.text.MessageFormat JavaDoc;
30
31 import org.openide.ErrorManager;
32 import org.openide.util.*;
33 import org.openide.nodes.Node;
34 import org.openide.filesystems.FileObject;
35
36 import org.netbeans.modules.form.project.ClassPathUtils;
37
38 /**
39  * A class that contains utility methods for the formeditor.
40  * @author Ian Formanek
41  */

42
43 public class FormUtils
44 {
45     // constants for CopyProperties method
46
public static final int CHANGED_ONLY = 1;
47     public static final int DISABLE_CHANGE_FIRING = 2;
48     public static final int PASS_DESIGN_VALUES = 4;
49     public static final int DONT_CLONE_VALUES = 8;
50
51     private static final Object JavaDoc CLASS_EXACTLY = new Object JavaDoc();
52     private static final Object JavaDoc CLASS_AND_SUBCLASSES = new Object JavaDoc();
53     private static final Object JavaDoc CLASS_AND_SWING_SUBCLASSES = new Object JavaDoc();
54
55     static final Object JavaDoc PROP_PREFERRED = new Object JavaDoc();
56     static final Object JavaDoc PROP_NORMAL = new Object JavaDoc();
57     static final Object JavaDoc PROP_EXPERT = new Object JavaDoc();
58     static final Object JavaDoc PROP_HIDDEN = new Object JavaDoc();
59
60     static final String JavaDoc PROP_REQUIRES_PARENT = "thisPropertyRequiresParent"; // NOI18N
61
static final String JavaDoc PROP_REQUIRES_CHILDREN = "thisPropertyRequiresChildren"; // NOI18N
62

63     /** Table defining categories of properties. It overrides original Swing
64      * definition from beaninfo (which is often inadequate). */

65     private static Object JavaDoc[][] propertyCategories = {
66         { "java.awt.Component", CLASS_AND_SUBCLASSES,
67                 "locale", PROP_HIDDEN,
68                 "locationOnScreen", PROP_HIDDEN,
69                 "showing", PROP_HIDDEN },
70         { "java.awt.Component", CLASS_AND_SWING_SUBCLASSES,
71                 "accessibleContext", PROP_HIDDEN,
72                 "components", PROP_HIDDEN,
73                 "containerListeners", PROP_HIDDEN,
74                 "focusTraversalPolicySet", PROP_HIDDEN,
75                 "focusCycleRootAncestor", PROP_HIDDEN,
76                 "focusOwner", PROP_HIDDEN },
77         { "java.awt.Container", CLASS_AND_SUBCLASSES,
78                 "componentCount", PROP_HIDDEN,
79                 "layout", PROP_HIDDEN },
80         { "javax.swing.JComponent", CLASS_AND_SUBCLASSES,
81                 "debugGraphicsOptions", PROP_EXPERT,
82                 "preferredSize", PROP_NORMAL,
83                 "actionMap", PROP_HIDDEN },
84         { "javax.swing.JComponent", CLASS_AND_SWING_SUBCLASSES,
85                 "graphics", PROP_HIDDEN,
86                 "height", PROP_HIDDEN,
87                 "inputMap", PROP_HIDDEN,
88                 "maximumSizeSet", PROP_HIDDEN,
89                 "minimumSizeSet", PROP_HIDDEN,
90                 "preferredSizeSet", PROP_HIDDEN,
91                 "registeredKeyStrokes", PROP_HIDDEN,
92                 "rootPane", PROP_HIDDEN,
93                 "topLevelAncestor", PROP_HIDDEN,
94                 "validateRoot", PROP_HIDDEN,
95                 "visibleRect", PROP_HIDDEN,
96                 "width", PROP_HIDDEN,
97                 "x", PROP_HIDDEN,
98                 "y", PROP_HIDDEN,
99                 "ancestorListeners", PROP_HIDDEN,
100                 "propertyChangeListeners", PROP_HIDDEN,
101                 "vetoableChangeListeners", PROP_HIDDEN,
102                 "actionListeners", PROP_HIDDEN,
103                 "changeListeners", PROP_HIDDEN,
104                 "itemListeners", PROP_HIDDEN,
105                 "managingFocus", PROP_HIDDEN,
106                 "optimizedDrawingEnabled", PROP_HIDDEN,
107                 "paintingTile", PROP_HIDDEN },
108         { "java.awt.Window", CLASS_AND_SWING_SUBCLASSES,
109                 "focusCycleRootAncestor", PROP_HIDDEN,
110                 "focusOwner", PROP_HIDDEN,
111                 "active", PROP_HIDDEN,
112                 "alignmentX", PROP_HIDDEN,
113                 "alignmentY", PROP_HIDDEN,
114                 "bufferStrategy", PROP_HIDDEN,
115                 "focused", PROP_HIDDEN,
116                 "graphicsConfiguration", PROP_HIDDEN,
117                 "mostRecentFocusOwner", PROP_HIDDEN,
118                 "inputContext", PROP_HIDDEN,
119                 "ownedWindows", PROP_HIDDEN,
120                 "owner", PROP_HIDDEN,
121                 "windowFocusListeners", PROP_HIDDEN,
122                 "windowListeners", PROP_HIDDEN,
123                 "windowStateListeners", PROP_HIDDEN,
124                 "warningString", PROP_HIDDEN,
125                 "toolkit", PROP_HIDDEN,
126                 "focusableWindow", PROP_HIDDEN,
127                 "locationRelativeTo", PROP_HIDDEN },
128         { "javax.swing.text.JTextComponent", CLASS_AND_SUBCLASSES,
129                 "document", PROP_PREFERRED,
130                 "text", PROP_PREFERRED,
131                 "editable", PROP_PREFERRED,
132                 "disabledTextColor", PROP_NORMAL,
133                 "selectedTextColor", PROP_NORMAL,
134                 "selectionColor", PROP_NORMAL,
135                 "caretColor", PROP_NORMAL },
136         { "javax.swing.text.JTextComponent", CLASS_AND_SWING_SUBCLASSES,
137                 "actions", PROP_HIDDEN,
138                 "caretListeners", PROP_HIDDEN,
139                 "inputMethodRequests", PROP_HIDDEN },
140         { "javax.swing.JTextField", CLASS_AND_SUBCLASSES,
141                 "columns", PROP_PREFERRED },
142         { "javax.swing.JTextField", CLASS_AND_SWING_SUBCLASSES,
143                 "horizontalVisibility", PROP_HIDDEN },
144         { "javax.swing.JFormattedTextField", CLASS_EXACTLY,
145                 "formatter", PROP_HIDDEN },
146         { "javax.swing.JPasswordField", CLASS_EXACTLY,
147                 "password", PROP_HIDDEN },
148         { "javax.swing.JTextArea", CLASS_AND_SUBCLASSES,
149                 "columns", PROP_PREFERRED,
150                 "rows", PROP_PREFERRED,
151                 "lineWrap", PROP_PREFERRED,
152                 "wrapStyleWord", PROP_PREFERRED },
153         { "javax.swing.JEditorPane", CLASS_AND_SUBCLASSES,
154                 "border", PROP_PREFERRED,
155                 "font", PROP_PREFERRED,
156                 "contentType", PROP_PREFERRED,
157                 "editorKit", PROP_PREFERRED },
158         { "javax.swing.JEditorPane", CLASS_AND_SWING_SUBCLASSES,
159                 "hyperlinkListeners", PROP_HIDDEN },
160         { "javax.swing.JTextPane", CLASS_EXACTLY,
161                 "characterAttributes", PROP_HIDDEN,
162                 "paragraphAttributes", PROP_HIDDEN },
163         { "javax.swing.JTree", CLASS_AND_SUBCLASSES,
164                 "border", PROP_PREFERRED },
165         { "javax.swing.JTree", CLASS_EXACTLY,
166                 "editing", PROP_HIDDEN,
167                 "editingPath", PROP_HIDDEN,
168                 "selectionCount", PROP_HIDDEN,
169                 "selectionEmpty", PROP_HIDDEN,
170                 "lastSelectedPathComponent", PROP_HIDDEN,
171                 "leadSelectionRow", PROP_HIDDEN,
172                 "maxSelectionRow", PROP_HIDDEN,
173                 "minSelectionRow", PROP_HIDDEN,
174                 "treeExpansionListeners", PROP_HIDDEN,
175                 "treeSelectionListeners", PROP_HIDDEN,
176                 "treeWillExpandListeners", PROP_HIDDEN },
177         { "javax.swing.AbstractButton", CLASS_AND_SUBCLASSES,
178                 "mnemonic", PROP_PREFERRED,
179                 "action", PROP_PREFERRED },
180         { "javax.swing.AbstractButton", CLASS_AND_SWING_SUBCLASSES,
181                 "selectedObjects", PROP_HIDDEN },
182         { "javax.swing.JToggleButton", CLASS_AND_SUBCLASSES,
183                 "icon", PROP_PREFERRED,
184                 "selected", PROP_PREFERRED,
185                 "buttonGroup", PROP_PREFERRED },
186         { "javax.swing.JButton", CLASS_AND_SUBCLASSES,
187                 "icon", PROP_PREFERRED,
188                 "defaultButton", PROP_HIDDEN },
189         { "javax.swing.JCheckBox", CLASS_EXACTLY,
190                 "icon", PROP_NORMAL },
191         { "javax.swing.JRadioButton", CLASS_EXACTLY,
192                 "icon", PROP_NORMAL },
193         { "javax.swing.JMenuItem", CLASS_AND_SUBCLASSES,
194                 "icon", PROP_PREFERRED },
195         { "javax.swing.JMenuItem", CLASS_AND_SWING_SUBCLASSES,
196                 "menuDragMouseListeners", PROP_HIDDEN,
197                 "menuKeyListeners", PROP_HIDDEN },
198         { "javax.swing.JCheckBoxMenuItem", CLASS_AND_SUBCLASSES,
199                 "selected", PROP_PREFERRED,
200                 "buttonGroup", PROP_PREFERRED,
201                 "icon", PROP_NORMAL },
202         { "javax.swing.JRadioButtonMenuItem", CLASS_AND_SUBCLASSES,
203                 "selected", PROP_PREFERRED,
204                 "buttonGroup", PROP_PREFERRED,
205                 "icon", PROP_NORMAL },
206         { "javax.swing.JTabbedPane", CLASS_EXACTLY,
207                 "selectedComponent", PROP_EXPERT },
208         { "javax.swing.JSplitPane", CLASS_AND_SUBCLASSES,
209                 "dividerLocation", PROP_PREFERRED,
210                 "dividerSize", PROP_PREFERRED,
211                 "orientation", PROP_PREFERRED,
212                 "resizeWeight", PROP_PREFERRED },
213         { "javax.swing.JSplitPane", CLASS_EXACTLY,
214                 "leftComponent", PROP_HIDDEN,
215                 "rightComponent", PROP_HIDDEN,
216                 "topComponent", PROP_HIDDEN,
217                 "bottomComponent", PROP_HIDDEN },
218         { "javax.swing.JSlider", CLASS_AND_SUBCLASSES,
219                 "majorTickSpacing", PROP_PREFERRED,
220                 "minorTickSpacing", PROP_PREFERRED,
221                 "paintLabels", PROP_PREFERRED,
222                 "paintTicks", PROP_PREFERRED,
223                 "paintTrack", PROP_PREFERRED,
224                 "snapToTicks", PROP_PREFERRED },
225         { "javax.swing.JLabel", CLASS_AND_SUBCLASSES,
226                 "horizontalAlignment", PROP_PREFERRED,
227                 "verticalAlignment", PROP_PREFERRED,
228                 "displayedMnemonic", PROP_PREFERRED,
229                 "labelFor", PROP_PREFERRED },
230         { "javax.swing.JList", CLASS_AND_SUBCLASSES,
231                 "model", PROP_PREFERRED,
232                 "border", PROP_PREFERRED,
233                 "selectionMode", PROP_PREFERRED },
234         { "javax.swing.JComboBox", CLASS_AND_SUBCLASSES,
235                 "model", PROP_PREFERRED },
236         { "javax.swing.JComboBox", CLASS_EXACTLY,
237                 "popupVisible", PROP_HIDDEN,
238                 "popupMenuListeners", PROP_HIDDEN,
239                 "selectedObjects", PROP_HIDDEN },
240         { "javax.swing.Scrollable", CLASS_AND_SWING_SUBCLASSES,
241                 "preferredScrollableViewportSize", PROP_HIDDEN,
242                 "scrollableTracksViewportWidth", PROP_HIDDEN,
243                 "scrollableTracksViewportHeight", PROP_HIDDEN },
244         { "javax.swing.JScrollBar", CLASS_EXACTLY,
245                 "adjustmentListeners", PROP_HIDDEN },
246         { "javax.swing.JTable", CLASS_AND_SUBCLASSES,
247                 "model", PROP_PREFERRED,
248                 "border", PROP_PREFERRED },
249         { "javax.swing.JTable", CLASS_EXACTLY,
250                 "editing", PROP_HIDDEN,
251                 "editorComponent", PROP_HIDDEN,
252                 "selectedColumn", PROP_HIDDEN,
253                 "selectedColumnCount", PROP_HIDDEN,
254                 "selectedColumns", PROP_HIDDEN,
255                 "selectedRow", PROP_HIDDEN,
256                 "selectedRowCount", PROP_HIDDEN,
257                 "selectedRows", PROP_HIDDEN },
258         { "javax.swing.JSeparator", CLASS_EXACTLY,
259                 "font", PROP_NORMAL },
260         { "javax.swing.JInternalFrame", CLASS_AND_SUBCLASSES,
261                 "defaultCloseOperation", PROP_PREFERRED,
262                 "visible", PROP_NORMAL },
263         { "javax.swing.JInternalFrame", CLASS_EXACTLY,
264                 "menuBar", PROP_HIDDEN,
265                 "JMenuBar", PROP_HIDDEN,
266                 "desktopPane", PROP_HIDDEN,
267                 "internalFrameListeners", PROP_HIDDEN,
268                 "mostRecentFocusOwner", PROP_HIDDEN,
269                 "warningString", PROP_HIDDEN,
270                 "closed", PROP_HIDDEN },
271         { "javax.swing.JMenu", CLASS_EXACTLY,
272                 "accelerator", PROP_HIDDEN,
273                 "tearOff", PROP_HIDDEN,
274                 "menuComponents", PROP_HIDDEN,
275                 "menuListeners", PROP_HIDDEN,
276                 "popupMenu", PROP_HIDDEN,
277                 "topLevelMenu", PROP_HIDDEN },
278         { "javax.swing.JPopupMenu", CLASS_AND_SWING_SUBCLASSES,
279                 "popupMenuListeners", PROP_HIDDEN },
280         { "java.awt.Frame", CLASS_AND_SWING_SUBCLASSES,
281                 "cursorType", PROP_HIDDEN,
282                 "menuBar", PROP_HIDDEN },
283         { "javax.swing.JFrame", CLASS_AND_SUBCLASSES,
284                 "title", PROP_PREFERRED },
285         { "javax.swing.JFrame", CLASS_EXACTLY,
286                 "menuBar", PROP_HIDDEN,
287                 "layout", PROP_HIDDEN },
288         { "javax.swing.JDialog", CLASS_AND_SUBCLASSES,
289                 "title", PROP_PREFERRED },
290         { "javax.swing.JDialog", CLASS_EXACTLY,
291                 "layout", PROP_HIDDEN },
292         { "javax.swing.MenuElement", CLASS_AND_SWING_SUBCLASSES,
293                 "component", PROP_HIDDEN,
294                 "subElements", PROP_HIDDEN },
295         { "javax.swing.JMenuBar", CLASS_EXACTLY,
296                 "helpMenu", PROP_HIDDEN,
297                 "menuCount", PROP_HIDDEN,
298                 "selected", PROP_HIDDEN },
299         { "javax.swing.JSpinner", CLASS_AND_SUBCLASSES,
300                 "model", PROP_PREFERRED },
301         { "java.applet.Applet", CLASS_AND_SUBCLASSES,
302                 "appletContext", PROP_HIDDEN,
303                 "codeBase", PROP_HIDDEN,
304                 "documentBase", PROP_HIDDEN },
305         { "javax.swing.JFileChooser", CLASS_EXACTLY,
306                 "acceptAllFileFilter", PROP_HIDDEN,
307                 "choosableFileFilters", PROP_HIDDEN }
308     };
309
310     /** Table with explicit changes to propeties accessibility. E.g. some
311      * properties needs to be restricted to "detached write". */

312     private static Object JavaDoc[][] propertiesAccess = {
313         { "javax.swing.JFrame", CLASS_AND_SUBCLASSES,
314               "defaultCloseOperation", new Integer JavaDoc(FormProperty.DETACHED_WRITE) }
315     };
316
317     /** Table of properties that need the component to be added in the parent,
318      * or child components in the container before the property can be set.
319      * [We use one table though these are two distinct categories - it's fine
320      * until there is a property requiring both conditions.] */

321     private static Object JavaDoc[][] propertyContainerDeps = {
322         { "javax.swing.JTabbedPane", CLASS_AND_SUBCLASSES,
323                   "selectedIndex", PROP_REQUIRES_CHILDREN,
324                   "selectedComponent", PROP_REQUIRES_CHILDREN },
325         { "javax.swing.JInternalFrame", CLASS_AND_SUBCLASSES,
326                   "maximum", PROP_REQUIRES_PARENT,
327                   "icon", PROP_REQUIRES_PARENT }
328     };
329
330     /** Table defining order of dependent properties. */
331     private static Object JavaDoc[][] propertyOrder = {
332         { "javax.swing.text.JTextComponent",
333             "document", "text" },
334         { "javax.swing.JSpinner",
335             "model", "editor" },
336         { "javax.swing.AbstractButton",
337             "action", "actionCommand",
338             "action", "enabled",
339             "action", "mnemonic",
340             "action", "icon",
341             "action", "text",
342             "action", "toolTipText" },
343         { "javax.swing.JMenuItem",
344             "action", "accelerator" },
345         { "javax.swing.JList",
346             "model", "selectedIndex",
347             "model", "selectedValues" },
348         { "javax.swing.JComboBox",
349             "model", "selectedIndex",
350             "model", "selectedItem" },
351         { "java.awt.TextComponent",
352             "text", "selectionStart",
353             "text", "selectionEnd" },
354         { "javax.swing.JEditorPane",
355             "contentType", "text",
356             "editorKit", "text" }
357     };
358
359     /** List of components that should never be containers; some of them are
360      * not specified in original Swing beaninfos. */

361     private static String JavaDoc[] forbiddenContainers = {
362         "javax.swing.JLabel", // NOI18N
363
"javax.swing.JButton", // NOI18N
364
"javax.swing.JToggleButton", // NOI18N
365
"javax.swing.JCheckBox", // NOI18N
366
"javax.swing.JRadioButton", // NOI18N
367
"javax.swing.JComboBox", // NOI18N
368
"javax.swing.JList", // NOI18N
369
"javax.swing.JTextField", // NOI18N
370
"javax.swing.JTextArea", // NOI18N
371
"javax.swing.JScrollBar", // NOI18N
372
"javax.swing.JSlider", // NOI18N
373
"javax.swing.JProgressBar", // NOI18N
374
"javax.swing.JFormattedTextField", // NOI18N
375
"javax.swing.JPasswordField", // NOI18N
376
"javax.swing.JSpinner", // NOI18N
377
"javax.swing.JSeparator", // NOI18N
378
"javax.swing.JTextPane", // NOI18N
379
"javax.swing.JEditorPane", // NOI18N
380
"javax.swing.JTree", // NOI18N
381
"javax.swing.JTable", // NOI18N
382
"javax.swing.JOptionPane", // NOI18N
383
"javax.swing.JColorChooser", // NOI18N
384
"javax.swing.JFileChooser", // NOI18N
385
};
386     
387     // -----------------------------------------------------------------------------
388
// Utility methods
389

390     public static ResourceBundle getBundle() {
391         return NbBundle.getBundle(FormUtils.class);
392     }
393
394     public static String JavaDoc getBundleString(String JavaDoc key) {
395         return NbBundle.getBundle(FormUtils.class).getString(key);
396     }
397
398     public static String JavaDoc getFormattedBundleString(String JavaDoc key,
399                                                   Object JavaDoc[] arguments)
400     {
401         ResourceBundle bundle = NbBundle.getBundle(FormUtils.class);
402         return MessageFormat.format(bundle.getString(key), arguments);
403     }
404
405     /** Utility method that tries to clone an object. Objects of explicitly
406      * specified types are constructed directly, other are serialized and
407      * deserialized (if not serializable exception is thrown).
408      */

409     public static Object JavaDoc cloneObject(Object JavaDoc o, FormModel formModel) throws CloneNotSupportedException JavaDoc {
410         if (o == null) return null;
411
412         if ((o instanceof Byte JavaDoc) ||
413                  (o instanceof Short JavaDoc) ||
414                  (o instanceof Integer JavaDoc) ||
415                  (o instanceof Long JavaDoc) ||
416                  (o instanceof Float JavaDoc) ||
417                  (o instanceof Double JavaDoc) ||
418                  (o instanceof Boolean JavaDoc) ||
419                  (o instanceof Character JavaDoc) ||
420                  (o instanceof String JavaDoc)) {
421             return o; // no need to change reference
422
}
423
424         if (o.getClass() == Font.class) {
425             return o;
426         }
427         // Issue 49973
428
if ((o.getClass() == TitledBorder JavaDoc.class)
429             && (Utilities.isMac())) {
430             TitledBorder JavaDoc border = (TitledBorder JavaDoc)o;
431             return new TitledBorder JavaDoc(
432                 border.getBorder(),
433                 border.getTitle(),
434                 border.getTitleJustification(),
435                 border.getTitlePosition(),
436                 border.getTitleFont(),
437                 border.getTitleColor());
438         }
439         if (o.getClass() == Color.class)
440             return new Color(((Color)o).getRGB());
441         if (o instanceof Dimension)
442             return new Dimension((Dimension)o);
443         if (o instanceof Point)
444             return new Point((Point)o);
445         if (o instanceof Rectangle)
446             return new Rectangle((Rectangle)o);
447         if (o instanceof Insets)
448             return ((Insets)o).clone();
449         if (o instanceof GradientPaint) {
450             GradientPaint gp = (GradientPaint)o;
451             return new GradientPaint(gp.getPoint1(), gp.getColor1(), gp.getPoint2(), gp.getColor2(), gp.isCyclic());
452         }
453         if (o instanceof Serializable)
454             return cloneBeanInstance(o, null, formModel);
455
456         throw new CloneNotSupportedException JavaDoc();
457     }
458
459     /** Utility method that tries to clone an object as a bean.
460      * First - if it is serializable, then it is copied using serialization.
461      * If not serializable, then all properties (taken from BeanInfo) are
462      * copied (property values cloned recursively).
463      */

464     public static Object JavaDoc cloneBeanInstance(Object JavaDoc bean, BeanInfo bInfo, FormModel formModel)
465         throws CloneNotSupportedException JavaDoc
466     {
467         if (bean == null)
468             return null;
469
470         if (bean instanceof Serializable) {
471             try {
472                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
473                 ObjectOutputStream oos = new ObjectOutputStream(baos);
474                 oos.writeObject(bean);
475                 oos.close();
476
477                 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
478                 return new OIS(bais, bean.getClass().getClassLoader(), formModel).readObject();
479             }
480             catch (Exception JavaDoc ex) {
481                 ErrorManager em = ErrorManager.getDefault();
482                 em.annotate(ex, "Cannot clone "+bean.getClass().getName()); // NOI18N
483
em.notify(ErrorManager.INFORMATIONAL, ex);
484                 throw new CloneNotSupportedException JavaDoc(ex.getMessage());
485             }
486         }
487
488         // object is not Serializable
489
Object JavaDoc clone;
490         try {
491             clone = CreationFactory.createDefaultInstance(bean.getClass());
492             if (clone == null)
493                 throw new CloneNotSupportedException JavaDoc();
494
495             if (bInfo == null)
496                 bInfo = Utilities.getBeanInfo(bean.getClass());
497         }
498         catch (Exception JavaDoc ex) {
499             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
500             throw new CloneNotSupportedException JavaDoc(ex.getMessage());
501         }
502
503         // default instance successfully created, now copy properties
504
PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
505         for (int i=0; i < pds.length; i++) {
506             Method JavaDoc getter = pds[i].getReadMethod();
507             Method JavaDoc setter = pds[i].getWriteMethod();
508             if (getter != null && setter != null) {
509                 Object JavaDoc propertyValue;
510                 try {
511                     propertyValue = getter.invoke(bean, new Object JavaDoc[0]);
512                 }
513                 catch (Exception JavaDoc e1) { // ignore - do not copy this property
514
continue;
515                 }
516                 try {
517                     propertyValue = cloneObject(propertyValue, formModel);
518                 }
519                 catch (Exception JavaDoc e2) { // ignore - do not clone property value
520
}
521                 try {
522                     setter.invoke(clone, new Object JavaDoc[] { propertyValue });
523                 }
524                 catch (Exception JavaDoc e3) { // ignore - do not copy this property
525
}
526             }
527         }
528
529         return clone;
530     }
531
532     /** This method provides copying of property values from one array of
533      * properties to another. The arrays need not be equally sorted. It is
534      * recommended to use arrays of FormProperty, for which the mode parameter
535      * can be used to specify some options (using bit flags):
536      * CHANGED_ONLY (to copy only values of changed properties),
537      * DISABLE_CHANGE_FIRING (to disable firing of changes in target properties),
538      * PASS_DESIGN_VALUES (to pass the same FormDesignValue instances if they
539      * cannot or should not be copied),
540      */

541     public static void copyProperties(Node.Property[] sourceProperties,
542                                       Node.Property[] targetProperties,
543                                       int mode)
544     {
545         for (int i=0; i < sourceProperties.length; i++) {
546             Node.Property snProp = sourceProperties[i];
547             FormProperty sfProp = snProp instanceof FormProperty ?
548                                     (FormProperty)snProp : null;
549
550             if (sfProp != null
551                     && (mode & CHANGED_ONLY) != 0
552                     && !sfProp.isChanged())
553                 continue; // copy only changed properties
554

555             // find target property
556
Node.Property tnProp = targetProperties[i];
557             if (!tnProp.getName().equals(snProp.getName())) {
558                 int j;
559                 for (j=0; j < targetProperties.length; j++) {
560                     tnProp = targetProperties[i];
561                     if (tnProp.getName().equals(snProp.getName()))
562                         break;
563                 }
564                 if (j == targetProperties.length)
565                     continue; // not found
566
}
567             FormProperty tfProp = tnProp instanceof FormProperty ?
568                                     (FormProperty)tnProp : null;
569
570             try {
571                 // get and clone property value
572
Object JavaDoc propertyValue = snProp.getValue();
573                 Object JavaDoc copiedValue = propertyValue;
574                 if ((mode & DONT_CLONE_VALUES) == 0) {
575                     if (!(propertyValue instanceof FormDesignValue)) {
576                         try { // clone common property value
577
FormModel formModel = (sfProp == null) ? null : sfProp.getPropertyContext().getFormModel();
578                             copiedValue = FormUtils.cloneObject(propertyValue, formModel);
579                         }
580                         catch (CloneNotSupportedException JavaDoc ex) {} // ignore, don't report
581
}
582                     else { // handle FormDesignValue
583
Object JavaDoc val = ((FormDesignValue)propertyValue).copy(tfProp);
584                         if (val != null)
585                             copiedValue = val;
586                         else if ((mode & PASS_DESIGN_VALUES) == 0)
587                             continue; // cannot just pass the same design value
588
}
589                 }
590
591                 // set property value
592
if (tfProp != null) {
593                     boolean firing = tfProp.isChangeFiring();
594                     tfProp.setChangeFiring((mode & DISABLE_CHANGE_FIRING) == 0);
595                     tfProp.setValue(copiedValue);
596                     tfProp.setChangeFiring(firing);
597                 }
598                 else tnProp.setValue(copiedValue);
599
600                 if (sfProp != null && tfProp != null) {
601                     // also clone current PropertyEditor
602
PropertyEditor sPrEd = sfProp.getCurrentEditor();
603                     PropertyEditor tPrEd = tfProp.getCurrentEditor();
604                     if (sPrEd != null
605                         && (tPrEd == null
606                             || sPrEd.getClass() != tPrEd.getClass())
607                         && (propertyValue == copiedValue
608                             || (propertyValue != null && copiedValue != null
609                                 && propertyValue.getClass() == copiedValue.getClass())))
610                     {
611                         tPrEd = sPrEd instanceof RADConnectionPropertyEditor ?
612                             new RADConnectionPropertyEditor(tfProp.getValueType()) :
613                             (PropertyEditor)CreationFactory.createDefaultInstance(
614                                                              sPrEd.getClass());
615                         tfProp.setCurrentEditor(tPrEd);
616                     }
617                 }
618             }
619             catch (Exception JavaDoc ex) { // ignore
620
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
621             }
622         }
623     }
624
625     public static void copyPropertiesToBean(RADProperty[] props,
626                                             Object JavaDoc targetBean,
627                                             Collection relativeProperties)
628     {
629         for (int i = 0; i < props.length; i++) {
630             RADProperty prop = props[i];
631             if (!prop.isChanged())
632                 continue;
633
634             try {
635                 if (relativeProperties != null) {
636                     Object JavaDoc value = prop.getValue();
637                     if (value instanceof RADComponent
638                         || value instanceof RADComponent.ComponentReference
639                         || (value instanceof RADConnectionPropertyEditor.RADConnectionDesignValue
640                             && (((RADConnectionPropertyEditor.RADConnectionDesignValue)value).type
641                                 == RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_BEAN)))
642                     {
643                         relativeProperties.add(prop);
644                         continue;
645                     }
646                 }
647
648                 Method JavaDoc writeMethod = prop.getPropertyDescriptor().getWriteMethod();
649                 if (writeMethod == null
650                     || !prop.canWriteToTarget()
651                     || !writeMethod.getDeclaringClass().isAssignableFrom(
652                                                              targetBean.getClass()))
653                     continue;
654
655                 Object JavaDoc realValue = prop.getRealValue();
656                 if (realValue == FormDesignValue.IGNORED_VALUE)
657                     continue; // ignore this value, as it is not a real value
658

659                 realValue = FormUtils.cloneObject(realValue, props[i].getPropertyContext().getFormModel());
660                 writeMethod.invoke(targetBean, new Object JavaDoc[] { realValue });
661             }
662             catch (CloneNotSupportedException JavaDoc ex) { // ignore, don't report
663
}
664             catch (Exception JavaDoc ex) {
665                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
666             }
667         }
668     }
669
670     // ---------
671

672     public static boolean isContainer(Class JavaDoc beanClass) {
673 // Map containerBeans = formSettings.getContainerBeans();
674
// Object registered = containerBeans != null ?
675
// containerBeans.get(beanClass.getName()) : null;
676
// if (registered instanceof Boolean)
677
// return ((Boolean)registered).booleanValue();
678

679         // not registered
680
int containerStatus = canBeContainer(beanClass);
681         if (containerStatus == -1) { // "isContainer" attribute not specified
682
containerStatus = 1;
683             Class JavaDoc cls = beanClass.getSuperclass();
684             while (cls != null
685                    && !cls.equals(java.awt.Container JavaDoc.class))
686             {
687                 String JavaDoc beanClassName = cls.getName();
688                 int i;
689                 for (i=0; i < forbiddenContainers.length; i++)
690                     if (beanClassName.equals(forbiddenContainers[i]))
691                         break; // superclass cannot be container
692

693                 if (i < forbiddenContainers.length) {
694                     containerStatus = 0;
695                     break;
696                 }
697
698                 cls = cls.getSuperclass();
699             }
700         }
701
702         return containerStatus == 1;
703 // boolean isContainer = containerStatus == 1;
704
//
705
// if (beanClass.getName().startsWith("javax.swing.")) // NOI18N
706
// setIsContainer(beanClass, isContainer);
707
//
708
// return isContainer;
709
}
710
711     /** @return 1 if the class is explicitly specified as container in BeanInfo;
712      * 0 if the class is explicitly enumerated in forbiddenContainers
713      * or specified as non-container in its BeanInfo;
714      * -1 if the class is not forbidden nor specified in BeanInfo at all
715      */

716     public static int canBeContainer(Class JavaDoc beanClass) {
717         if (beanClass == null
718                 || !java.awt.Container JavaDoc.class.isAssignableFrom(beanClass))
719             return 0;
720
721         String JavaDoc beanClassName = beanClass.getName();
722         for (int i=0; i < forbiddenContainers.length; i++)
723             if (beanClassName.equals(forbiddenContainers[i]))
724                 return 0; // cannot be container
725

726         Object JavaDoc isContainerValue = null;
727         try {
728             BeanDescriptor desc = Utilities.getBeanInfo(beanClass)
729                                                     .getBeanDescriptor();
730             if (desc != null)
731                isContainerValue = desc.getValue("isContainer"); // NOI18N
732
}
733         catch (Exception JavaDoc ex) { // ignore failure
734
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
735         }
736         catch (Error JavaDoc ex) { // Issue 74002
737
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
738         }
739
740         if (isContainerValue instanceof Boolean JavaDoc)
741             return ((Boolean JavaDoc)isContainerValue).booleanValue() ? 1 : 0;
742         return -1; // "isContainer" attribute not specified
743
}
744
745 // public static void setIsContainer(Class beanClass, boolean isContainer) {
746
// if (beanClass == null)
747
// return;
748
//
749
// Map containerBeans = formSettings.getContainerBeans();
750
// if (containerBeans == null)
751
// containerBeans = new HashMap();
752
//
753
// containerBeans.put(beanClass.getName(), isContainer ? Boolean.TRUE : Boolean.FALSE);
754
// formSettings.setContainerBeans(containerBeans);
755
// }
756
//
757
// public static void removeIsContainerRegistration(Class beanClass) {
758
// Map containerBeans = formSettings.getContainerBeans();
759
// if (containerBeans == null || beanClass == null)
760
// return;
761
//
762
// containerBeans.remove(beanClass.getName());
763
// formSettings.setContainerBeans(containerBeans);
764
// }
765

766     // ---------
767

768     /** Returns explicit property category classification (defined in
769      * propertyCategories table)for properties of given class.
770      * The returned array can be used in getPropertyCategory method to get
771      * category for individual property. Used for SWING components to
772      * correct their default (insufficient) classification.
773      */

774     static Object JavaDoc[] getPropertiesCategoryClsf(Class JavaDoc beanClass,
775                                               BeanDescriptor beanDescriptor)
776     {
777         ArrayList reClsf = null;
778 // Class beanClass = beanInfo.getBeanDescriptor().getBeanClass();
779

780         // some magic with JComponents first...
781
if (javax.swing.JComponent JavaDoc.class.isAssignableFrom(beanClass)) {
782             reClsf = new ArrayList(8);
783             Object JavaDoc isContainerValue = beanDescriptor.getValue("isContainer"); // NOI18N
784
if (isContainerValue == null || Boolean.TRUE.equals(isContainerValue)) {
785                 reClsf.add("font"); // NOI18N
786
reClsf.add(PROP_NORMAL);
787             }
788             else {
789                 reClsf.add("border"); // NOI18N
790
reClsf.add(PROP_NORMAL); // NOI18N
791
}
792         }
793
794         return collectPropertiesClsf(beanClass, propertyCategories, reClsf);
795     }
796
797     /** Returns type of property (PROP_PREFERRED, PROP_NORMAL, PROP_EXPERT or
798      * PROP_HIDDEN) based on PropertyDescriptor and definitions in
799      * properties classification for given bean class (returned from
800      * getPropertiesCategoryClsf method).
801      */

802     static Object JavaDoc getPropertyCategory(PropertyDescriptor pd,
803                                       Object JavaDoc[] propsClsf)
804     {
805         Object JavaDoc cat = findPropertyClsf(pd.getName(), propsClsf);
806         if (cat != null)
807             return cat;
808
809         if (pd.isHidden())
810             return PROP_HIDDEN;
811         if (pd.isExpert())
812             return PROP_EXPERT;
813         if (pd.isPreferred() || Boolean.TRUE.equals(pd.getValue("preferred"))) // NOI18N
814
return PROP_PREFERRED;
815         return PROP_NORMAL;
816     }
817
818     /** Returns explicit property access type classification for properties of
819      * given class (defined in propertiesAccess table). The returned array can
820      * be used in getPropertyAccess method to get the access type for
821      * individual property.
822      */

823     static Object JavaDoc[] getPropertiesAccessClsf(Class JavaDoc beanClass) {
824         return collectPropertiesClsf(beanClass, propertiesAccess, null);
825     }
826
827     /** Returns access type for given property (as FormProperty constant).
828      * 0 if no restriction is explicitly defined.
829      */

830     static int getPropertyAccess(PropertyDescriptor pd,
831                                  Object JavaDoc[] propsClsf)
832     {
833         Object JavaDoc access = findPropertyClsf(pd.getName(), propsClsf);
834         return access == null ? 0 : ((Integer JavaDoc)access).intValue();
835     }
836
837     static Object JavaDoc[] getPropertiesParentChildDepsClsf(Class JavaDoc beanClass) {
838         return collectPropertiesClsf(beanClass, propertyContainerDeps, null);
839     }
840
841     static String JavaDoc getPropertyParentChildDependency(PropertyDescriptor pd,
842                                                  Object JavaDoc[] propClsf)
843     {
844         return (String JavaDoc) findPropertyClsf(pd.getName(), propClsf);
845     }
846
847     private static Object JavaDoc[] collectPropertiesClsf(Class JavaDoc beanClass,
848                                                   Object JavaDoc[][] table,
849                                                   java.util.List JavaDoc list)
850     {
851         // Set of names of super classes of the bean and interfaces implemented by the bean.
852
Set superClasses = superClasses(beanClass);
853
854         for (int i=0; i < table.length; i++) {
855             Object JavaDoc[] clsf = table[i];
856             String JavaDoc refClass = (String JavaDoc)clsf[0];
857             Object JavaDoc subclasses = clsf[1];
858
859             if (refClass.equals(beanClass.getName())
860                 ||
861                 (subclasses == CLASS_AND_SUBCLASSES
862                          && superClasses.contains(refClass))
863                 ||
864                 (subclasses == CLASS_AND_SWING_SUBCLASSES
865                          && superClasses.contains(refClass)
866                          && beanClass.getName().startsWith("javax.swing."))) { // NOI18N
867
if (list == null)
868                     list = new ArrayList(8);
869                 for (int j=2; j < clsf.length; j++)
870                     list.add(clsf[j]);
871             }
872         }
873
874         if (list != null) {
875             Object JavaDoc[] array = new Object JavaDoc[list.size()];
876             list.toArray(array);
877             return array;
878         }
879         return null;
880     }
881
882     private static Object JavaDoc findPropertyClsf(String JavaDoc name, Object JavaDoc[] clsf) {
883         if (clsf != null) {
884             int i = clsf.length;
885             while (i > 0) {
886                 if (clsf[i-2].equals(name))
887                     return clsf[i-1];
888                 i -= 2;
889             }
890         }
891         return null;
892     }
893
894     static boolean isMarkedParentDependentProperty(Node.Property prop) {
895         return Boolean.TRUE.equals(prop.getValue(PROP_REQUIRES_PARENT));
896     }
897
898     static boolean isMarkedChildrenDependentProperty(Node.Property prop) {
899         return Boolean.TRUE.equals(prop.getValue(PROP_REQUIRES_CHILDREN));
900     }
901
902     /** @return a formatted name of specified method
903      */

904     public static String JavaDoc getMethodName(MethodDescriptor desc) {
905         return getMethodName(desc.getName(), desc.getMethod().getParameterTypes());
906     }
907     
908     public static String JavaDoc getMethodName(String JavaDoc name, Class JavaDoc[] params) {
909     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(name);
910         if ((params == null) ||(params.length == 0)) {
911             sb.append("()"); // NOI18N
912
} else {
913             for (int i = 0; i < params.length; i++) {
914                 if (i == 0) sb.append("("); // NOI18N
915
else sb.append(", "); // NOI18N
916
sb.append(Utilities.getShortClassName(params[i]));
917             }
918             sb.append(")"); // NOI18N
919
}
920
921         return sb.toString();
922     }
923
924     static void sortProperties(Node.Property[] properties) {
925         Arrays.sort(properties, new Comparator() {
926             public int compare(Object JavaDoc o1, Object JavaDoc o2) {
927                 String JavaDoc n1 =((Node.Property)o1).getDisplayName();
928                 String JavaDoc n2 =((Node.Property)o2).getDisplayName();
929                 return n1.compareTo(n2);
930             }
931         });
932     }
933     
934     static void reorderProperties(Class JavaDoc beanClass, RADProperty[] properties) {
935         sortProperties(properties);
936         Object JavaDoc[] order = collectPropertiesOrder(beanClass, propertyOrder);
937         for (int i=0; i<order.length/2; i++) {
938             updatePropertiesOrder(properties, (String JavaDoc)order[2*i], (String JavaDoc)order[2*i+1]);
939         }
940     }
941     
942     private static void updatePropertiesOrder(RADProperty[] properties,
943         String JavaDoc firstProp, String JavaDoc secondProp) {
944         int firstIndex = findPropertyIndex(properties, firstProp);
945         int secondIndex = findPropertyIndex(properties, secondProp);
946         if ((firstIndex != -1) && (secondIndex != -1) && (firstIndex > secondIndex)) {
947             // Move the first one before the second
948
RADProperty first = properties[firstIndex];
949             for (int i=firstIndex; i>secondIndex; i--) {
950                 properties[i] = properties[i-1];
951             }
952             properties[secondIndex] = first;
953         }
954     }
955     
956     private static int findPropertyIndex(RADProperty[] properties, String JavaDoc property) {
957         int index = -1;
958         for (int i=0; i<properties.length; i++) {
959             if (property.equals(properties[i].getName())) {
960                 index = i;
961                 break;
962             }
963         }
964         return index;
965     }
966     
967     private static Object JavaDoc[] collectPropertiesOrder(Class JavaDoc beanClass, Object JavaDoc[][] table) {
968         // Set of names of super classes of the bean and interfaces implemented by the bean.
969
Set superClasses = superClasses(beanClass);
970
971         java.util.List JavaDoc list = new LinkedList();
972         for (int i=0; i < table.length; i++) {
973             Object JavaDoc[] order = table[i];
974             String JavaDoc refClass = (String JavaDoc)order[0];
975
976             if (superClasses.contains(refClass)) {
977                 for (int j=1; j<order.length; j++) {
978                     list.add(order[j]);
979                 }
980             }
981         }
982         return list.toArray();
983     }
984
985     // ---------
986

987     /** Loads a class of a component to be used (instantiated) in the form
988      * editor. The class might be either a support class being part of the IDE,
989      * or a user class defined externally (by a project classpath).
990      * There are also separate loadSystemClass for loading a module class only.
991      * @param name String name of the class
992      * @param formFile FileObject representing the form file as part of a project
993      */

994     public static Class JavaDoc loadClass(String JavaDoc name, FileObject formFile)
995         throws ClassNotFoundException JavaDoc
996     {
997         return ClassPathUtils.loadClass(name, formFile);
998     }
999
1000    public static Class JavaDoc loadClass(String JavaDoc name, FormModel form)
1001        throws ClassNotFoundException JavaDoc
1002    {
1003        FormDataObject dobj = FormEditor.getFormDataObject(form);
1004        return dobj != null ? loadClass(name, dobj.getFormFile()) :
1005                              loadSystemClass(name); // layout test may have no data object
1006
}
1007
1008    /** Loads a class using IDE system class loader. Usable for form module
1009     * support classes, property editors, etc.
1010     */

1011    public static Class JavaDoc loadSystemClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
1012        ClassLoader JavaDoc loader = (ClassLoader JavaDoc)
1013                                 Lookup.getDefault().lookup(ClassLoader JavaDoc.class);
1014        if (loader == null)
1015            throw new ClassNotFoundException JavaDoc();
1016
1017        return Class.forName(name, true, loader);
1018    }
1019
1020    // ---------
1021

1022    private static class OIS extends ObjectInputStream {
1023        private ClassLoader JavaDoc classLoader;
1024        private FormModel formModel;
1025
1026        public OIS(InputStream is, ClassLoader JavaDoc loader, FormModel formModel) throws IOException {
1027            super(is);
1028            this.formModel = formModel;
1029            classLoader = loader;
1030        }
1031
1032        protected Class JavaDoc resolveClass(ObjectStreamClass streamCls)
1033            throws IOException, ClassNotFoundException JavaDoc
1034        {
1035            String JavaDoc name = streamCls.getName();
1036            return loadClass(name);
1037        }
1038        
1039        private Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
1040            if (classLoader != null) {
1041                try {
1042                    return Class.forName(name, true, classLoader);
1043                } catch (ClassNotFoundException JavaDoc ex) {}
1044            }
1045            return FormUtils.loadClass(name, formModel);
1046        }
1047        
1048    }
1049
1050    public static List JavaDoc/*RADComponent*/ getSelectedLayoutComponents(Node[] nodes) {
1051        if ((nodes == null) || (nodes.length < 1))
1052            return null;
1053
1054        List JavaDoc components = new ArrayList();
1055        for (int i=0; i<nodes.length; i++) {
1056            RADComponentCookie radCookie =
1057                (RADComponentCookie) nodes[i].getCookie(RADComponentCookie.class);
1058            if (radCookie != null) {
1059                RADComponent metacomp = radCookie.getRADComponent();
1060                if ((metacomp instanceof RADVisualComponent)) {
1061                    RADVisualComponent visComp = (RADVisualComponent)metacomp;
1062                    RADVisualContainer visCont = visComp.getParentContainer();
1063                    if ((visCont != null) && javax.swing.JScrollPane JavaDoc.class.isAssignableFrom(visCont.getBeanInstance().getClass())) {
1064                        visComp = visCont;
1065                        visCont = visCont.getParentContainer();
1066                    }
1067
1068                    if (isInTopDesignComponent(visComp) && (visCont!= null) && (visCont.getLayoutSupport() == null)) {
1069                        components.add(visComp);
1070                    } else {
1071                        return null;
1072                    }
1073                } else {
1074                    return null;
1075                }
1076            }
1077        }
1078        return components;
1079    }
1080
1081    public static boolean isInTopDesignComponent(RADComponent comp) {
1082        FormDesigner designer = FormEditor.getFormDesigner(comp.getFormModel());
1083        RADVisualComponent topDesigned = designer.getTopDesignComponent();
1084        while ((comp != null) && (comp != topDesigned)) {
1085            comp = comp.getParentComponent();
1086        }
1087        return (comp == topDesigned);
1088    }
1089    
1090    private static Set superClasses(Class JavaDoc beanClass) {
1091        Set superClasses = new HashSet();
1092        Class JavaDoc[] infaces = beanClass.getInterfaces();
1093        for (int i=0; i<infaces.length; i++) {
1094            superClasses.add(infaces[i].getName());
1095        }
1096        Class JavaDoc superClass = beanClass;
1097        do {
1098            superClasses.add(superClass.getName());
1099        } while ((superClass = superClass.getSuperclass()) != null);
1100        return superClasses;
1101    }
1102    /*
1103     * Calls Introspector.getBeanInfo() more safely to handle 3rd party BeanInfos
1104     * that may be broken or malformed. This is a replacement for Introspector.getBeanInfo().
1105     * @see java.beans.Introspector.getBeanInfo(Class)
1106     */

1107    public static java.beans.BeanInfo JavaDoc getBeanInfo(Class JavaDoc clazz) throws java.beans.IntrospectionException JavaDoc {
1108        try {
1109            return Utilities.getBeanInfo(clazz);//, java.beans.Introspector.USE_ALL_BEANINFO);
1110
} catch (Error JavaDoc ex1) { // why is Error thrown instead of IntrospectionException?
1111
try {
1112                return Introspector.getBeanInfo(clazz, java.beans.Introspector.IGNORE_IMMEDIATE_BEANINFO);
1113            } catch (Error JavaDoc ex2) {
1114                return Introspector.getBeanInfo(clazz, java.beans.Introspector.IGNORE_ALL_BEANINFO);
1115            }
1116        }
1117    }
1118}
1119
Popular Tags