KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > util > Display


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.common.validation.util;
25
26 import java.text.MessageFormat JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import com.sun.enterprise.tools.common.validation.Failure;
31 import com.sun.enterprise.tools.common.validation.util.BundleReader;
32
33 /**
34  * Display is a class that provides utiltiy methods for displaying
35  * validation failures.
36  *
37  * @author Rajeshwar Patil
38  * @version %I%, %G%
39  */

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

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

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

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

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

114     protected boolean isFailureObject(Object JavaDoc object){
115         return (object instanceof Failure);
116     }
117 }
118
Popular Tags