| 28 | import pcgen.util.Logging; |
| 29 | |
| 30 | public class CDOMKitLoader |
| 31 | { |
| 32 | private final Map<String, CDOMSubLineLoader<? extends BaseKit>> loadMap = new HashMap<>(); |
| 33 | |
| 34 | private final Class<Kit> targetClass = Kit.class; |
| 35 | |
| 36 | public void addLineLoader(CDOMSubLineLoader<? extends BaseKit> loader) |
| 37 | { |
| 38 | // TODO check null |
| 39 | // TODO check duplicate! |
| 40 | loadMap.put(loader.getPrefix(), loader); |
| 41 | } |
| 42 | |
| 43 | public boolean parseSubLine(LoadContext context, Kit obj, String val, URI source) |
| 44 | { |
| 45 | int sepLoc = val.indexOf('\t'); |
| 46 | String firstToken = (sepLoc == -1) ? val : val.substring(0, sepLoc); |
| 47 | int colonLoc = firstToken.indexOf(':'); |
| 48 | if (colonLoc == -1) |
| 49 | { |
| 50 | Logging.addParseMessage(Logging.LST_ERROR, |
| 51 | "Unsure what to do with line without " + "a colon in first token: " + val + " in file: " + source); |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | String prefix = firstToken.substring(0, colonLoc); |
| 56 | CDOMSubLineLoader<? extends BaseKit> loader = loadMap.get(prefix); |
| 57 | if (loader == null) |
| 58 | { |
| 59 | Logging.addParseMessage(Logging.LST_ERROR, |
| 60 | "Unsure what to do with line with prefix: " + prefix + ". Line was: " + val + " in file: " + source); |
| 61 | return false; |
| 62 | } |
| 63 | return subParse(context, obj, loader, val); |
| 64 | } |
| 65 | |
| 66 | private <CC extends BaseKit> boolean subParse(LoadContext context, Kit kit, CDOMSubLineLoader<CC> loader, |
| 67 | String line) |
| 68 | { |
| 69 | CC obj = loader.getCDOMObject(); |
| 70 | context.getObjectContext().addToList(kit, ListKey.KIT_TASKS, obj); |
| 71 | return loader.parseLine(context, obj, line); |
| 72 | } |
| 73 | |
| 74 | protected Kit getCDOMObject(LoadContext context, String name) |
| 75 | { |
| 76 | Kit obj = context.getReferenceContext().silentlyGetConstructedCDOMObject(targetClass, name); |
| 77 | if (obj == null) |
| 78 | { |
| 79 | obj = context.getReferenceContext().constructCDOMObject(targetClass, name); |
| 80 | } |
| 81 | return obj; |
| 82 | } |
| 83 | |
| 84 | public Class<Kit> getTargetClass() |
| 85 | { |
| 86 | return targetClass; |
| 87 | } |
nothing calls this directly
no outgoing calls
no test coverage detected