1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.message;
|
11
|
|
|
12
|
|
import java.util.ArrayList;
|
13
|
|
import java.util.Enumeration;
|
14
|
|
import java.util.Iterator;
|
15
|
|
import java.util.List;
|
16
|
|
import java.util.Locale;
|
17
|
|
import java.util.StringTokenizer;
|
18
|
|
|
19
|
|
import org.jbind.util.collection.ConcatIterator;
|
20
|
|
|
21
|
|
public class CompositeMessage extends AbstractMessage implements ICompositeMessage {
|
22
|
|
|
23
|
|
private List myMessages = new ArrayList();
|
24
|
|
private Object myParameters = null;
|
25
|
|
|
26
|
16730
|
public CompositeMessage(MessageFormats aMessageFormats, String aKey, Object aParameters) {
|
27
|
16730
|
super(aMessageFormats, aKey);
|
28
|
16730
|
myParameters = aParameters;
|
29
|
|
}
|
30
|
|
|
31
|
298
|
protected Object getParameters(Locale aLocale) {
|
32
|
298
|
return myParameters;
|
33
|
|
}
|
34
|
|
|
35
|
17632
|
public boolean isEmpty() {
|
36
|
17632
|
return myMessages.size() == 0;
|
37
|
|
}
|
38
|
|
|
39
|
0
|
public boolean isComposite() {
|
40
|
0
|
return true;
|
41
|
|
}
|
42
|
|
|
43
|
377
|
public Iterator iterSubMessages() {
|
44
|
377
|
return myMessages.iterator();
|
45
|
|
}
|
46
|
|
|
47
|
72
|
public Iterator iterSimpleMessages() {
|
48
|
72
|
List l = new ArrayList();
|
49
|
72
|
for (Iterator i = iterSubMessages(); i.hasNext(); ) {
|
50
|
46
|
IMessage m = (IMessage)i.next();
|
51
|
46
|
l.add(m.iterSimpleMessages());
|
52
|
|
}
|
53
|
72
|
return new ConcatIterator(l);
|
54
|
|
}
|
55
|
|
|
56
|
298
|
public String output(Locale aLocale, boolean anIndent, boolean anOutputContainerLines) {
|
57
|
298
|
StringBuffer sb = new StringBuffer();
|
58
|
298
|
boolean needsReturn = false;
|
59
|
298
|
if (anOutputContainerLines) {
|
60
|
298
|
sb.append(super.output(aLocale, anIndent, anOutputContainerLines));
|
61
|
298
|
needsReturn = true;
|
62
|
|
}
|
63
|
298
|
for (Iterator i = iterSubMessages(); i.hasNext(); ) {
|
64
|
293
|
IMessage m = (IMessage)i.next();
|
65
|
293
|
String s = m.output(aLocale, anIndent, anOutputContainerLines);
|
66
|
293
|
for (Enumeration e = new StringTokenizer(s, "\n"); e.hasMoreElements(); ) {
|
67
|
304
|
if (needsReturn) {
|
68
|
217
|
sb.append('\n');
|
69
|
217
|
needsReturn = false;
|
70
|
|
}
|
71
|
304
|
String line = (String)e.nextElement();
|
72
|
304
|
if (anIndent) {
|
73
|
304
|
sb.append('\t');
|
74
|
|
}
|
75
|
304
|
sb.append(line);
|
76
|
304
|
if (e.hasMoreElements()) {
|
77
|
11
|
sb.append('\n');
|
78
|
|
}
|
79
|
|
}
|
80
|
293
|
if (i.hasNext()) {
|
81
|
76
|
sb.append('\n');
|
82
|
|
}
|
83
|
|
}
|
84
|
298
|
return sb.toString();
|
85
|
|
}
|
86
|
|
|
87
|
352
|
public void add(IMessage aMessage) {
|
88
|
352
|
myMessages.add(aMessage);
|
89
|
|
}
|
90
|
|
|
91
|
7
|
public void addTo(ICompositeMessage aCompositeMessage) {
|
92
|
7
|
for (Iterator i = iterSubMessages(); i.hasNext(); ) {
|
93
|
8
|
IMessage m = (IMessage)i.next();
|
94
|
8
|
m.addTo(aCompositeMessage);
|
95
|
|
}
|
96
|
|
}
|
97
|
|
|
98
|
|
}
|
99
|
|
|