1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties;
23
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /***
29 * Abstract base clase for a {@link de.fu_berlin.ties.Processor} that collects
30 * all the input arguments and processes the collected arguments when shutting
31 * down. The {@link #close(int)} method delegates to the abstract
32 * {@link #process(List, ContextMap)} method to process the collected arguments.
33 *
34 * <p>Instances of this class are not thread-safe and must be synchronized
35 * externally, if required.
36 *
37 * @author Christian Siefkes
38 * @version $Revision: 1.9 $, $Date: 2006/10/21 16:03:52 $, $Author: siefkes $
39 */
40 public abstract class CollectingProcessor
41 extends ConfigurableProcessor
42 implements Closeable {
43
44 /***
45 * Used to collect the input arguments.
46 */
47 private final List<String> collectedArgs = new ArrayList<String>();
48
49 /***
50 * Creates a new instance.
51 *
52 * @param conf used to configure this instance; if <code>null</code>,
53 * the {@linkplain TiesConfiguration#CONF standard configuration} is used
54 */
55 public CollectingProcessor(final TiesConfiguration conf) {
56 super(conf);
57 }
58
59 /***
60 * {@inheritDoc}
61 */
62 public final void close(final int errorCount)
63 throws IOException, ProcessingException {
64
65 process(collectedArgs, new ContextMap());
66 }
67
68 /***
69 * {@inheritDoc}
70 */
71 public final void process(final String input) {
72
73 collectedArgs.add(input);
74 }
75
76 /***
77 * Processes the collected input arguments.
78 *
79 * @param collected a list of Strings containing the collected input
80 * arguments
81 * @param context a map of objects that are made available for processing;
82 * will be empty when called from the {@link #close(int)} method in this
83 * class
84 * @throws IOException if an I/O error occurs
85 * @throws ProcessingException if an error occurs during processing
86 */
87 public abstract void process(final List<String> collected,
88 final ContextMap context)
89 throws IOException, ProcessingException;
90
91 }