Search in sources :

Example 6 with ServiceException

use of loci.common.services.ServiceException in project bioformats by openmicroscopy.

the class OMEXMLServiceImpl method createRoot.

/**
 * Constructs an OME root node. <b>NOTE:</b> This method is mostly here to
 * ensure type safety of return values as instances of service dependency
 * classes should not leak out of the interface.
 * @param xml String of XML to create the root node from.
 * @return An ome.xml.model.OMEModelObject subclass root node.
 * @throws IOException If there is an error reading from the string.
 * @throws SAXException If there is an error parsing the XML.
 * @throws ParserConfigurationException If there is an error preparing the
 * parsing infrastructure.
 */
private OMEXMLMetadataRoot createRoot(String xml) throws ServiceException {
    try {
        OMEModel model = new OMEModelImpl();
        OMEXMLMetadataRoot ome = new OMEXMLMetadataRoot(XMLTools.parseDOM(xml).getDocumentElement(), model);
        model.resolveReferences();
        return ome;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(loci.common.services.ServiceException) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) ServiceException(loci.common.services.ServiceException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 7 with ServiceException

use of loci.common.services.ServiceException in project bioformats by openmicroscopy.

the class ImageViewer method open.

/**
 * Opens the given data source using the current format reader.
 */
public void open(String id) {
    wait(true);
    try {
        // Location f = new Location(id);
        // id = f.getAbsolutePath();
        IMetadata meta = null;
        if (omexmlService != null) {
            try {
                meta = omexmlService.createOMEXMLMetadata();
                myReader.setMetadataStore(meta);
            } catch (ServiceException exc) {
                LOGGER.debug("Could not create OME-XML metadata", exc);
            }
        }
        if (meta == null) {
            LOGGER.info("OME metadata unavailable");
        }
        myReader.setId(id);
        int num = myReader.getImageCount();
        ProgressMonitor progress = new ProgressMonitor(this, "Reading " + id, null, 0, num + 1);
        sizeZ = myReader.getSizeZ();
        sizeT = myReader.getSizeT();
        sizeC = myReader.getEffectiveSizeC();
        // if (myReader.isRGB(id)) sizeC = (sizeC + 2) / 3; // adjust for RGB
        progress.setProgress(1);
        BufferedImage[] img = new BufferedImage[num];
        for (int i = 0; i < num; i++) {
            if (progress.isCanceled())
                break;
            img[i] = myReader.openImage(i);
            if (i == 0)
                setImages(myReader, img);
            progress.setProgress(i + 2);
        }
        myReader.close(true);
    } catch (FormatException exc) {
        LOGGER.info("", exc);
        wait(false);
        return;
    } catch (IOException exc) {
        LOGGER.info("", exc);
        wait(false);
        return;
    }
    wait(false);
}
Also used : ProgressMonitor(javax.swing.ProgressMonitor) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) FormatException(loci.formats.FormatException)

Example 8 with ServiceException

use of loci.common.services.ServiceException in project bioformats by openmicroscopy.

the class PrintROIs method main.

public static void main(String[] args) throws Exception {
    ImageReader reader = new ImageReader();
    IMetadata omexml;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        omexml = service.createOMEXMLMetadata();
    } catch (DependencyException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    } catch (ServiceException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    }
    reader.setMetadataStore(omexml);
    reader.setId(args[0]);
    printAllROIs(omexml);
    System.out.println();
    for (int series = 0; series < reader.getSeriesCount(); series++) {
        printSeriesROIs(omexml, series);
    }
    reader.close();
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) Point(ome.xml.model.Point)

Example 9 with ServiceException

use of loci.common.services.ServiceException in project bioformats by openmicroscopy.

the class NetCDFServiceImpl method getArray.

/* (non-Javadoc)
   * @see loci.formats.NetCDFService#getArray(java.lang.String, int[], int[])
   */
@Override
public Object getArray(String path, int[] origin, int[] shape) throws ServiceException {
    String groupName = getDirectory(path);
    String variableName = getName(path);
    Group group = getGroup(groupName);
    Variable variable = group.findVariable(variableName);
    try {
        if (origin != null && shape != null) {
            return variable.read(origin, shape).reduce().copyToNDJavaArray();
        }
        return variable.read().copyToNDJavaArray();
    } catch (InvalidRangeException e) {
        throw new ServiceException(e);
    } catch (IOException e) {
        throw new ServiceException(e);
    } catch (NullPointerException e) {
        return null;
    }
}
Also used : Group(ucar.nc2.Group) Variable(ucar.nc2.Variable) ServiceException(loci.common.services.ServiceException) InvalidRangeException(ucar.ma2.InvalidRangeException) IOException(java.io.IOException)

Example 10 with ServiceException

use of loci.common.services.ServiceException in project bioformats by openmicroscopy.

the class CellWorxReader method getReader.

private IFormatReader getReader(String file, boolean omexml) throws FormatException, IOException {
    IFormatReader pnl = new DeltavisionReader();
    if (checkSuffix(file, "tif")) {
        pnl = new MetamorphReader();
    }
    if (omexml) {
        IMetadata metadata;
        try {
            metadata = service.createOMEXMLMetadata();
        } catch (ServiceException exc) {
            throw new FormatException("Could not create OME-XML store.", exc);
        }
        pnl.setMetadataStore(metadata);
    }
    pnl.setId(file);
    return pnl;
}
Also used : IFormatReader(loci.formats.IFormatReader) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) FormatException(loci.formats.FormatException)

Aggregations

ServiceException (loci.common.services.ServiceException)54 FormatException (loci.formats.FormatException)40 DependencyException (loci.common.services.DependencyException)34 ServiceFactory (loci.common.services.ServiceFactory)30 OMEXMLService (loci.formats.services.OMEXMLService)29 IOException (java.io.IOException)21 IMetadata (loci.formats.meta.IMetadata)16 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)12 Location (loci.common.Location)11 PositiveInteger (ome.xml.model.primitives.PositiveInteger)11 File (java.io.File)10 ImageReader (loci.formats.ImageReader)10 MetadataStore (loci.formats.meta.MetadataStore)10 CoreMetadata (loci.formats.CoreMetadata)9 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)9 EnumerationException (ome.xml.model.enums.EnumerationException)9 RandomAccessInputStream (loci.common.RandomAccessInputStream)7 MissingLibraryException (loci.formats.MissingLibraryException)7 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 SAXException (org.xml.sax.SAXException)6