/
CreateFromSavedSimulationDelegate.java
85 lines (69 loc) · 2.52 KB
/
CreateFromSavedSimulationDelegate.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************************************
*
* CreateFromSavedSimulationDelegate.java, in ummisco.gama.serialize, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package ummisco.gama.serializer.gaml;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.thoughtworks.xstream.XStream;
import msi.gama.runtime.IScope;
import msi.gaml.statements.Arguments;
import msi.gaml.statements.CreateStatement;
import msi.gaml.types.IType;
import msi.gama.common.interfaces.ICreateDelegate;
import msi.gama.metamodel.agent.SavedAgent;
import msi.gaml.types.Types;
import ummisco.gama.serializer.factory.StreamConverter;
import ummisco.gama.serializer.gamaType.converters.ConverterScope;
/**
* Class CreateFromSavecSimulationDelegate.
*
* @author bgaudou
* @since 18 July 2018
*
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class CreateFromSavedSimulationDelegate implements ICreateDelegate {
/**
* Method acceptSource()
*
* @see msi.gama.common.interfaces.ICreateDelegate#acceptSource(IScope, java.lang.Object)
*/
@Override
public boolean acceptSource(IScope scope, final Object source) {
return source instanceof GamaSavedSimulationFile;
}
/**
* @see msi.gama.common.interfaces.ICreateDelegate#createFrom(msi.gama.runtime.IScope,
* java.util.List, int, java.lang.Object)
*/
@Override
public boolean createFrom(final IScope scope, final List<Map<String, Object>> inits, final Integer max,
final Object source, final Arguments init, final CreateStatement statement) {
final GamaSavedSimulationFile file = (GamaSavedSimulationFile) source;
final ConverterScope cScope = new ConverterScope(scope);
final XStream xstream = StreamConverter.loadAndBuild(cScope,cScope.getClass());
String stringFile = file.getBuffer().get(0);
final SavedAgent saveAgt = (SavedAgent) xstream.fromXML(stringFile);
HashMap mapSavedAgt = new HashMap<String, Object>();
mapSavedAgt.put("SavedAgent", saveAgt);
inits.add(mapSavedAgt);
return true;
}
/**
* Method fromFacetType()
*
* @see msi.gama.common.interfaces.ICreateDelegate#fromFacetType()
*/
@Override
public IType fromFacetType() {
return Types.FILE;
}
}