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; |
21
|
|
|
|
22
|
|
|
import com.google.gson.Gson; |
23
|
|
|
import com.google.gson.JsonSyntaxException; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Simple variable assignation |
27
|
|
|
*/ |
28
|
|
|
final public class SimpleAssignationType implements AssignationType { |
29
|
1 |
|
final static private Gson GSON = new Gson(); |
30
|
|
|
|
31
|
|
|
final private Class<?> type; |
32
|
|
|
|
33
|
1 |
|
public SimpleAssignationType(Class<?> type) { |
34
|
1 |
|
this.type = type; |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
@Override |
38
|
|
|
public Assignation parseSimple(String varName, String value) { |
39
|
|
|
try { |
40
|
1 |
|
return Assignation.simple(varName, GSON.fromJson(value, type)); |
41
|
|
|
} catch (JsonSyntaxException e) { |
42
|
|
|
return Assignation.NULL; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|