KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > ValidationError


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  * ValidationError.java
21  *
22  * Created on March 3, 2004, 2:15 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean;
26
27 /**
28  *
29  * @author Peter Williams
30  */

31 public final class ValidationError implements Comparable JavaDoc {
32     
33     private final Partition partition;
34     private final String JavaDoc fieldId;
35     private final String JavaDoc message;
36     
37     /** Creates a new instance of ValidationError */
38     private ValidationError(String JavaDoc fieldId, String JavaDoc message) {
39         this(PARTITION_GLOBAL, fieldId, message);
40     }
41     
42     /** Creates a new instance of ValidationError */
43     private ValidationError(Partition partition, String JavaDoc fieldId, String JavaDoc message) {
44         this.partition = partition;
45         this.fieldId = fieldId;
46         this.message = message;
47     }
48     
49     /** Returns the partition. This features is to allow us to partition error
50      * messages by subpanel of a customizer and only display error messages
51      * associated with the current panel. It could have other uses as well.
52      *
53      * @return the partition.
54      */

55     public Partition getPartition() {
56         return partition;
57     }
58     
59     /** Returns the field Id, which is the absolute xpath describing this fieldId.
60      *
61      * @return the field Id.
62      */

63     public String JavaDoc getFieldId() {
64         return fieldId;
65     }
66     
67     /** Returns the validation message describing the error that this field
68      * contains.
69      *
70      * @return the validation error message.
71      */

72     public String JavaDoc getMessage() {
73         return message;
74     }
75
76     /** Two ValidationError's are equal if they hvae the same partition and
77      * fieldId.
78      *
79      * @param obj ValidationError to compare equality with.
80      * @return true if equal, false otherwise.
81      */

82     public boolean equals(Object JavaDoc obj) {
83         boolean result;
84         
85         if(this == obj) {
86             result = true;
87         } else {
88             ValidationError target = (ValidationError) obj;
89             result = partition.equals(target.partition) && fieldId.equals(target.fieldId);
90         }
91         
92         return result;
93     }
94     
95     private volatile int hashCode = 0;
96     
97     /** Hashcode for a ValidationError object. Overridden for consistency with
98      * equals.
99      *
100      * @return integer hashcode
101      */

102     public int hashCode() {
103         if(hashCode == 0) {
104             int result = fieldId.hashCode();
105             if(partition != null) {
106                 result = 37*result + partition.hashCode();
107             }
108             hashCode = result;
109         }
110         return hashCode;
111     }
112     
113     /** Compare this instance of ValidationError with the target instance.
114      * We index by partition first, then fieldId. Partition ordering doesn't
115      * really matter as long as members of a partition are grouped.
116      *
117      * @param Instance of ValidationError to compare with.
118      */

119     public int compareTo(Object JavaDoc obj) {
120         int result;
121         
122         if(this == obj) {
123             result = 0;
124         } else {
125             ValidationError target = (ValidationError) obj;
126             result = partition.compareTo(target.partition);
127
128             if(result == 0) {
129                 result = fieldId.compareTo(target.fieldId);
130             }
131         }
132
133         return result;
134     }
135     
136     /** Creates a new ValidationError Object
137      *
138      * @param fieldId Absolute Xpath of the field this messages applies to
139      * @param message Error message describing the error in this field.
140      */

141     public static ValidationError getValidationError(String JavaDoc fieldId, String JavaDoc message) {
142         return new ValidationError(fieldId, message);
143     }
144     
145     public static ValidationError getValidationErrorMask(String JavaDoc fieldId) {
146         return new ValidationError(fieldId, "");
147     }
148     
149     /** Creates a new ValidationError Object
150      *
151      * @param fieldId Absolute Xpath of the field this messages applies to
152      * @param panelId1 Customizer panel ID this field is displayed
153      * @param message Error message describing the error in this field.
154      */

155     public static ValidationError getValidationError(Partition partition, String JavaDoc fieldId, String JavaDoc message) {
156         return new ValidationError(partition, fieldId, message);
157     }
158     
159     public static ValidationError getValidationErrorMask(Partition partition, String JavaDoc fieldId) {
160         return new ValidationError(partition, fieldId, "");
161     }
162     
163     /** -----------------------------------------------------------------------
164      * Partitions defined for customizer ui.
165      */

166     
167     // Global partition
168
public static final Partition PARTITION_GLOBAL =
169         new Partition("Global");
170     
171     // Partitions for sun-web-app
172
public static final Partition PARTITION_WEB_GENERAL =
173         new Partition("WebGeneral", 0); // NOI18N
174
public static final Partition PARTITION_WEB_CLASSLOADER =
175         new Partition("WebClassLoader", 1); // NOI18N
176
public static final Partition PARTITION_WEB_PROPERTIES =
177         new Partition("WebProperties", 2); // NOI18N
178
public static final Partition PARTITION_SESSION_MANAGER =
179         new Partition("SessionManager", 3, 0); // NOI18N
180
public static final Partition PARTITION_SESSION_STORE =
181         new Partition("SessionStore", 3, 1); // NOI18N
182
public static final Partition PARTITION_SESSION_SESSION =
183         new Partition("SessionSession", 3, 2); // NOI18N
184
public static final Partition PARTITION_SESSION_COOKIE =
185         new Partition("SessionCookie", 3, 3); // NOI18N
186
public static final Partition PARTITION_WEB_MESSAGES =
187         new Partition("WebMessages", 4); // NOI18N
188
public static final Partition PARTITION_WEB_LOCALE =
189         new Partition("WebLocale", 5); // NOI18N
190
public static final Partition PARTITION_CACHE_GENERAL =
191         new Partition("CacheGeneral", 6, 0); // NOI18N
192
public static final Partition PARTITION_CACHE_HELPERS =
193         new Partition("CacheHelpers", 6, 1); // NOI18N
194
public static final Partition PARTITION_CACHE_CONSTRAINTS =
195         new Partition("CacheConstraints", 6, 2); // NOI18N
196

197     // Partitions for SecurityRoleMapping
198
public static final Partition PARTITION_SECURITY_ASSIGN =
199         new Partition("SecurityAssign", 0); // NOI18N
200
public static final Partition PARTITION_SECURITY_MASTER =
201         new Partition("SecurityMaster", 1); // NOI18N
202

203     // Partitions for ServiceRef
204
public static final Partition PARTITION_SERVICEREF_GENERAL =
205         new Partition("ServiceRefGeneral", 0); // NOI18N
206
public static final Partition PARTITION_SERVICEREF_PORTINFO =
207         new Partition("ServiceRefPortInfo", 1); // NOI18N
208

209     // Partitions for ConnectorRoot
210
public static final Partition PARTITION_CONNECTOR_ADAPTER =
211         new Partition("ConnectorAdapter", 0); // NOI18N
212
public static final Partition PARTITION_CONNECTOR_ROLES =
213         new Partition("ConnectorRoles", 1); // NOI18N
214

215     // Partitions for sun-ejb-jar
216
public static final Partition PARTITION_EJBJAR_CMP_RESOURCE =
217         new Partition("EjbJarCmpResource", 0); // NOI18N
218
public static final Partition PARTITION_EJBJAR_PM_DESCRIPTORS =
219         new Partition("EjbJarPmDescriptors", 1); // NOI18N
220
public static final Partition PARTITION_EJBJAR_MESSAGES =
221         new Partition("EjbJarMessages", 2); // NOI18N
222

223     
224     public static final class Partition implements Comparable JavaDoc {
225         private final String JavaDoc partitionName;
226         private int tabIndex;
227         private int subTabIndex;
228
229         private Partition(final String JavaDoc name) {
230             this(name, -1, -1);
231         }
232         
233         private Partition(final String JavaDoc name, final int index) {
234             this(name, index, -1);
235         }
236         
237         private Partition(final String JavaDoc name, final int index, final int subIndex) {
238             partitionName = name;
239             tabIndex = index;
240             subTabIndex = subIndex;
241         }
242
243         public String JavaDoc toString() {
244             return partitionName;
245         }
246         
247         public int getTabIndex() {
248             return tabIndex;
249         }
250         
251         public int getSubTabIndex() {
252             return subTabIndex;
253         }
254         
255         public int compareTo(Object JavaDoc obj) {
256             Partition target = (Partition) obj;
257             return partitionName.compareTo(target.partitionName);
258         }
259     }
260 }
261
262
Popular Tags