Search in sources :

Example 91 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project asterixdb by apache.

the class TestHelper method getConfigurations.

public static AsterixConfiguration getConfigurations(String fileName) throws IOException, JAXBException, AsterixException {
    try (InputStream is = TestHelper.class.getClassLoader().getResourceAsStream(fileName)) {
        if (is != null) {
            JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
            Unmarshaller unmarshaller = ctx.createUnmarshaller();
            return (AsterixConfiguration) unmarshaller.unmarshal(is);
        } else {
            throw new AsterixException("Could not find configuration file " + fileName);
        }
    }
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 92 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project asterixdb by apache.

the class Utils method loadAsterixConfig.

public static AsterixConfiguration loadAsterixConfig(String path) throws IOException {
    File f = new File(path);
    try {
        JAXBContext configCtx = JAXBContext.newInstance(AsterixConfiguration.class);
        Unmarshaller unmarshaller = configCtx.createUnmarshaller();
        AsterixConfiguration conf = (AsterixConfiguration) unmarshaller.unmarshal(f);
        return conf;
    } catch (JAXBException e) {
        throw new IOException(e);
    }
}
Also used : AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 93 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project asterixdb by apache.

the class AsterixInstallerIntegrationUtil method initZookeeperTestConfiguration.

private static void initZookeeperTestConfiguration(int port) throws JAXBException, FileNotFoundException {
    String installerConfPath = InstallerDriver.getManagixHome() + File.separator + InstallerDriver.MANAGIX_CONF_XML;
    JAXBContext ctx = JAXBContext.newInstance(Configuration.class);
    Unmarshaller unmarshaller = ctx.createUnmarshaller();
    Configuration configuration = (Configuration) unmarshaller.unmarshal(new File(installerConfPath));
    configuration.getZookeeper().setClientPort(new BigInteger("" + port));
    Marshaller marshaller = ctx.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(configuration, new FileOutputStream(installerConfPath));
}
Also used : Marshaller(javax.xml.bind.Marshaller) Configuration(org.apache.asterix.installer.schema.conf.Configuration) FileOutputStream(java.io.FileOutputStream) BigInteger(java.math.BigInteger) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 94 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project asterixdb by apache.

the class InstallerUtil method getAsterixConfiguration.

public static AsterixConfiguration getAsterixConfiguration(String asterixConf) throws FileNotFoundException, IOException, JAXBException {
    if (asterixConf == null) {
        asterixConf = InstallerDriver.getManagixHome() + File.separator + DEFAULT_ASTERIX_CONFIGURATION_PATH;
    }
    File file = new File(asterixConf);
    JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
    Unmarshaller unmarshaller = ctx.createUnmarshaller();
    AsterixConfiguration asterixConfiguration = (AsterixConfiguration) unmarshaller.unmarshal(file);
    return asterixConfiguration;
}
Also used : AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 95 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project asterixdb by apache.

the class TestSuiteParser method parse.

public org.apache.asterix.testframework.xml.TestSuite parse(File testSuiteCatalog) throws Exception {
    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    saxParserFactory.setXIncludeAware(true);
    SAXParser saxParser = saxParserFactory.newSAXParser();
    saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "file");
    JAXBContext ctx = JAXBContext.newInstance(org.apache.asterix.testframework.xml.TestSuite.class);
    Unmarshaller um = ctx.createUnmarshaller();
    return (org.apache.asterix.testframework.xml.TestSuite) um.unmarshal(new SAXSource(saxParser.getXMLReader(), new InputSource(testSuiteCatalog.toURI().toString())));
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXParser(javax.xml.parsers.SAXParser) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

Unmarshaller (javax.xml.bind.Unmarshaller)292 JAXBContext (javax.xml.bind.JAXBContext)240 JAXBException (javax.xml.bind.JAXBException)97 InputStream (java.io.InputStream)91 Test (org.junit.Test)79 StringReader (java.io.StringReader)40 BaseTest (org.orcid.core.BaseTest)39 V2Convertible (org.orcid.core.version.V2Convertible)39 File (java.io.File)33 InputSource (org.xml.sax.InputSource)22 IOException (java.io.IOException)21 JAXBElement (javax.xml.bind.JAXBElement)18 Marshaller (javax.xml.bind.Marshaller)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParserFactory (javax.xml.parsers.SAXParserFactory)13 XMLInputFactory (javax.xml.stream.XMLInputFactory)13 XMLStreamException (javax.xml.stream.XMLStreamException)13 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Schema (javax.xml.validation.Schema)13