Changeset 7038


Ignore:
Timestamp:
10/06/10 15:02:00 (9 years ago)
Author:
melissa
Message:

Adjusted original metadata population, so that it doesn't take nearly as much time or memory. Closes #574, see #564.

Location:
trunk/components/bio-formats/src/loci/formats
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/FormatReader.java

    r6881 r7038  
    280280    } 
    281281 
    282     if (saveOriginalMetadata && simple && meta.equals(metadata)) { 
    283       MetadataStore store = getMetadataStore(); 
    284       if (store instanceof OMEXMLMetadata) { 
    285         try { 
    286           if (factory == null) factory = new ServiceFactory(); 
    287           if (service == null) { 
    288             service = factory.getInstance(OMEXMLService.class); 
    289           } 
    290           service.populateOriginalMetadata( 
    291             (OMEXMLMetadata) store, key, value.toString()); 
    292         } 
    293         catch (DependencyException e) { 
    294           LOGGER.warn("OMEXMLService not available.", e); 
    295         } 
    296       } 
    297     } 
    298  
    299282    meta.put(key, val == null ? value : val); 
    300283  } 
     
    10721055  /* @see IFormatHandler#setId(String) */ 
    10731056  public void setId(String id) throws FormatException, IOException { 
    1074     if (!id.equals(currentId)) initFile(id); 
     1057    if (!id.equals(currentId)) { 
     1058      initFile(id); 
     1059 
     1060      if (saveOriginalMetadata) { 
     1061        MetadataStore store = getMetadataStore(); 
     1062        if (store instanceof OMEXMLMetadata) { 
     1063          try { 
     1064            if (factory == null) factory = new ServiceFactory(); 
     1065            if (service == null) { 
     1066              service = factory.getInstance(OMEXMLService.class); 
     1067            } 
     1068            service.populateOriginalMetadata( 
     1069              (OMEXMLMetadata) store, metadata); 
     1070          } 
     1071          catch (DependencyException e) { 
     1072            LOGGER.warn("OMEXMLService not available.", e); 
     1073          } 
     1074        } 
     1075      } 
     1076    } 
    10751077  } 
    10761078 
  • trunk/components/bio-formats/src/loci/formats/services/OMEXMLService.java

    r6978 r7038  
    2323 
    2424package loci.formats.services; 
     25 
     26import java.util.Hashtable; 
    2527 
    2628import loci.common.services.Service; 
     
    2931import loci.formats.meta.MetadataStore; 
    3032import loci.formats.ome.OMEXMLMetadata; 
    31  
    3233 
    3334/** 
     
    159160 
    160161  /** 
     162   * Adds the key/value pairs in the specified Hashtable as new 
     163   * OriginalMetadata annotations in the given OME-XML metadata object. 
     164   * @param omexmlMeta An object of type 
     165   *   {@link loci.formats.ome.OMEXMLMetadata}. 
     166   * @param metadata A hashtable containing metadata key/value pairs. 
     167   */ 
     168  public void populateOriginalMetadata(OMEXMLMetadata omexmlMeta, 
     169    Hashtable<String, Object> metadata); 
     170 
     171  /** 
    161172   * Adds the specified key/value pair as a new OriginalMetadata node 
    162173   * to the given OME-XML metadata object. 
  • trunk/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java

    r7009 r7038  
    2525 
    2626import java.io.IOException; 
     27import java.util.Hashtable; 
    2728import java.util.List; 
    2829 
     
    5253import ome.xml.model.Pixels; 
    5354import ome.xml.model.StructuredAnnotations; 
     55import ome.xml.model.XMLAnnotation; 
    5456 
    5557import org.slf4j.Logger; 
     
    358360  } 
    359361 
     362  /** 
     363   * @see loci.formats.ome.OMEXMLService#populateOriginalMetadata(loci.formats.ome.OMEXMLMetadata, Hashtable<String, Object>) 
     364   */ 
     365  public void populateOriginalMetadata(OMEXMLMetadata omexmlMeta, 
     366    Hashtable<String, Object> metadata) 
     367  { 
     368    OME root = (OME) omexmlMeta.getRoot(); 
     369    StructuredAnnotations annotations = root.getStructuredAnnotations(); 
     370    if (annotations == null) annotations = new StructuredAnnotations(); 
     371    int annotationIndex = annotations.sizeOfXMLAnnotationList(); 
     372 
     373    for (String key : metadata.keySet()) { 
     374      XMLAnnotation annotation = new XMLAnnotation(); 
     375      annotation.setID(MetadataTools.createLSID("Annotation", annotationIndex)); 
     376      annotation.setValue(makeOriginalMetadata(key, metadata.get(key))); 
     377      annotations.addXMLAnnotation(annotation); 
     378      annotationIndex++; 
     379    } 
     380 
     381    root.setStructuredAnnotations(annotations); 
     382    omexmlMeta.setRoot(root); 
     383  } 
     384 
    360385  /* (non-Javadoc) 
    361386   * @see loci.formats.ome.OMEXMLService#populateOriginalMetadata(loci.formats.ome.OMEXMLMetadata, java.lang.String, java.lang.String) 
     
    366391    int annotationIndex = 0; 
    367392    try { 
    368       annotationIndex = omexmlMeta.getListAnnotationCount(); 
     393      annotationIndex = omexmlMeta.getXMLAnnotationCount(); 
    369394    } 
    370395    catch (NullPointerException e) { } 
    371     String listID = MetadataTools.createLSID("Annotation", annotationIndex * 3); 
    372     omexmlMeta.setListAnnotationID(listID, annotationIndex); 
    373     omexmlMeta.setListAnnotationNamespace( 
    374       StructuredAnnotations.NAMESPACE, annotationIndex); 
    375  
    376     int keyIndex = annotationIndex * 2; 
    377     int valueIndex = annotationIndex * 2 + 1; 
    378     String keyID = 
    379       MetadataTools.createLSID("Annotation", annotationIndex * 3 + 1); 
    380     String valueID = 
    381       MetadataTools.createLSID("Annotation", annotationIndex * 3 + 2); 
    382     omexmlMeta.setCommentAnnotationID(keyID, keyIndex); 
    383     omexmlMeta.setCommentAnnotationID(valueID, valueIndex); 
    384     omexmlMeta.setCommentAnnotationValue(key, keyIndex); 
    385     omexmlMeta.setCommentAnnotationValue(value, valueIndex); 
    386     omexmlMeta.setCommentAnnotationNamespace( 
    387       StructuredAnnotations.NAMESPACE, keyIndex); 
    388     omexmlMeta.setCommentAnnotationNamespace( 
    389       StructuredAnnotations.NAMESPACE, valueIndex); 
    390     omexmlMeta.setListAnnotationAnnotationRef(keyID, annotationIndex, 0); 
    391     omexmlMeta.setListAnnotationAnnotationRef(valueID, annotationIndex, 1); 
     396 
     397    String id = MetadataTools.createLSID("Annotation", annotationIndex); 
     398    omexmlMeta.setXMLAnnotationID(id, annotationIndex); 
     399    String xml = makeOriginalMetadata(key, value); 
     400    omexmlMeta.setXMLAnnotationValue(xml, annotationIndex); 
    392401  } 
    393402 
     
    485494  } 
    486495 
     496  /** Create an XML annotation for the given OriginalMetadata key/value pair. */ 
     497  private String makeOriginalMetadata(String key, Object value) { 
     498    return "<OriginalMetadata><Key>" + key + "</Key><Value>" + value + 
     499      "</Value></OriginalMetadata>"; 
     500  } 
     501 
    487502} 
Note: See TracChangeset for help on using the changeset viewer.