KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > RuntimeHelpStatus


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal;
12
13 import java.util.*;
14
15 import org.eclipse.core.runtime.*;
16
17 /**
18  * This class is intended to capture all runtime exception happening during the
19  * execution of the Help System.
20  */

21
22 public class RuntimeHelpStatus {
23     private static RuntimeHelpStatus inst = null;
24
25     // contains Status objects of errors occurred
26
private ArrayList errorList = new ArrayList();
27
28     // contains File names (Strings) of invalid contribution files.
29
private ArrayList badFilesList = new ArrayList();
30
31     // contains the error messages (Strings) from the parser
32
private ArrayList parserErrorMessagesList = new ArrayList();
33
34     /**
35      * RuntimeHelpStatus constructor comment.
36      */

37     public RuntimeHelpStatus() {
38         super();
39     }
40     public synchronized void addParseError(String JavaDoc message,
41             String JavaDoc invalidFileName) {
42         // add the Exception to the files list only once. These exceptions will
43
// be used to
44
// produce the list of files with errors.
45
if (!badFilesList.contains(invalidFileName))
46             badFilesList.add(invalidFileName);
47
48         // now add the message. All parser messages are added
49
parserErrorMessagesList.add(message);
50
51     }
52     public boolean errorsExist() {
53         if (errorList.isEmpty() && parserErrorMessagesList.isEmpty()
54                 && badFilesList.isEmpty())
55             return false;
56         else
57             return true;
58     }
59     public static synchronized RuntimeHelpStatus getInstance() {
60         if (inst == null) // create instance
61
inst = new RuntimeHelpStatus();
62         return inst;
63     }
64     /**
65      * clears RuntimeHelpStatus object.
66      */

67     public void reset() {
68         errorList.clear();
69         badFilesList.clear();
70         parserErrorMessagesList.clear();
71     }
72     public synchronized String JavaDoc toString() {
73         StringBuffer JavaDoc fullText = new StringBuffer JavaDoc();
74         if (!errorList.isEmpty()) {
75             fullText.append(HelpResources.getString("E006")); //$NON-NLS-1$
76
fullText.append("******************** \n"); //$NON-NLS-1$
77
for (int i = 0; i < errorList.size(); i++) {
78                 fullText.append(((Status) (errorList.get(i))).getMessage());
79                 fullText.append("\n"); //$NON-NLS-1$
80
}
81         }
82
83         if (fullText.length() > 0)
84             fullText.append("\n"); //$NON-NLS-1$
85

86         if (!parserErrorMessagesList.isEmpty()) {
87             // display the files that failed to parse
88
fullText.append(HelpResources.getString("E007")); //$NON-NLS-1$
89
fullText.append("******************** \n"); //$NON-NLS-1$
90
for (int i = 0; i < badFilesList.size(); i++) {
91                 fullText.append(((String JavaDoc) (badFilesList.get(i))));
92                 fullText.append("\n"); //$NON-NLS-1$
93
}
94
95             fullText.append("\n"); //$NON-NLS-1$
96

97             // and the parse error message
98
fullText.append(HelpResources.getString("E008")); //$NON-NLS-1$
99
fullText.append("******************** \n"); //$NON-NLS-1$
100
for (int i = 0; i < parserErrorMessagesList.size(); i++) {
101                 fullText.append(((String JavaDoc) (parserErrorMessagesList.get(i))));
102                 fullText.append("\n"); //$NON-NLS-1$
103
}
104         }
105
106         if (fullText.length() > 0)
107             return fullText.toString();
108         else
109             return ""; //$NON-NLS-1$
110

111     }
112 }
113
Popular Tags