1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.mail2.jakarta.resolver;
18
19 import java.io.IOException;
20
21 import org.apache.commons.mail2.jakarta.DataSourceResolver;
22
23 import jakarta.activation.DataSource;
24
25
26
27
28
29
30 public class DataSourceCompositeResolver extends DataSourceBaseResolver {
31
32
33 private final DataSourceResolver[] dataSourceResolvers;
34
35
36
37
38
39
40 public DataSourceCompositeResolver(final DataSourceResolver[] dataSourceResolvers) {
41 this.dataSourceResolvers = dataSourceResolvers.clone();
42 }
43
44
45
46
47
48
49
50 public DataSourceCompositeResolver(final DataSourceResolver[] dataSourceResolvers, final boolean isLenient) {
51 super(isLenient);
52 this.dataSourceResolvers = dataSourceResolvers.clone();
53 }
54
55
56
57
58
59
60 public DataSourceResolver[] getDataSourceResolvers() {
61
62 return dataSourceResolvers.clone();
63 }
64
65
66 @Override
67 public DataSource resolve(final String resourceLocation) throws IOException {
68 final DataSource result = resolve(resourceLocation, true);
69 if (isLenient() || result != null) {
70 return result;
71 }
72 throw new IOException("The following resource was not found : " + resourceLocation);
73
74 }
75
76
77 @Override
78 public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException {
79 for (final DataSourceResolver dataSourceResolver : dataSourceResolvers) {
80 final DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient);
81 if (dataSource != null) {
82 return dataSource;
83 }
84 }
85 if (isLenient) {
86 return null;
87 }
88 throw new IOException("The following resource was not found : " + resourceLocation);
89 }
90 }