Legend { public void marshall(Writer writer) { try { JAXBContext context = JAXBContext.newInstance( Legend.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(this, writer); } catch (JAXBException e) { e.printStackTrace(); } }  String getName(); void setName(String name); LegendComponent getLegendRoot(); void setLegendRoot(LegendComponent root); List<Map> getMaps(); void setMaps(List<Map> L); void addMap(Map O); void removeMap(Map O); SemanticRelationDescriptor getSRD(); void setSRD(SemanticRelationDescriptor srd); LegendLeaf getLeaf(String name); LegendComponent getComponent(String name); LegendComposite getTheme(String name); static void buildLegend(LegendComposite container, LegendComponent legendComponent); static Legend unmarshall(InputStream stream); static Legend unmarshall(String fileName); static Legend unmarshall(File file); static Legend unmarshall(StringReader reader); void marshall(Writer writer); void marshall(OutputStream stream); void marshall(String fileName); @Override String toString(); List<LegendComposite> getThemes(); List<LegendLeaf> getLeaves();  }
@Test public void testMarshall() { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; db = dbf.newDocumentBuilder(); Legend legend = new Legend(); legend.setName("Legend"); LegendLeaf leaf = new LegendLeaf(); leaf.setName("Vegetation"); LegendComposite root = new LegendComposite(); root.setName("LegendRoot"); root.addComponent(leaf); legend.setLegendRoot(root); } catch (Exception e) { e.printStackTrace(); } }