MaskPersistable implements DimapPersistable { @Override public final Mask createObjectFromXml(Element element, Product product) { final String name = getChildAttributeValue(element, TAG_NAME, ATTRIB_VALUE); final int width = product.getSceneRasterWidth(); final int height = product.getSceneRasterHeight(); final Mask mask = new Mask(name, width, height, createImageType()); mask.setDescription(getChildAttributeValue(element, TAG_DESCRIPTION, ATTRIB_VALUE)); mask.setImageTransparency(Double.parseDouble(getChildAttributeValue(element, TAG_TRANSPARENCY, ATTRIB_VALUE))); final int r = Integer.parseInt(getChildAttributeValue(element, TAG_COLOR, ATTRIB_RED)); final int g = Integer.parseInt(getChildAttributeValue(element, TAG_COLOR, ATTRIB_GREEN)); final int b = Integer.parseInt(getChildAttributeValue(element, TAG_COLOR, ATTRIB_BLUE)); final int a = Integer.parseInt(getChildAttributeValue(element, TAG_COLOR, ATTRIB_ALPHA)); mask.setImageColor(new Color(r, g, b, a)); configureMask(mask, element); return mask; }  @Override final Mask createObjectFromXml(Element element, Product product); @Override final Element createXmlFromObject(Object object);  }
@Test public void testMaskCreation() throws IOException, JDOMException { final DimapPersistable persistable = new TestMaskPersistable(); final InputStream resourceStream = getClass().getResourceAsStream("TestMask.xml"); final Document document = new SAXBuilder().build(resourceStream); final Product product = new Product("P", "T", 10, 10); final Mask maskFromXml = (Mask) persistable.createObjectFromXml(document.getRootElement(), product); assertNotNull(maskFromXml); assertEquals(TestImageType.class, maskFromXml.getImageType().getClass()); assertEquals(10, maskFromXml.getSceneRasterWidth()); assertEquals(10, maskFromXml.getSceneRasterHeight()); assertEquals("Bibo", maskFromXml.getName()); assertEquals("A big yellow bird is in the pixel.", maskFromXml.getDescription()); assertEquals(0.7, maskFromXml.getImageTransparency(), 0.0); assertEquals(new Color(17, 11, 67), maskFromXml.getImageColor()); }