//
// EditImageName.java
//

import loci.formats.ImageReader;
import loci.formats.ome.OMEXMLMetadata;
import org.openmicroscopy.xml.ImageNode;
import org.openmicroscopy.xml.OMENode;

/** Edits the given file's image name (but does not save back to disk). */
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(new OMEXMLMetadata());
    String id = args[0];
    System.out.print("Reading metadata ");
    reader.setId(id); 
    OMEXMLMetadata store = (OMEXMLMetadata) reader.getMetadataStore();
    System.out.println(" [done]");
    // get OME root node
    OMENode ome = (OMENode) store.getRoot();
    // get first Image node
    ImageNode image = (ImageNode) ome.getImages().get(0);
    // get Image name
    String name = image.getName();
    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
    image.setName(name);
    System.out.println("Updated Image name = " + name);
    // output full OME-XML block
    System.out.println("Full OME-XML dump:");
    System.out.println(ome.writeOME(false));
  }

}

@@ -79,26 +79,16 @@
 ats.
-ome.OMEXML
 Metadata
 ;%0Aim
@@ -83,16 +83,21 @@
 Metadata
+Tools
 ;%0Aimport
@@ -101,79 +101,39 @@
 ort 
-org.openmicroscopy.xml.ImageNode;%0Aimport org.openmicroscopy.xml.OMENode
+loci.formats.ome.OMEXMLMetadata
 ;%0A%0A/
@@ -650,21 +650,26 @@
 etadata 
-store
+omexmlMeta
  = (OMEX
@@ -746,77 +746,8 @@
 %22);%0A
-    // get OME root node%0A    OMENode ome = (OMENode) store.getRoot();
 %0A   
@@ -758,78 +758,49 @@
 get 
-first I
+i
 mage n
-od
+am
 e%0A    I
-mageNode image = (ImageNode) ome.getImages().get
+nteger zero = new Integer
 (0);
@@ -808,58 +808,50 @@
     
-// get Image name%0A    String name = image.get
+String name = omexmlMeta.getImage
 Name(
+zero
 );%0A 
@@ -919,17 +919,17 @@
  change 
-I
+i
 mage nam
@@ -1235,26 +1235,50 @@
     
-image.setName(name
+omexmlMeta.setImage(name, null, null, zero
 );%0A 
@@ -1438,26 +1438,42 @@
 tln(
-ome.writeOME(false
+MetadataTools.getOMEXML(omexmlMeta
 ));%0A

Update code to use most recent API.