Search in sources :

Example 96 with Unmarshaller

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

the class PropertiesAccessor method configure.

private AsterixConfiguration configure(InputStream is, String fileName) throws AsterixException {
    try {
        JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
        Unmarshaller unmarshaller = ctx.createUnmarshaller();
        return (AsterixConfiguration) unmarshaller.unmarshal(is);
    } catch (JAXBException e) {
        throw new AsterixException("Failed to read configuration file " + fileName, e);
    }
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 97 with Unmarshaller

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

the class ExternalLibraryUtils method getLibrary.

/**
     * Get the library from the xml file
     *
     * @param libraryXMLPath
     * @return
     * @throws Exception
     */
private static ExternalLibrary getLibrary(File libraryXMLPath) throws Exception {
    JAXBContext configCtx = JAXBContext.newInstance(ExternalLibrary.class);
    Unmarshaller unmarshaller = configCtx.createUnmarshaller();
    ExternalLibrary library = (ExternalLibrary) unmarshaller.unmarshal(libraryXMLPath);
    return library;
}
Also used : ExternalLibrary(org.apache.asterix.external.library.ExternalLibrary) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 98 with Unmarshaller

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

the class ConfigureConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    configureCluster("local", "local.xml");
    configureCluster("local", "local_chained_declustering_rep.xml");
    configureCluster("local", "local_metadata_only_rep.xml");
    configureCluster("demo", "demo.xml");
    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.setConfigured(true);
    configuration.getBackup().setBackupDir(InstallerDriver.getManagixHome() + File.separator + "backup");
    configuration.getZookeeper().setHomeDir(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.MANAGIX_INTERNAL_DIR + File.separator + "zookeeper_home");
    configuration.getZookeeper().getServers().setJavaHome(System.getProperty("java.home"));
    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) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 99 with Unmarshaller

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

the class JaxbUtil method unmarshalNoValidate.

private static Features unmarshalNoValidate(String uri, InputStream stream) {
    try {
        Unmarshaller unmarshaller = FEATURES_CONTEXT.createUnmarshaller();
        NoSourceAndNamespaceFilter xmlFilter = new NoSourceAndNamespaceFilter(XmlUtils.xmlReader());
        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
        InputSource is = new InputSource(uri);
        if (stream != null) {
            is.setByteStream(stream);
        }
        SAXSource source = new SAXSource(xmlFilter, is);
        Features features = (Features) unmarshaller.unmarshal(source);
        features.setNamespace(xmlFilter.getNamespace());
        return features;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("Unable to load " + uri, e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) Unmarshaller(javax.xml.bind.Unmarshaller) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Example 100 with Unmarshaller

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

the class PresetGeometries method convertCustomGeometry.

/**
     * Convert a single CustomGeometry object, i.e. from xmlbeans
     */
public static CustomGeometry convertCustomGeometry(XMLStreamReader staxReader) {
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(BINDING_PACKAGE);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        JAXBElement<CTCustomGeometry2D> el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class);
        return new CustomGeometry(el.getValue());
    } catch (JAXBException e) {
        LOG.log(POILogger.ERROR, "Unable to parse single custom geometry", e);
        return null;
    }
}
Also used : CTCustomGeometry2D(org.apache.poi.sl.draw.binding.CTCustomGeometry2D) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

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