1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.bindings.core.general.binding;
17
18 import org.jadira.bindings.core.api.Binding;
19 import org.jadira.bindings.core.api.FromUnmarshaller;
20 import org.jadira.bindings.core.api.ToMarshaller;
21
22
23
24
25
26
27
28 public class InverseCompositeBinding<S, T> implements Binding<S, T> {
29
30 private final ToMarshaller<T, S> marshal;
31
32 private final FromUnmarshaller<T, S> unmarshal;
33
34
35
36
37
38 public InverseCompositeBinding(Binding<T, S> binding) {
39
40 if (binding == null) {
41 throw new IllegalStateException("Binding may not be null");
42 }
43
44 this.unmarshal = binding;
45 this.marshal = binding;
46 }
47
48
49
50
51
52
53 public InverseCompositeBinding(ToMarshaller<T, S> marshal, FromUnmarshaller<T, S> unmarshal) {
54
55 if (unmarshal == null) {
56 throw new IllegalStateException("Unmarshaller may not be null");
57 }
58 if (marshal == null) {
59 throw new IllegalStateException("Marshaller may not be null");
60 }
61
62 this.unmarshal = unmarshal;
63 this.marshal = marshal;
64 }
65
66
67
68
69
70 public T marshal(S object) {
71 return unmarshal.unmarshal(object);
72 }
73
74
75
76
77
78 public S unmarshal(T input) {
79 return marshal.marshal(input);
80 }
81
82
83
84
85
86 public Class<S> getBoundClass() {
87 return marshal.getTargetClass();
88 }
89
90
91
92
93
94 public Class<T> getTargetClass() {
95 return marshal.getBoundClass();
96 }
97 }