1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.loaders;
22
23 import org.millscript.commons.util.map.EHashMap;
24 import org.millscript.commons.vfs.VEntry;
25 import org.millscript.commons.vfs.VFolder;
26 import org.millscript.millscript.alert.Alerts;
27
28 import java.io.IOException;
29 import java.util.Iterator;
30 import java.util.List;
31
32 /**
33 * This class implements the MillScript map loader. The contents of the map
34 * directory are read, where each filename(without extension) is the key and
35 * the result of autoloading the file(based on extension) is the value.
36 */
37 public class MapLoader extends ValueLoader {
38
39 /**
40 * @see org.millscript.millscript.loaders.Loader#loadValue()
41 */
42 @Override
43 public Object loadValue() throws IOException {
44 if ( this.entry instanceof VFolder && this.entry.exists() ) {
45 EHashMap< String, Object > result = new EHashMap< String, Object >();
46 List entries = ((VFolder) this.entry).listEntries();
47 Iterator it = entries.iterator();
48 while ( it.hasNext() ) {
49 VEntry mapEntry = (VEntry) it.next();
50 Loader loader = this.pack.makeLoaderFor( mapEntry );
51 if ( loader != null ) {
52 result.insert(
53 loader.getSymbol(),
54 loader.loadValue()
55 );
56 }
57 }
58 return result;
59 } else {
60 throw(
61 Alerts.compile(
62 "Inventory entry is not a folder",
63 "Map loader can only be used to load folders"
64 ).culprit( "entry", this.entry ).mishap()
65 );
66 }
67 }
68
69 }