//
// EditImageName.java
//

import loci.formats.ImageReader;
import loci.formats.MetadataTools;
import loci.formats.meta.MetadataRetrieve;
import loci.formats.meta.MetadataStore;

/**
 * Edits the given file's image name (but does not save back to disk).
 *
 * <dl><dt><b>Source code:</b></dt>
 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/bio-formats/utils/EditImageName.java">Trac</a>,
 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/bio-formats/utils/EditImageName.java">SVN</a></dd></dl>
 */
public class EditImageName {

  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.out.println("Usage: java EditImageName file");
      return;
    }
    ImageReader reader = new ImageReader();
    // record metadata to OME-XML format
    reader.setMetadataStore(MetadataTools.createOMEXMLMetadata());
    String id = args[0];
    System.out.print("Reading metadata ");
    reader.setId(id);
    MetadataStore omexmlMeta = reader.getMetadataStore();
    System.out.println(" [done]");

    // get image name
    String name = ((MetadataRetrieve) omexmlMeta).getImageName(0);
    System.out.println("Initial Image name = " + name);
    // change image name (reverse it)
    char[] arr = name.toCharArray();
    for (int i=0; i<arr.length/2; i++) {
      int i2 = arr.length - i - 1;
      char c = arr[i];
      char c2 = arr[i2];
      arr[i] = c2;
      arr[i2] = c;
    }
    name = new String(arr);
    // save altered name back to OME-XML structure
    omexmlMeta.setImageName(name, 0);
    System.out.println("Updated Image name = " + name);
    // output full OME-XML block
    System.out.println("Full OME-XML dump:");
    String xml = MetadataTools.getOMEXML((MetadataRetrieve) omexmlMeta);
    System.out.println(xml);
  }

}

@@ -115,24 +115,25 @@
 ts.meta.
+I
 Metadata
 Retrieve
@@ -128,56 +128,8 @@
 data
-Retrieve;%0Aimport loci.formats.meta.MetadataStore
 ;%0A%0A/
@@ -801,32 +801,31 @@
     
-reader.setMetadataStore(
+IMetadata omexmlMeta = 
 Meta
@@ -856,16 +856,56 @@
 tadata()
+;%0A    reader.setMetadataStore(omexmlMeta
 );%0A    S
@@ -993,66 +993,8 @@
 d);%0A
-    MetadataStore omexmlMeta = reader.getMetadataStore();%0A
     
@@ -1068,28 +1068,8 @@
 me =
- ((MetadataRetrieve)
  ome
@@ -1075,17 +1075,16 @@
 exmlMeta
-)
 .getImag
@@ -1689,27 +1689,8 @@
 XML(
-(MetadataRetrieve) 
 omex

Update EditImageName example to use IMetadata interface.