KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > beaninfo > editors > ExPropertyEditorSupport


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  * ExPropertyEditorSupport.java
21  *
22  * Created on March 26, 2003, 4:38 PM
23  */

24
25 package org.netbeans.beaninfo.editors;
26 import java.beans.*;
27 import org.openide.explorer.propertysheet.*;
28 /** Support class for ExPropertyEditor which provides means for validating
29  * hints from the PropertyEnv instance passed to attachEnv. Forces
30  * subclasses to be fail-fast in the case that illegal values are passed
31  * via the PropertyEnv (the alternative is cryptic error messages when
32  * the editor tries to use the hints).
33  * @author Tim Boudreau
34  * @version 1.0
35  */

36 public abstract class ExPropertyEditorSupport extends PropertyEditorSupport implements ExPropertyEditor {
37     
38     /** Creates a new instance of ExPropertyEditorSupport */
39     protected ExPropertyEditorSupport() {
40     }
41     
42     /** Implementation of PropertyEditorSupport.attachEnv(). This method
43      * is final to ensure that the values from the env are validated.
44      * Subclasses should override attachEnvImpl to provide the actual
45      * attaching behavior. attachEnvImpl is called first, then
46      * validateEnv (to avoid fetching the values twice). */

47     public final void attachEnv(PropertyEnv env) {
48         attachEnvImpl(env);
49         validateEnv(env);
50     }
51     
52     /** Perform the actual attaching of the PropertyEnv. */
53     protected abstract void attachEnvImpl(PropertyEnv env);
54     
55     /** Validate values stored in the PropertyEnv. This method allows
56      * subclasses to be fail-fast if they are supplied illegal values
57      * as hints from the PropertyEnv. Subclasses should confirm that any
58      * hints used by their property editor are valid values. If they
59      * are not valid, an EnvException should be thrown with a clear
60      * description of the problem. */

61     protected abstract void validateEnv(PropertyEnv env);
62     
63     /** This class exists to enable unit tests to differentiate
64      * between code bugs in the editors and invalid values from
65      * the propertyEnv. */

66     public static class EnvException extends IllegalArgumentException JavaDoc {
67         public EnvException(String JavaDoc s) { super(s); }
68     }
69     
70     /** Utility method to convert an array of Objects into a comma
71      * delimited string. */

72     protected static final String JavaDoc arrToStr(Object JavaDoc[] s) {
73         if (s == null) return "null"; //NOI18N
74
StringBuffer JavaDoc out = new StringBuffer JavaDoc(s.length * 10);
75         for (int i=0; i < s.length; i++) {
76             if (s[i] != null) {
77                 out.append(s[i]);
78             } else {
79                 out.append("null");
80             }
81             if (i != s.length-1) {
82                 out.append(","); //NOI18N
83
}
84         }
85         return out.toString();
86     }
87 }
88
Popular Tags