use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.
the class MarshallingTest method testMarshallingV2_0.
@Test
public void testMarshallingV2_0() throws JAXBException, IOException, SAXException {
JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.notification.permission_v2");
Unmarshaller unmarshaller = context.createUnmarshaller();
InputStream inputStream = MarshallingTest.class.getResourceAsStream(SAMPLE_PATH_V2);
org.orcid.jaxb.model.notification.permission_v2.NotificationPermission notification = (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) unmarshaller.unmarshal(inputStream);
assertNotNull(notification);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.PERMISSION, notification.getNotificationType());
assertEquals(2, notification.getItems().getItems().size());
assertEquals("2014-01-01T14:45:32", notification.getSentDate().toXMLFormat());
// Back the other way
String expected = IOUtils.toString(getClass().getResourceAsStream(SAMPLE_PATH_V2), "UTF-8");
Pattern pattern = Pattern.compile("<!--.*?-->\\s*", Pattern.DOTALL);
expected = pattern.matcher(expected).replaceAll("");
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.orcid.org/ns/notification ../notification-permission-2.0.xsd");
StringWriter writer = new StringWriter();
marshaller.marshal(notification, writer);
XMLUnit.setIgnoreWhitespace(true);
Diff diff = new Diff(expected, writer.toString());
assertTrue(diff.identical());
}
use of javax.xml.bind.Marshaller 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);
}
use of javax.xml.bind.Marshaller 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));
}
use of javax.xml.bind.Marshaller in project sissi by KimShen.
the class JAXBWriter method marshallerPart.
/**
* 忽略指定部分
*
* @param context
* @param part
* @param output
* @param element
* @return
* @throws Exception
*/
private Element marshallerPart(JIDContext context, WriterPart part, OutputStream output, Element element) throws Exception {
Marshaller marshaller = this.generateMarshaller(true, part == WriterPart.WITHOUT_FIRST ? true : false);
String content = this.getPart(this.prepareToLines(marshaller, element), part);
this.log.info("Write on " + context.jid().asString() + " " + content);
output.write(content.getBytes("UTF-8"));
return element;
}
use of javax.xml.bind.Marshaller in project phoenix by apache.
the class ConfigurationParserTest method writeXML.
/*
Used for debugging to dump out a simple xml filed based on the bound objects.
*/
private String writeXML() {
DataModel data = new DataModel();
try {
DataValue dataValue = new DataValue();
dataValue.setDistribution(20);
dataValue.setValue("jnhgGhHminwiajn");
List<DataValue> dataValueList = new ArrayList<>();
dataValueList.add(dataValue);
Column column = new Column();
column.setLength(15);
column.setDataSequence(DataSequence.RANDOM);
column.setName("TEST_COL");
column.setUserDefined(true);
column.setDataValues(dataValueList);
List<Column> columnList = new ArrayList<>();
columnList.add(column);
data.setDataMappingColumns(columnList);
Scenario scenario = new Scenario();
scenario.setPhoenixProperties(new HashMap<String, String>());
scenario.getPhoenixProperties().put("phoenix.query.threadPoolSize", "200");
scenario.setDataOverride(new DataOverride());
scenario.setTableName("tableName");
scenario.setRowCount(10);
QuerySet querySet = new QuerySet();
querySet.setExecutionType(ExecutionType.PARALLEL);
querySet.setExecutionDurationInMs(10000);
scenario.getQuerySet().add(querySet);
Query query = new Query();
querySet.getQuery().add(query);
querySet.setConcurrency("15");
querySet.setNumberOfExecutions(20);
query.setStatement("select * from FHA");
Scenario scenario2 = new Scenario();
scenario2.setPhoenixProperties(new HashMap<String, String>());
scenario2.setDataOverride(new DataOverride());
scenario2.setTableName("tableName2");
scenario2.setRowCount(500);
List<Scenario> scenarios = new ArrayList<Scenario>();
scenarios.add(scenario);
scenarios.add(scenario2);
data.setScenarios(scenarios);
// create JAXB context and initializing Marshaller
JAXBContext jaxbContext = JAXBContext.newInstance(DataModel.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// for getting nice formatted output
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// Writing to console
jaxbMarshaller.marshal(data, System.out);
} catch (JAXBException e) {
// some exception occured
e.printStackTrace();
}
return data.toString();
}
Aggregations