A CDOMControlLoader is a loader that processes the Data Definitions (initially FACT/FACTSET)
| 37 | * (initially FACT/FACTSET) |
| 38 | */ |
| 39 | public class CDOMControlLoader extends LstLineFileLoader |
| 40 | { |
| 41 | private final Map<String, CDOMSubLineLoader<?>> loadMap = new HashMap<>(); |
| 42 | |
| 43 | public CDOMControlLoader() |
| 44 | { |
| 45 | //CONSIDER a better way to load these? |
| 46 | addLineLoader(new CDOMSubLineLoader<>("FACTDEF", FactDefinition.class)); |
| 47 | addLineLoader(new CDOMSubLineLoader<>("FACTSETDEF", FactSetDefinition.class)); |
| 48 | addLineLoader(new CDOMSubLineLoader<>("DEFAULTVARIABLEVALUE", DefaultVarValue.class)); |
| 49 | addLineLoader(new CDOMSubLineLoader<>("FUNCTION", UserFunction.class)); |
| 50 | addLineLoader(new CDOMSubLineLoader<>("DYNAMICSCOPE", DynamicCategory.class)); |
| 51 | } |
| 52 | |
| 53 | private void addLineLoader(CDOMSubLineLoader<?> loader) |
| 54 | { |
| 55 | Objects.requireNonNull(loader, "Cannot add null loader to Control Loader"); |
| 56 | String prefix = loader.getPrefix(); |
| 57 | if (loadMap.containsKey(prefix)) |
| 58 | { |
| 59 | throw new IllegalArgumentException("Cannot add a second loader for prefix: " + prefix); |
| 60 | } |
| 61 | loadMap.put(loader.getPrefix(), loader); |
| 62 | } |
| 63 | |
| 64 | private boolean parseSubLine(LoadContext context, String val, URI source) |
| 65 | { |
| 66 | int sepLoc = val.indexOf('\t'); |
| 67 | String firstToken = (sepLoc == -1) ? val : val.substring(0, sepLoc); |
| 68 | int colonLoc = firstToken.indexOf(':'); |
| 69 | if (colonLoc == -1) |
| 70 | { |
| 71 | Logging.addParseMessage(Logging.LST_ERROR, |
| 72 | "Unsure what to do with line without " + "a colon in first token: " + val + " in file: " + source); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | String prefix = firstToken.substring(0, colonLoc); |
| 77 | CDOMSubLineLoader<?> loader = loadMap.get(prefix); |
| 78 | if (loader == null) |
| 79 | { |
| 80 | Logging.addParseMessage(Logging.LST_ERROR, |
| 81 | "Unsure what to do with line with prefix: " + prefix + ". Line was: " + val + " in file: " + source); |
| 82 | return false; |
| 83 | } |
| 84 | if (!subParse(context, loader, val)) |
| 85 | { |
| 86 | return false; |
| 87 | } |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | private <CC extends Loadable> boolean subParse(LoadContext context, CDOMSubLineLoader<CC> loader, String line) |
| 92 | { |
| 93 | int tabLoc = line.indexOf(SystemLoader.TAB_DELIM); |
| 94 | String lineIdentifier; |
| 95 | if (tabLoc == -1) |
| 96 | { |
nothing calls this directly
no outgoing calls
no test coverage detected