File: RecordLoader.java

package info (click to toggle)
python-schema-salad 8.9.20251102115403-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,060 kB
  • sloc: python: 19,247; cpp: 2,631; cs: 1,869; java: 1,341; makefile: 187; xml: 184; sh: 103; javascript: 46
file content (51 lines) | stat: -rw-r--r-- 1,842 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ${package}.utils;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class RecordLoader<T extends Saveable> implements Loader<T> {
  private final Class<? extends T> saveableClass;
  private final String container;
  private final Boolean noLinkCheck;

  public RecordLoader(final Class<? extends T> saveableClass, final String container, final Boolean noLinkCheck) {
    this.saveableClass = saveableClass;
    this.container = container;
    this.noLinkCheck = noLinkCheck;
  }

  public T load(
      final Object doc,
      final String baseUri,
      final LoadingOptions loadingOptions,
      final String docRoot) {
    Loader.validateOfJavaType(java.util.Map.class, doc);
    try {
      final Constructor<? extends T> constructor =
          this.saveableClass.getConstructor(
              new Class[] {Object.class, String.class, LoadingOptions.class, String.class});
      LoadingOptions innerLoadingOptions = loadingOptions;
      if (this.container != null || this.noLinkCheck != null) {
        LoadingOptionsBuilder builder = new LoadingOptionsBuilder().copiedFrom(loadingOptions);
        if (this.container != null) {
          builder.setContainer(this.container);
        }
        if (this.noLinkCheck != null) {
          builder.setNoLinkCheck(this.noLinkCheck);
        }
        innerLoadingOptions = builder.build();
      }
      final T ret = constructor.newInstance(doc, baseUri, innerLoadingOptions, docRoot);
      return ret;
    } catch (InvocationTargetException e) {
      final Throwable cause = e.getCause();
      if (cause instanceof RuntimeException) {
        throw (RuntimeException) cause;
      }
      throw new RuntimeException(e.getCause());
    } catch (ReflectiveOperationException e) {
      throw new RuntimeException(e);
    }
  }

}