public static List<NamedValue> convertMapPairs(List<ome.xml.model.MapPair> map) { if (map == null) { return null; } final List<NamedValue> nvl = new ArrayList<NamedValue>(map.size()); for (final ome.xml.model.MapPair nv : map) { if (nv == null) { nvl.add(null); } else { final String name = nv.getName(); final String value = nv.getValue(); nvl.add(new NamedValue(name, value)); } } return nvl; }
protected Element asXMLElement(Document document, Element GenericExcitationSource_element) { // Creating XML block for GenericExcitationSource if (GenericExcitationSource_element == null) { GenericExcitationSource_element = document.createElementNS(NAMESPACE, "GenericExcitationSource"); } if (map != null) { // Element property Map which is complex (has // sub-elements) Element map_child = document.createElementNS(NAMESPACE, "Map"); for (MapPair entry: map) { Element pair = document.createElementNS(NAMESPACE, "M"); pair.setAttribute("K", entry.getName()); pair.setTextContent(entry.getValue()); map_child.appendChild(pair); } GenericExcitationSource_element.appendChild(map_child); } return super.asXMLElement(document, GenericExcitationSource_element); } }
Element pair = document.createElementNS(NAMESPACE, "M"); pair.setAttribute("K", entry.getName()); pair.setTextContent(entry.getValue()); map_child.appendChild(pair);
Element pair = document.createElementNS(NAMESPACE, "M"); pair.setAttribute("K", entry.getName()); pair.setTextContent(entry.getValue()); value_child.appendChild(pair);
Element pair = document.createElementNS(NAMESPACE, "M"); pair.setAttribute("K", entry.getName()); pair.setTextContent(entry.getValue()); value_child.appendChild(pair);
@Override public void setRoot(MetadataRoot root) { super.setRoot(root); // look for resolution data annotation int mapCount = 0; try { mapCount = getMapAnnotationCount(); } catch (NullPointerException e) { // no map annotations } for (int i=0; i<mapCount; i++) { if (NAMESPACE.equals(getMapAnnotationNamespace(i))) { List<MapPair> resAnnotation = getMapAnnotationValue(i); List<Resolution> r = new ArrayList<Resolution>(); r.add(new Resolution()); for (MapPair p : resAnnotation) { int index = Integer.parseInt(p.getName()); if (index == r.size()) { r.add(new Resolution(p.getValue())); } else LOGGER.warn("Out of order"); } resolutions.add(r); written = true; } } }
@Override public void setRoot(MetadataRoot root) { super.setRoot(root); // look for resolution data annotation int mapCount = 0; try { mapCount = getMapAnnotationCount(); } catch (NullPointerException e) { // no map annotations } for (int i=0; i<mapCount; i++) { if (NAMESPACE.equals(getMapAnnotationNamespace(i))) { List<MapPair> resAnnotation = getMapAnnotationValue(i); List<Resolution> r = new ArrayList<Resolution>(); r.add(new Resolution()); for (MapPair p : resAnnotation) { int index = Integer.parseInt(p.getName()); if (index == r.size()) { r.add(new Resolution(p.getValue())); } else LOGGER.warn("Out of order"); } resolutions.add(r); written = true; } } }
void assertPair(List<MapPair> dataMap, int idx, String name, String value) { assertEquals(name, dataMap.get(idx).getName()); assertEquals(value, dataMap.get(idx).getValue()); } }
void assertPair(List<MapPair> dataMap, int idx, String name, String value) { assertEquals(name, dataMap.get(idx).getName()); assertEquals(value, dataMap.get(idx).getValue()); }
Element pair = document.createElementNS(NAMESPACE, "M"); pair.setAttribute("K", entry.getName()); pair.setTextContent(entry.getValue()); map_child.appendChild(pair);
Element pair = document.createElementNS(NAMESPACE, "M"); pair.setAttribute("K", entry.getName()); pair.setTextContent(entry.getValue()); map_child.appendChild(pair);
@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()); }