comparison env/lib/python3.7/site-packages/schema_salad/java/main_utils/OneOrListOfLoader.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.List;
5 import java.util.Optional;
6
7
8 public class OneOrListOfLoader<T> implements Loader<OneOrListOf<T>> {
9 private final Loader<T> oneLoader;
10 private final Loader<List<T>> listLoader;
11
12 public OneOrListOfLoader(Loader<T> oneLoader, Loader<List<T>> listLoader) {
13 this.oneLoader = oneLoader;
14 this.listLoader = listLoader;
15 }
16
17 public OneOrListOf<T> load(
18 final Object doc,
19 final String baseUri,
20 final LoadingOptions loadingOptions,
21 final String docRoot) {
22 final List<ValidationException> errors = new ArrayList();
23 try {
24 return OneOrListOf.oneOf(this.oneLoader.load(doc, baseUri, loadingOptions, docRoot));
25 } catch (ValidationException e) {
26 errors.add(e);
27 }
28 try {
29 return OneOrListOf.listOf(this.listLoader.load(doc, baseUri, loadingOptions, docRoot));
30 } catch (ValidationException e) {
31 errors.add(e);
32 }
33 throw new ValidationException("Failed to one or list of of type", errors);
34 }
35 }