1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package com.unitesk.atp.messages;
33
34 /***
35 * The message box that discards all messages but counts them.
36 *
37 * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
38 * @version $Id: NullMessageBox.java,v 1.3 2004/10/12 08:23:12 all-x Exp $
39 */
40 public class NullMessageBox implements MessageBox
41 {
42 /***
43 * Creates message box with default {@link MessageStringManager string manager}.
44 *
45 * @see #NullMessageBox(MessageStringManager)
46 */
47 public NullMessageBox()
48 {
49 }
50
51 /***
52 * Creates message box with the specified {@link MessageStringManager string manager}.
53 *
54 * @param sm The specified string manager.
55 */
56 public NullMessageBox( MessageStringManager sm )
57 {
58 if( sm == null ) throw new NullPointerException( "sm" );
59 this.sm = sm;
60 }
61
62 /***
63 * {@inheritDoc}
64 */
65 public synchronized void fatal( Message message )
66 {
67 error( message );
68 status();
69 }
70
71 /***
72 * {@inheritDoc}
73 */
74 public synchronized void error( Message message )
75 {
76 context.setMessage( message );
77 context.setLevel( ErrorMessageLevel.level);
78 error_count++;
79 errorStr( sm.getString( context ) );
80 }
81
82 /***
83 * {@inheritDoc}
84 */
85 public synchronized void warning( Message message )
86 {
87 context.setMessage( message );
88 context.setLevel( WarningMessageLevel.level );
89 warning_count++;
90 warningStr( sm.getString( context ) );
91 }
92
93 /***
94 * {@inheritDoc}
95 */
96 public synchronized void info( Message message )
97 {
98 context.setMessage( message );
99 context.setLevel( InfoMessageLevel.level );
100 info_count++;
101 infoStr( sm.getString( context ) );
102 }
103
104 /***
105 * {@inheritDoc}
106 */
107 public synchronized void info( String message )
108 {
109 info_count++;
110 infoStr( message );
111 }
112
113 /***
114 * {@inheritDoc}
115 */
116 public int getErrorCount()
117 {
118 return error_count;
119 }
120
121 /***
122 * {@inheritDoc}
123 */
124 public int getWarningCount()
125 {
126 return warning_count;
127 }
128
129 /***
130 * {@inheritDoc}
131 */
132 public int getInfoCount()
133 {
134 return info_count;
135 }
136
137 /***
138 * {@inheritDoc}
139 */
140 public void statistics()
141 {
142 info( new MessageBoxStatisticsMessage() );
143 }
144
145 /***
146 * {@inheritDoc}
147 */
148 public void status()
149 {
150 if( getErrorCount() > 0 )
151 {
152 statistics();
153 stop( 1 );
154 }
155 }
156
157 /***
158 * {@inheritDoc}
159 */
160 public void stop( int code )
161 {
162 throw new FatalErrorException( code );
163 }
164
165 /***
166 * {@inheritDoc}
167 */
168 public MessageStringManager getStringManager() { return sm; }
169
170 protected synchronized void errorStr( String message )
171 {
172
173 }
174
175 protected synchronized void warningStr( String message )
176 {
177
178 }
179
180 protected synchronized void infoStr( String message )
181 {
182
183 }
184
185 protected MessageContext context = new MessageContext( this );
186 protected MessageStringManager sm = new MessageStringManager();
187
188 private int error_count;
189 private int warning_count;
190 private int info_count;
191 }