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);
}
}
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);
}
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();
}
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;
}
}
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;
}
Aggregations