1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.settings4j.contentresolver;
18
19 import org.settings4j.ContentResolver;
20
21
22
23
24
25
26
27
28
29 public class UnionContentResolver implements ContentResolver {
30
31 private ContentResolver[] contentResolvers = new ContentResolver[0];
32
33
34
35
36 public UnionContentResolver() {
37 super();
38 }
39
40
41
42
43
44
45 public UnionContentResolver(final ContentResolver contentResolver) {
46 super();
47 addContentResolverInternal(contentResolver);
48 }
49
50
51 public void addContentResolver(final ContentResolver contentResolver) {
52 synchronized (this) {
53 addContentResolverInternal(contentResolver);
54 }
55 }
56
57 private void addContentResolverInternal(final ContentResolver contentResolver) {
58 final ContentResolver[] contentResolversNew = new ContentResolver[this.contentResolvers.length + 1];
59 for (int i = 0; i < this.contentResolvers.length; i++) {
60 contentResolversNew[i] = this.contentResolvers[i];
61 }
62 contentResolversNew[this.contentResolvers.length] = contentResolver;
63
64 this.contentResolvers = contentResolversNew;
65 }
66
67
68 public byte[] getContent(final String key) {
69 byte[] result = null;
70 for (ContentResolver contentResolver : contentResolvers) {
71 result = contentResolver.getContent(key);
72 if (result != null) {
73 return result;
74 }
75 }
76 return result;
77 }
78 }