@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { HeaderSource headerSource = (HeaderSource) source; writer.addAttribute("name", headerSource.getName()); writer.addAttribute("description", headerSource.getDescription()); writer.addAttribute("optional", Boolean.toString(headerSource.isOptional())); writer.setValue(headerSource.getLocation()); }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { HeaderSource headerSource = new HeaderSource(); headerSource.setName(reader.getAttribute("name")); headerSource.setDescription(reader.getAttribute("description")); headerSource.setOptional(Boolean.parseBoolean(reader.getAttribute("optional"))); headerSource.setLocation(reader.getValue()); return headerSource; } }
private static ArrayList<String> createSourceDescriptionLines(HeaderSource headerSource) { final ArrayList<String> descriptionLines = new ArrayList<>(); final String description = headerSource.getDescription(); if (!(description == null || description.isEmpty())) { descriptionLines.add(description); } else { descriptionLines.add(MessageFormat.format("Sets source ''{0}'' to <filepath>.", headerSource.getName())); } if (headerSource.isOptional()) { descriptionLines.add("This is an optional source."); } else { descriptionLines.add("This is a mandatory source."); } return descriptionLines; }
private static boolean isSourceNodeIdInHeader(String sourceNodeId, List<HeaderSource> headerSources) { for (HeaderSource headerSource : headerSources) { if (sourceNodeId.equals(headerSource.getName())) { return true; } } return false; }
private static ArrayList<DocElement> createSourceDocElementList(List<HeaderSource> sources) { ArrayList<DocElement> docElementList = new ArrayList<>(10); for (HeaderSource headerSource : sources) { String sourceSyntax = MessageFormat.format(" -S{0}=<file>", headerSource.getName()); final ArrayList<String> descriptionLines = createSourceDescriptionLines(headerSource); docElementList.add(new DocElement(sourceSyntax, descriptionLines.toArray(new String[descriptionLines.size()]))); } sortAlphabetically(docElementList); return docElementList; }
assertNotNull(sources); assertEquals(2, sources.size()); assertEquals("input1", sources.get(0).getName()); assertEquals(true, sources.get(0).isOptional()); assertEquals("AATSR L1b TOA", sources.get(0).getDescription()); assertEquals("input2", sources.get(1).getName()); assertEquals(false, sources.get(1).isOptional()); assertEquals("C:\\data\\x.dim", sources.get(1).getLocation());