Search in sources :

Example 91 with JAXBContext

use of javax.xml.bind.JAXBContext in project oxAuth by GluuFederation.

the class ConfigurationTest method loadConfFromFile.

private static AppConfiguration loadConfFromFile(String p_filePath) throws JAXBException {
    final JAXBContext jc = JAXBContext.newInstance(AppConfiguration.class);
    final Unmarshaller u = jc.createUnmarshaller();
    return (AppConfiguration) u.unmarshal(new File(p_filePath));
}
Also used : AppConfiguration(org.xdi.oxauth.model.configuration.AppConfiguration) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 92 with JAXBContext

use of javax.xml.bind.JAXBContext in project oxAuth by GluuFederation.

the class ConfSerialization method loadXml.

public static <T> T loadXml(String p_fileName, Class p_clazz) {
    final URL url = ConfSerialization.class.getResource(p_fileName);
    try {
        System.out.println("Loading configuration file: " + url);
        JAXBContext jc = JAXBContext.newInstance(p_clazz);
        Unmarshaller u = jc.createUnmarshaller();
        return (T) u.unmarshal(url);
    } catch (JAXBException e) {
        System.out.println("Failed to get the configuration file: " + url);
        e.printStackTrace();
    }
    return null;
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL)

Example 93 with JAXBContext

use of javax.xml.bind.JAXBContext in project sukija by ahomansikka.

the class JAXBUtil method marshal.

/** Kirjoitetaan XML-dataa.
   *
   * @param value  Data, joka kirjoitetaan.
   * @param contextPath
   * @param out    Paikka, johon kirjoitetaan.
   */
public static final <T> void marshal(JAXBElement<T> value, String contextPath, OutputStream out, ClassLoader classLoader) throws JAXBException {
    JAXBContext jc = JAXBContext.newInstance(contextPath, classLoader);
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(value, out);
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext)

Example 94 with JAXBContext

use of javax.xml.bind.JAXBContext 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 95 with JAXBContext

use of javax.xml.bind.JAXBContext 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)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)1150 Unmarshaller (javax.xml.bind.Unmarshaller)558 Marshaller (javax.xml.bind.Marshaller)371 JAXBException (javax.xml.bind.JAXBException)330 Test (org.junit.Test)226 File (java.io.File)161 InputStream (java.io.InputStream)150 StringWriter (java.io.StringWriter)138 IOException (java.io.IOException)105 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 StringReader (java.io.StringReader)74 StreamSource (javax.xml.transform.stream.StreamSource)73 JAXBElement (javax.xml.bind.JAXBElement)72 ArrayList (java.util.ArrayList)58 URL (java.net.URL)55 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Schema (javax.xml.validation.Schema)48 SchemaFactory (javax.xml.validation.SchemaFactory)48 OutputStream (java.io.OutputStream)42 BaseTest (org.orcid.core.BaseTest)39