KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > util > Display


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.j2ee.sun.validation.util;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.netbeans.modules.j2ee.sun.validation.Failure;
27 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader;
28
29 /**
30  * Display is a class that provides utiltiy methods for displaying
31  * validation failures.
32  *
33  * @author Rajeshwar Patil
34  * @version %I%, %G%
35  */

36 public class Display {
37
38     /** Creates a new instance of <code>Display</code>. */
39     public Display() {
40     }
41
42
43     /**
44      * Displays validation failures in a command mode.
45      * It systems out the failure messages.
46      */

47     public void text(Collection JavaDoc collection) {
48         Object JavaDoc object = null;
49         Failure failure = null;
50
51         if(collection != null){
52             Iterator JavaDoc iterator = collection.iterator();
53             while(iterator.hasNext()){
54                 object = iterator.next();
55                 boolean failureObect = isFailureObject(object);
56                 if(failureObect){
57                     failure = (Failure) object;
58                     reportFailure(failure.failureMessage());
59                 } else {
60                     reportError(object);
61                 }
62             }
63         }
64     }
65
66
67     /**
68      * Displays validation failures in a GUI mode.
69      */

70     public void gui(Collection JavaDoc collection){
71         assert false :
72                 (BundleReader.getValue("MSG_not_yet_implemented")); //NOI18N
73
}
74
75
76     /**
77      * Systems out the failure message.
78      * @param message the failure message to report.
79      */

80     protected void reportFailure(String JavaDoc message){
81         System.out.println(message);
82     }
83
84
85     /**
86      * Reports an error message.
87      * @param object the given object which is not of type {@link Failure}
88      */

89     protected void reportError(Object JavaDoc object){
90         String JavaDoc format = BundleReader.getValue(
91             "MSG_does_not_support_displaying_of"); //NOI18N
92
Class JavaDoc classObject = object.getClass();
93         Object JavaDoc[] arguments = new Object JavaDoc[]{"Display", //NOI18N
94
classObject.getName()};
95
96         String JavaDoc message =
97             MessageFormat.format(format, arguments);
98
99         assert false : message;
100     }
101
102
103     /**
104      * Determines whether the given <code>object</code> is of
105      * type {@link Failure}
106      * @param object the given object to determine the type of
107      * @return <code>true</code> only if the given
108      * <code>object</code> is of type <code>Failure</code>
109      */

110     protected boolean isFailureObject(Object JavaDoc object){
111         return (object instanceof Failure);
112     }
113 }
114
Popular Tags