@Override public void unloadLstFiles(LoadContext lc, Collection<CampaignSourceEntry> files) { HashMapToList<Class<?>, CDOMSubLineLoader<?>> loaderMap = new HashMapToList<Class<?>, CDOMSubLineLoader<?>>(); for (CDOMSubLineLoader<?> loader : loadMap.values()) { loaderMap.addToListFor(loader.getLoadedClass(), loader); } for (CampaignSourceEntry cse : files) { lc.setExtractURI(cse.getURI()); URI writeURI = cse.getWriteURI(); File f = new File(writeURI); ensureCreated(f.getParentFile()); try { TreeSet<String> set = new TreeSet<String>(); for (Kit k : lc.getReferenceContext().getConstructedCDOMObjects(Kit.class)) { if (cse.getURI().equals(k.getSourceURI())) { StringBuilder sb = new StringBuilder(); String[] unparse = lc.unparseSubtoken(k, "*KITTOKEN"); sb.append("STARTPACK:"); sb.append(k.getDisplayName()); if (unparse != null) { sb.append('\t').append(StringUtil.join(unparse, "\t")); } sb.append('\n'); Changes<BaseKit> changes = lc.getObjectContext().getListChanges(k, ListKey.KIT_TASKS); Collection<BaseKit> tasks = changes.getAdded(); if (tasks == null) { continue; } for (BaseKit kt : tasks) { List<CDOMSubLineLoader<?>> loaders = loaderMap.getListFor(kt.getClass()); for (CDOMSubLineLoader loader : loaders) { processTask(lc, kt, loader, sb); } } sb.append('\n'); set.add(sb.toString()); } } PrintWriter pw = new PrintWriter(f); pw.println("#~PARAGRAPH"); for (String s : set) { pw.print(s); } pw.close(); } catch (IOException e) { Logging.errorPrint("Exception in Load: ", e); } } }
@Override protected ParseResult parseNonEmptyToken(LoadContext context, BaseKit kit, String value) { ParsingSeparator pipeSep = new ParsingSeparator(value, '|'); pipeSep.addGroupingPair('[', ']'); pipeSep.addGroupingPair('(', ')'); while (pipeSep.hasNext()) { String subTok = pipeSep.next(); if (subTok.length() == 0) { return new ParseResult.Fail( getTokenName() + " arguments has invalid pipe separator: " + value, context); } ParseResult pr = checkForIllegalSeparator(',', subTok); if (!pr.passed()) { return pr; } ParsingSeparator commaSep = new ParsingSeparator(subTok, ','); commaSep.addGroupingPair('[', ']'); commaSep.addGroupingPair('(', ')'); String minString = commaSep.next(); String maxString; if (commaSep.hasNext()) { maxString = commaSep.next(); } else { maxString = subTok; } if (commaSep.hasNext()) { return new ParseResult.Fail("Token cannot have more than one separator ','", context); } Formula min = FormulaFactory.getFormulaFor(minString); if (!min.isValid()) { return new ParseResult.Fail( "Min Formula in " + getTokenName() + " was not valid: " + min.toString(), context); } Formula max = FormulaFactory.getFormulaFor(maxString); if (!max.isValid()) { return new ParseResult.Fail( "Max Formula in " + getTokenName() + " was not valid: " + max.toString(), context); } kit.setOptionBounds(min, max); } return ParseResult.SUCCESS; }
@Override public String[] unparse(LoadContext context, BaseKit kit) { Collection<OptionBound> bounds = kit.getBounds(); if (bounds == null) { return null; } List<String> list = new ArrayList<>(); for (OptionBound bound : bounds) { Formula min = bound.getOptionMin(); Formula max = bound.getOptionMax(); if (min == null || max == null) { // Error if only one is null return null; } StringBuilder sb = new StringBuilder(); sb.append(min); if (!min.equals(max)) { sb.append(',').append(max); } list.add(sb.toString()); } return new String[] {StringUtil.join(list, Constants.PIPE)}; }