Search in sources :

Example 1 with OMEModelImpl

use of ome.xml.model.OMEModelImpl 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 2 with OMEModelImpl

use of ome.xml.model.OMEModelImpl in project bioformats by openmicroscopy.

the class XMLAnnotationTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.parse(this.getClass().getResourceAsStream("XMLAnnotationTest.ome"));
    OMEModel model = new OMEModelImpl();
    // Read string XML in as a DOM tree and parse into the object hierarchy
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with OMEModelImpl

use of ome.xml.model.OMEModelImpl in project bioformats by openmicroscopy.

the class GenericExcitationMapTest method testGenericExcitationSourceMapContent.

@Test
public void testGenericExcitationSourceMapContent() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
    assertNotNull(ome);
    assertEquals(ome.getImage(0).getPixels().getChannel(0).getLightSourceSettings().getID(), "LightSource:0");
    assertNotNull(ome.getInstrument(0).getLightSource(0));
    GenericExcitationSource geSource = (GenericExcitationSource) ome.getInstrument(0).getLightSource(0);
    List<MapPair> dataMap = geSource.getMap();
    assertEquals(6, dataMap.size());
    assertPair(dataMap, 0, "a", "1");
    assertPair(dataMap, 1, "d", "2");
    assertPair(dataMap, 2, "c", "3");
    assertPair(dataMap, 3, "b", "4");
    assertPair(dataMap, 4, "e", "5");
    assertPair(dataMap, 5, "c", "6");
}
Also used : MapPair(ome.xml.model.MapPair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) GenericExcitationSource(ome.xml.model.GenericExcitationSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Example 4 with OMEModelImpl

use of ome.xml.model.OMEModelImpl in project bioformats by openmicroscopy.

the class GenericExcitationMapTest method testGenericExcitationSourceValid.

@Test
public void testGenericExcitationSourceValid() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Example 5 with OMEModelImpl

use of ome.xml.model.OMEModelImpl in project bioformats by openmicroscopy.

the class ImagingEnvironmentMapTest method testGenericExcitationSourceMapContent.

@Test
public void testGenericExcitationSourceMapContent() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
    assertNotNull(ome);
    assertEquals(ome.getImage(0).getPixels().getID(), "Pixels:0");
    assertNotNull(ome.getImage(0).getImagingEnvironment());
    ImagingEnvironment imagingEnvironment = ome.getImage(0).getImagingEnvironment();
    List<MapPair> dataMap = imagingEnvironment.getMap();
    assertEquals(6, dataMap.size());
    assertPair(dataMap, 0, "a", "1");
    assertPair(dataMap, 1, "d", "2");
    assertPair(dataMap, 2, "c", "3");
    assertPair(dataMap, 3, "b", "4");
    assertPair(dataMap, 4, "e", "5");
    assertPair(dataMap, 5, "c", "6");
}
Also used : MapPair(ome.xml.model.MapPair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) ImagingEnvironment(ome.xml.model.ImagingEnvironment) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Aggregations

OMEModelImpl (ome.xml.model.OMEModelImpl)10 OMEModel (ome.xml.model.OMEModel)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 OME (ome.xml.model.OME)8 Test (org.testng.annotations.Test)8 Document (org.w3c.dom.Document)8 Element (org.w3c.dom.Element)7 MapPair (ome.xml.model.MapPair)3 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)2 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 ServiceException (loci.common.services.ServiceException)1 GenericExcitationSource (ome.xml.model.GenericExcitationSource)1 ImagingEnvironment (ome.xml.model.ImagingEnvironment)1 MapAnnotation (ome.xml.model.MapAnnotation)1 BeforeClass (org.testng.annotations.BeforeClass)1 SAXException (org.xml.sax.SAXException)1