Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
YamlConstructor.java
1 package org.bukkit.configuration.file;
2 
3 import java.util.LinkedHashMap;
4 import java.util.Map;
5 
6 import org.yaml.snakeyaml.nodes.Node;
7 import org.yaml.snakeyaml.constructor.SafeConstructor;
8 import org.yaml.snakeyaml.error.YAMLException;
9 import org.yaml.snakeyaml.nodes.Tag;
10 
12 
13 public class YamlConstructor extends SafeConstructor {
14 
15  public YamlConstructor() {
16  this.yamlConstructors.put(Tag.MAP, new ConstructCustomObject());
17  }
18 
19  private class ConstructCustomObject extends ConstructYamlMap {
20  @Override
21  public Object construct(Node node) {
22  if (node.isTwoStepsConstruction()) {
23  throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
24  }
25 
26  Map<?, ?> raw = (Map<?, ?>) super.construct(node);
27 
28  if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
29  Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size());
30  for (Map.Entry<?, ?> entry : raw.entrySet()) {
31  typed.put(entry.getKey().toString(), entry.getValue());
32  }
33 
34  try {
36  } catch (IllegalArgumentException ex) {
37  throw new YAMLException("Could not deserialize object", ex);
38  }
39  }
40 
41  return raw;
42  }
43 
44  @Override
45  public void construct2ndStep(Node node, Object object) {
46  throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
47  }
48  }
49 }
static ConfigurationSerializable deserializeObject(Map< String,?> args, Class<?extends ConfigurationSerializable > clazz)