Search in sources :

Example 1 with MapAnnotation

use of ome.xml.model.MapAnnotation in project bioformats by openmicroscopy.

the class MapAnnotationTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    // Add an Image/Pixels
    Image image = new Image();
    image.setID("Image:0");
    Pixels pixels = new Pixels();
    pixels.setID("Pixels:0");
    image.setPixels(pixels);
    // Add a Map Annotation
    List<MapPair> map = new ArrayList<MapPair>();
    map.add(new MapPair("a", "1"));
    map.add(new MapPair("d", "2"));
    map.add(new MapPair("c", "3"));
    map.add(new MapPair("b", "4"));
    map.add(new MapPair("e", "5"));
    map.add(new MapPair("c", "6"));
    MapAnnotation mapAnnotation = new MapAnnotation();
    mapAnnotation.setID("Annotation:0");
    mapAnnotation.setValue(map);
    StructuredAnnotations structuredAnnotations = new StructuredAnnotations();
    structuredAnnotations.addMapAnnotation(mapAnnotation);
    ome.setStructuredAnnotations(structuredAnnotations);
    image.linkAnnotation(mapAnnotation);
    ome.addImage(image);
}
Also used : MapPair(ome.xml.model.MapPair) MapAnnotation(ome.xml.model.MapAnnotation) ArrayList(java.util.ArrayList) StructuredAnnotations(ome.xml.model.StructuredAnnotations) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with MapAnnotation

use of ome.xml.model.MapAnnotation in project bioformats by openmicroscopy.

the class MapAnnotationTest method testMapAnnotationValueContent.

@Test
public void testMapAnnotationValueContent() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
    assertNotNull(ome);
    assertEquals(ome.getImage(0).getPixels().getID(), "Pixels:0");
    assertNotNull(ome.getImage(0).getLinkedAnnotation(0));
    MapAnnotation mapAnnotation = (MapAnnotation) ome.getImage(0).getLinkedAnnotation(0);
    List<MapPair> dataMap = mapAnnotation.getValue();
    assertEquals(6, dataMap.size());
    assertEquals("a", dataMap.get(0).getName());
    assertEquals("1", dataMap.get(0).getValue());
    assertEquals("d", dataMap.get(1).getName());
    assertEquals("2", dataMap.get(1).getValue());
    assertEquals("c", dataMap.get(2).getName());
    assertEquals("3", dataMap.get(2).getValue());
    assertEquals("b", dataMap.get(3).getName());
    assertEquals("4", dataMap.get(3).getValue());
    assertEquals("e", dataMap.get(4).getName());
    assertEquals("5", dataMap.get(4).getValue());
    assertEquals("c", dataMap.get(5).getName());
    assertEquals("6", dataMap.get(5).getValue());
}
Also used : MapPair(ome.xml.model.MapPair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MapAnnotation(ome.xml.model.MapAnnotation) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Aggregations

MapAnnotation (ome.xml.model.MapAnnotation)2 MapPair (ome.xml.model.MapPair)2 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Image (ome.xml.model.Image)1 OME (ome.xml.model.OME)1 OMEModel (ome.xml.model.OMEModel)1 OMEModelImpl (ome.xml.model.OMEModelImpl)1 Pixels (ome.xml.model.Pixels)1 StructuredAnnotations (ome.xml.model.StructuredAnnotations)1 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1