MCPcopy Create free account
hub / github.com/agateau/pixelwheels / load

Method load

core/src/com/agateau/utils/Introspector.java:77–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75 }
76
77 public void load() {
78 if (!mFileHandle.exists()) {
79 return;
80 }
81 XmlReader.Element root = FileUtils.parseXml(mFileHandle);
82 if (root == null) {
83 return;
84 }
85 for (XmlReader.Element keyElement : root.getChildrenByName("key")) {
86 String name = keyElement.getAttribute("name");
87 String type = keyElement.getAttribute("type");
88 String value = keyElement.getText();
89 Field field;
90 try {
91 field = mClass.getField(name);
92 } catch (NoSuchFieldException e) {
93 NLog.e("No field named '%s', skipping", name);
94 continue;
95 }
96 String fieldType = field.getType().toString();
97 if (!fieldType.equals(type)) {
98 NLog.e(
99 "Field '%s' is of type '%s', but XML expected '%s', skipping",
100 name, fieldType, type);
101 continue;
102 }
103 switch (type) {
104 case "int":
105 set(name, Integer.valueOf(value));
106 break;
107 case "boolean":
108 set(name, Boolean.valueOf(value));
109 break;
110 case "float":
111 set(name, Float.valueOf(value));
112 break;
113 default:
114 throw new RuntimeException(
115 "Unsupported type '" + type + "' for field '" + name + "'");
116 }
117 }
118 }
119
120 public void save() {
121 XmlWriter writer = new XmlWriter(mFileHandle.writer(false));

Callers 2

createIntrospectorMethod · 0.95
testRoundTripMethod · 0.95

Calls 5

parseXmlMethod · 0.95
eMethod · 0.95
setMethod · 0.95
toStringMethod · 0.45
equalsMethod · 0.45

Tested by 1

testRoundTripMethod · 0.76