comparison env/lib/python3.7/site-packages/schema_salad/java/main_utils/UnionLoader.java @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 package ${package}.utils;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.List;
6
7 public class UnionLoader implements Loader<Object> {
8 private final List<Loader> alternates;
9
10 public UnionLoader(List<Loader> alternates) {
11 this.alternates = alternates;
12 }
13
14 public UnionLoader(Loader[] alternates) {
15 this(Arrays.asList(alternates));
16 }
17
18 public Object load(
19 final Object doc,
20 final String baseUri,
21 final LoadingOptions loadingOptions,
22 final String docRoot) {
23 final List<ValidationException> errors = new ArrayList();
24 for (final Loader loader : this.alternates) {
25 try {
26 return loader.load(doc, baseUri, loadingOptions, docRoot);
27 } catch (ValidationException e) {
28 errors.add(e);
29 }
30 }
31 throw new ValidationException("Failed to match union type", errors);
32 }
33 }