@Test public void testXmlCreationWithoutMaskDescription() { final Mask mask = new Mask("name", 10, 10, new TestImageType()); mask.setDescription(null); final DimapPersistable persistable = new TestMaskPersistable(); final Element element = persistable.createXmlFromObject(mask); final Element description = element.getChild(TAG_DESCRIPTION); assertNotNull(description); assertTrue(description.getAttribute(ATTRIB_VALUE).getValue().isEmpty()); }
@Override public final Element createXmlFromObject(Object object) { final Mask mask = (Mask) object; final Element root = new Element(TAG_MASK); root.setAttribute(ATTRIB_TYPE, mask.getImageType().getName()); final PropertyContainer config = mask.getImageConfig(); root.addContent(createElement(TAG_NAME, mask.getName())); root.addContent(createElement(TAG_DESCRIPTION, mask.getDescription())); final Element colorElement = new Element(TAG_COLOR); final Color color = (Color) config.getValue(Mask.ImageType.PROPERTY_NAME_COLOR); colorElement.setAttribute(ATTRIB_RED, String.valueOf(color.getRed())); colorElement.setAttribute(ATTRIB_GREEN, String.valueOf(color.getGreen())); colorElement.setAttribute(ATTRIB_BLUE, String.valueOf(color.getBlue())); colorElement.setAttribute(ATTRIB_ALPHA, String.valueOf(color.getAlpha())); root.addContent(colorElement); Object transparencyValue = config.getValue(Mask.ImageType.PROPERTY_NAME_TRANSPARENCY); final String transparency = String.valueOf(transparencyValue); root.addContent(createElement(TAG_TRANSPARENCY, transparency)); configureElement(root, mask); return root; }
MaskPersistable implements DimapPersistable { @Override public final Element createXmlFromObject(Object object) { final Mask mask = (Mask) object; final Element root = new Element(TAG_MASK); root.setAttribute(ATTRIB_TYPE, mask.getImageType().getName()); final PropertyContainer config = mask.getImageConfig(); root.addContent(createElement(TAG_NAME, mask.getName())); root.addContent(createElement(TAG_DESCRIPTION, mask.getDescription())); final Element colorElement = new Element(TAG_COLOR); final Color color = (Color) config.getValue(Mask.ImageType.PROPERTY_NAME_COLOR); colorElement.setAttribute(ATTRIB_RED, String.valueOf(color.getRed())); colorElement.setAttribute(ATTRIB_GREEN, String.valueOf(color.getGreen())); colorElement.setAttribute(ATTRIB_BLUE, String.valueOf(color.getBlue())); colorElement.setAttribute(ATTRIB_ALPHA, String.valueOf(color.getAlpha())); root.addContent(colorElement); Object transparencyValue = config.getValue(Mask.ImageType.PROPERTY_NAME_TRANSPARENCY); final String transparency = String.valueOf(transparencyValue); root.addContent(createElement(TAG_TRANSPARENCY, transparency)); configureElement(root, mask); return root; } }
MaskPersistable implements DimapPersistable { @Override public final Element createXmlFromObject(Object object) { final Mask mask = (Mask) object; final Element root = new Element(TAG_MASK); root.setAttribute(ATTRIB_TYPE, mask.getImageType().getName()); final PropertyContainer config = mask.getImageConfig(); root.addContent(createElement(TAG_NAME, mask.getName())); root.addContent(createElement(TAG_DESCRIPTION, mask.getDescription())); final Element colorElement = new Element(TAG_COLOR); final Color color = (Color) config.getValue(Mask.ImageType.PROPERTY_NAME_COLOR); colorElement.setAttribute(ATTRIB_RED, String.valueOf(color.getRed())); colorElement.setAttribute(ATTRIB_GREEN, String.valueOf(color.getGreen())); colorElement.setAttribute(ATTRIB_BLUE, String.valueOf(color.getBlue())); colorElement.setAttribute(ATTRIB_ALPHA, String.valueOf(color.getAlpha())); root.addContent(colorElement); Object transparencyValue = config.getValue(Mask.ImageType.PROPERTY_NAME_TRANSPARENCY); final String transparency = String.valueOf(transparencyValue); root.addContent(createElement(TAG_TRANSPARENCY, transparency)); configureElement(root, mask); return root; }  }
MaskPersistable implements DimapPersistable { @Override public final Element createXmlFromObject(Object object) { final Mask mask = (Mask) object; final Element root = new Element(TAG_MASK); root.setAttribute(ATTRIB_TYPE, mask.getImageType().getName()); final PropertyContainer config = mask.getImageConfig(); root.addContent(createElement(TAG_NAME, mask.getName())); root.addContent(createElement(TAG_DESCRIPTION, mask.getDescription())); final Element colorElement = new Element(TAG_COLOR); final Color color = (Color) config.getValue(Mask.ImageType.PROPERTY_NAME_COLOR); colorElement.setAttribute(ATTRIB_RED, String.valueOf(color.getRed())); colorElement.setAttribute(ATTRIB_GREEN, String.valueOf(color.getGreen())); colorElement.setAttribute(ATTRIB_BLUE, String.valueOf(color.getBlue())); colorElement.setAttribute(ATTRIB_ALPHA, String.valueOf(color.getAlpha())); root.addContent(colorElement); Object transparencyValue = config.getValue(Mask.ImageType.PROPERTY_NAME_TRANSPARENCY); final String transparency = String.valueOf(transparencyValue); root.addContent(createElement(TAG_TRANSPARENCY, transparency)); configureElement(root, mask); return root; }  @Override final Mask createObjectFromXml(Element element, Product product); @Override final Element createXmlFromObject(Object object); }
MaskPersistable implements DimapPersistable { @Override public final Element createXmlFromObject(Object object) { final Mask mask = (Mask) object; final Element root = new Element(TAG_MASK); root.setAttribute(ATTRIB_TYPE, mask.getImageType().getName()); final PropertyContainer config = mask.getImageConfig(); root.addContent(createElement(TAG_NAME, mask.getName())); root.addContent(createElement(TAG_DESCRIPTION, mask.getDescription())); final Element colorElement = new Element(TAG_COLOR); final Color color = (Color) config.getValue(Mask.ImageType.PROPERTY_NAME_COLOR); colorElement.setAttribute(ATTRIB_RED, String.valueOf(color.getRed())); colorElement.setAttribute(ATTRIB_GREEN, String.valueOf(color.getGreen())); colorElement.setAttribute(ATTRIB_BLUE, String.valueOf(color.getBlue())); colorElement.setAttribute(ATTRIB_ALPHA, String.valueOf(color.getAlpha())); root.addContent(colorElement); Object transparencyValue = config.getValue(Mask.ImageType.PROPERTY_NAME_TRANSPARENCY); final String transparency = String.valueOf(transparencyValue); root.addContent(createElement(TAG_TRANSPARENCY, transparency)); configureElement(root, mask); return root; }  @Override final Mask createObjectFromXml(Element element, Product product); @Override final Element createXmlFromObject(Object object);  }