1
|
|
|
/* |
2
|
|
|
* This file is part of ArakneLangLoader. |
3
|
|
|
* |
4
|
|
|
* ArakneLangLoader is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* ArakneLangLoader is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with ArakneLangLoader. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.arakne.swflangloader.parser.mapper; |
21
|
|
|
|
22
|
|
|
import java.lang.reflect.Field; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Hydrator using reflection field |
26
|
|
|
*/ |
27
|
|
|
final public class ReflectionPropertyHydrator<T, V> implements PropertyHydrator<T, V> { |
28
|
|
|
final private Field field; |
29
|
|
|
|
30
|
1 |
|
public ReflectionPropertyHydrator(Field field) { |
31
|
1 |
|
this.field = field; |
32
|
|
|
|
33
|
1 |
|
field.setAccessible(true); |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
@Override |
37
|
|
|
@SuppressWarnings("unchecked") |
38
|
|
|
public V get(T source) { |
39
|
|
|
try { |
40
|
1 |
|
return (V) field.get(source); |
41
|
|
|
} catch (IllegalAccessException e) { |
42
|
|
|
throw new RuntimeException(e); // Should not occurs |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
@Override |
47
|
|
|
public void set(T target, V value) { |
48
|
|
|
try { |
49
|
1 |
|
field.set(target, value); |
50
|
|
|
} catch (IllegalAccessException e) { |
51
|
|
|
throw new RuntimeException(e); // Should not occurs |
52
|
1 |
|
} |
53
|
1 |
|
} |
54
|
|
|
} |
55
|
|
|
|