Java Code Examples for javax.xml.bind.JAXB#marshal()

The following examples show how to use javax.xml.bind.JAXB#marshal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomProcessExecutorTest.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testCertChain() throws Exception {
	XmlDiagnosticData diagnosticData = DiagnosticDataFacade.newFacade().unmarshall(new File("src/test/resources/qualifNA.xml"));
	assertNotNull(diagnosticData);

	DefaultSignatureProcessExecutor executor = new DefaultSignatureProcessExecutor();
	executor.setDiagnosticData(diagnosticData);
	executor.setValidationPolicy(loadDefaultPolicy());
	executor.setCurrentTime(diagnosticData.getValidationDate());

	Reports reports = executor.execute();

	SimpleReport simpleReport = reports.getSimpleReport();
	assertEquals(1, simpleReport.getJaxbModel().getSignaturesCount());
	XmlCertificateChain certificateChain = simpleReport.getCertificateChain(simpleReport.getFirstSignatureId());
	assertNotNull(certificateChain);
	assertTrue(Utils.isCollectionNotEmpty(certificateChain.getCertificate()));
	assertEquals(3, certificateChain.getCertificate().size());
	ByteArrayOutputStream s = new ByteArrayOutputStream();
	JAXB.marshal(simpleReport.getJaxbModel(), s);

	validateBestSigningTimes(reports);
	checkReports(reports);
}
 
Example 2
Source File: RemoteStorageTest.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testXmlRead() throws Exception {
    String dsId = "testId";
    LocalObject local = new LocalStorage().create();
    local.setLabel(test.getMethodName());
    String format = "testns";
    XmlStreamEditor leditor = local.getEditor(FoxmlUtils.inlineProfile(dsId, format, "label"));
    EditorResult editorResult = leditor.createResult();
    TestXml content = new TestXml("test content");
    JAXB.marshal(content, editorResult);
    leditor.write(editorResult, 0, null);

    RemoteStorage fedora = new RemoteStorage(client);
    fedora.ingest(local, "junit");

    RemoteObject remote = fedora.find(local.getPid());
    RemoteXmlStreamEditor editor = new RemoteXmlStreamEditor(remote, dsId);
    Source src = editor.read();
    assertNotNull(src);
    TestXml resultContent = JAXB.unmarshal(src, TestXml.class);
    assertEquals(content, resultContent);
    long lastModified = editor.getLastModified();
    assertTrue(String.valueOf(lastModified), lastModified != 0 && lastModified < System.currentTimeMillis());
    assertEquals(format, editor.getProfile().getDsFormatURI());
}
 
Example 3
Source File: TaskParameterTest.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
@Test
    public void testTaskParameterJsonXml() throws Exception {
        String expectedTimestamp = "2017-01-05T14:51:24.639Z";
        Calendar c = DatatypeConverter.parseDateTime(expectedTimestamp);
        ObjectMapper om = JsonUtils.createJaxbMapper();
        TaskParameterView tp = new TaskParameterView();
        tp.addParamRef("paramRef").addTaskId(BigDecimal.TEN)
//                .addValueString("aha")
//                .addValueNumber(BigDecimal.ONE)
                .addValueDateTime(new Timestamp(c.getTimeInMillis()))
                ;
        tp.setJobId(BigDecimal.ZERO);
        String json = om.writeValueAsString(tp);
        assertTrue(json, json.contains("\"value\":\"" + expectedTimestamp));

        StringWriter stringWriter = new StringWriter();
        JAXB.marshal(tp, stringWriter);
        String xml = stringWriter.toString();
        assertTrue(xml, xml.contains(expectedTimestamp));
    }
 
Example 4
Source File: RemoteStorageTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = DigitalObjectConcurrentModificationException.class)
public void testXmlWriteConcurrent() throws Exception {
    String dsId = "testId";
    LocalObject local = new LocalStorage().create();
    local.setLabel(test.getMethodName());
    XmlStreamEditor leditor = local.getEditor(FoxmlUtils.inlineProfile(dsId, "testns", "label"));
    EditorResult editorResult = leditor.createResult();
    TestXml content = new TestXml("test content");
    JAXB.marshal(content, editorResult);
    leditor.write(editorResult, 0, null);

    RemoteStorage fedora = new RemoteStorage(client);
    fedora.ingest(local, "junit");

    RemoteObject remote = fedora.find(local.getPid());
    RemoteXmlStreamEditor editor = new RemoteXmlStreamEditor(remote, dsId);
    Source src = editor.read();
    assertNotNull(src);
    TestXml resultContent = JAXB.unmarshal(src, TestXml.class);

    // concurrent write
    RemoteObject concurrentRemote = fedora.find(local.getPid());
    RemoteXmlStreamEditor concurrentEditor = new RemoteXmlStreamEditor(concurrentRemote, dsId);
    TestXml concurrentContent = JAXB.unmarshal(concurrentEditor.read(), TestXml.class);
    concurrentContent.data = "concurrent change";
    EditorResult concurrentResult = concurrentEditor.createResult();
    JAXB.marshal(concurrentContent, concurrentResult);
    concurrentEditor.write(concurrentResult, editor.getLastModified(), null);
    concurrentRemote.flush();

    // write out of date modification
    String expectedContent = "changed test content";
    resultContent.data = expectedContent;
    editorResult = editor.createResult();
    JAXB.marshal(resultContent, editorResult);
    long lastModified = editor.getLastModified();
    editor.write(editorResult, lastModified, null);

    remote.flush();
}
 
Example 5
Source File: RepFiltersEditorDialog.java    From scelight with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent event ) {
 final XFileChooser fc = new XFileChooser( SAVE_FOLDER );
 fc.setDialogTitle( "Choose a file to save Replay Filters" );
 fc.setFileFilter( new FileNameExtensionFilter( "Replay Filter files (*."
         + REP_FILTERS_FILE_EXT + ')', REP_FILTERS_FILE_EXT ) );
 
 // Suggested file name
 fc.setSelectedFile( Utils.uniqueFile(
         SAVE_FOLDER.resolve( "replay-filters." + REP_FILTERS_FILE_EXT ) ).toFile() );
 
 if ( XFileChooser.APPROVE_OPTION != fc.showSaveDialog( RepFiltersEditorDialog.this ) )
  return;
 Path path = fc.getSelectedPath();
 // Ensure proper extension
 if ( !path.getFileName().toString().toLowerCase().endsWith( '.' + REP_FILTERS_FILE_EXT ) )
  path = path.resolveSibling( path.getFileName().toString() + '.'
          + REP_FILTERS_FILE_EXT );
 if ( Files.exists( path ) )
  if ( !GuiUtils.confirm( "The selected file already exists?", "Overwrite it?" ) )
   return;
 
 try {
  JAXB.marshal( repFiltersBean, path.toFile() );
 } catch ( final Exception e ) {
  Env.LOGGER.error( "Failed to write to file: " + path, e );
  GuiUtils.showErrorMsg( "Failed to write to file:", path );
 }
}
 
Example 6
Source File: RepProcCache.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the cache config bean.
 * 
 * @param config cache config bean to be set
 */
private static void setConfig( final ConfigBean config ) {
	try {
		JAXB.marshal( config, PATH_CONFIG_BEAN.toFile() );
		RepProcCache.config = config;
	} catch ( final Exception e ) {
		Env.LOGGER.error( "Failed to write replay processor cache config to: " + PATH_CONFIG_BEAN, e );
	}
}
 
Example 7
Source File: MapImageCache.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the cache config bean.
 * 
 * @param config cache config bean to be set
 */
private static void setConfig( final ConfigBean config ) {
	try {
		JAXB.marshal( config, PATH_CONFIG_BEAN.toFile() );
		MapImageCache.config = config;
	} catch ( final Exception e ) {
		Env.LOGGER.error( "Failed to write map image cache config to: " + PATH_CONFIG_BEAN, e );
	}
}
 
Example 8
Source File: LocalStorageTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDatastreamEditorWriteXml_Inlined() throws Exception {
    LocalStorage storage = new LocalStorage();
    LocalObject lobject = storage.create();
    String dsID = "dsID";
    MediaType mime = MediaType.TEXT_XML_TYPE;
    String label = "label";
    String formatUri = "formatUri";
    XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.inlineProfile(dsID, formatUri, label));
    assertNotNull(editor);
    assertNotNull(editor.getProfile());
    assertEquals(mime.toString(), editor.getProfile().getDsMIME());
    assertEquals(formatUri, editor.getProfile().getDsFormatURI());
    XmlData xdata = new XmlData("data");
    EditorResult xmlResult = editor.createResult();
    JAXB.marshal(xdata, xmlResult);
    editor.write(xmlResult, 0, null);
    lobject.flush();

    // is inline
    DigitalObject dobj = lobject.getDigitalObject();
    DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID);
    assertNotNull(ds);
    assertEquals(ControlGroup.INLINE.toExternal(), ds.getCONTROLGROUP());

    // is inlined
    DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID);
    assertNotNull(dsv);
    assertEquals(mime.toString(), dsv.getMIMETYPE());
    assertEquals(label, dsv.getLABEL());
    assertEquals(formatUri, dsv.getFORMATURI());
    assertNotNull(dsv.getXmlContent());
    assertNull(dsv.getContentLocation());
    assertNull(dsv.getBinaryContent());
}
 
Example 9
Source File: LocalStorageTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDatastreamEditorWriteXml_ManagedAsAttached() throws Exception {
    LocalStorage storage = new LocalStorage();
    LocalObject lobject = storage.create();
    String dsID = "dsID";
    MediaType mime = MediaType.TEXT_XML_TYPE;
    String label = "label";
    String formatUri = "formatUri";
    XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, formatUri, label));
    assertNotNull(editor);
    assertNotNull(editor.getProfile());
    assertEquals(mime.toString(), editor.getProfile().getDsMIME());
    assertEquals(formatUri, editor.getProfile().getDsFormatURI());
    File attachment = tmp.newFile();
    editor.write(attachment.toURI(), 0, null);
    XmlData xdata = new XmlData("data");
    EditorResult xmlResult = editor.createResult();
    JAXB.marshal(xdata, xmlResult);
    editor.write(xmlResult, editor.getLastModified(), null);
    lobject.flush();

    // is managed
    DigitalObject dobj = lobject.getDigitalObject();
    DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID);
    assertNotNull(ds);
    assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP());

    // is attached
    DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID);
    assertNotNull(dsv);
    assertEquals(mime.toString(), dsv.getMIMETYPE());
    assertEquals(label, dsv.getLABEL());
    assertEquals(formatUri, dsv.getFORMATURI());
    assertNull(dsv.getBinaryContent());
    assertNull(dsv.getXmlContent());
    assertNotNull(dsv.getContentLocation());

    XmlData result = JAXB.unmarshal(attachment, XmlData.class);
    assertEquals(xdata, result);
}
 
Example 10
Source File: PrepNextSc2TRelease.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * @param args used to take arguments from the running environment; args[0] is the name of the sc2-t-build.properties file to generate for Ant
 * @throws Exception if any error occurs
 */
public static void main( final String[] args ) throws Exception {
	final String BUILD_INFO_FILE = "/hu/slsc2textures/r/bean/build-info.xml";
	
	// Read current sc2-t build info
	final BuildInfoBean b = JAXB.unmarshal( TR.class.getResource( BUILD_INFO_FILE ), BuildInfoBean.class );
	System.out.println( "Current: " + b );
	
	// Increment build
	b.setBuild( b.getBuildNumber() + 1 );
	b.setDate( new Date() );
	System.out.println( "New: " + b );
	
	// Archive to sc2-t-build-history.txt and save new build info
	// to both src-sc2-textures and bin-sc2-textures folders (so no refresh is required in Eclipse)
	try ( final BufferedWriter out = Files.newBufferedWriter( Paths.get( "dev-data", "sc2-t-build-history.txt" ), Charset.forName( "UTF-8" ),
	        StandardOpenOption.APPEND ) ) {
		out.write( b.getBuildNumber() + " " + b.getDate() );
		out.newLine();
	}
	JAXB.marshal( b, Paths.get( "src-sc2-textures", BUILD_INFO_FILE ).toFile() );
	JAXB.marshal( b, Paths.get( "bin-sc2-textures", BUILD_INFO_FILE ).toFile() );
	
	// Create properties file for Ant
	final Properties p = new Properties();
	p.setProperty( "sc2TVer", TConsts.SC2_TEXTURES_VERSION.toString() );
	p.setProperty( "sc2TBuildNumber", b.getBuildNumber().toString() );
	try ( final FileOutputStream out = new FileOutputStream( args[ 0 ] ) ) {
		p.store( out, null );
	}
}
 
Example 11
Source File: PrepNextExtModApiRelease.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * @param args used to take arguments from the running environment; args[0] is the name of the ext-mod-api-build.properties file to generate for Ant
 * @throws Exception if any error occurs
 */
public static void main( final String[] args ) throws Exception {
	final String BUILD_INFO_FILE = "/hu/scelightapi/r/bean/build-info.xml";
	
	// Read current app-libs build info
	final BuildInfoBean b = JAXB.unmarshal( XR.class.getResource( BUILD_INFO_FILE ), BuildInfoBean.class );
	System.out.println( "Current: " + b );
	
	// Increment build
	b.setBuild( b.getBuildNumber() + 1 );
	b.setDate( new Date() );
	System.out.println( "New: " + b );
	
	// Archive to ext-mod-api-build-history.txt and save new build info
	// to both src-app and bin-app folders (so no refresh is required in Eclipse)
	try ( final BufferedWriter out = Files.newBufferedWriter( Paths.get( "dev-data", "ext-mod-api-build-history.txt" ), Charset.forName( "UTF-8" ),
	        StandardOpenOption.APPEND ) ) {
		out.write( b.getBuildNumber() + " " + b.getDate() );
		out.newLine();
	}
	JAXB.marshal( b, Paths.get( "src-ext-mod-api", BUILD_INFO_FILE ).toFile() );
	JAXB.marshal( b, Paths.get( "bin-ext-mod-api", BUILD_INFO_FILE ).toFile() );
	
	// Create properties file for Ant
	final Properties p = new Properties();
	p.setProperty( "extModApiVer", XConsts.EXT_MOD_API_VERSION.toString() );
	p.setProperty( "extModApiBuildNumber", b.getBuildNumber().toString() );
	try ( final FileOutputStream out = new FileOutputStream( args[ 0 ] ) ) {
		p.store( out, null );
	}
}
 
Example 12
Source File: SettingsBean.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * @see #configureSave(String, VersionBean, Path)
 */
@Override
public void save() {
	saveTime = new Date();
	
	try {
		JAXB.marshal( this, path.toFile() );
	} catch ( final Exception e ) {
		e.printStackTrace();
		LEnv.LOGGER.error( "Failed to save " + savedByModuleName + " settings to: " + path + "\nDo you have write permission in the folder?", e );
	}
}
 
Example 13
Source File: RemoteStorageTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testXmlWrite() throws Exception {
    String dsId = "testId";
    LocalObject local = new LocalStorage().create();
    local.setLabel(test.getMethodName());
    String format = "testns";
    XmlStreamEditor leditor = local.getEditor(FoxmlUtils.inlineProfile(dsId, format, "label"));
    EditorResult editorResult = leditor.createResult();
    TestXml content = new TestXml("test content");
    JAXB.marshal(content, editorResult);
    leditor.write(editorResult, 0, null);

    RemoteStorage fedora = new RemoteStorage(client);
    fedora.ingest(local, "junit");

    RemoteObject remote = fedora.find(local.getPid());
    RemoteXmlStreamEditor editor = new RemoteXmlStreamEditor(remote, dsId);
    Source src = editor.read();
    assertNotNull(src);
    TestXml resultContent = JAXB.unmarshal(src, TestXml.class);

    // write modification
    String expectedContent = "changed test content";
    resultContent.data = expectedContent;
    editorResult = editor.createResult();
    JAXB.marshal(resultContent, editorResult);
    long lastModified = editor.getLastModified();
    assertEquals(format, editor.getProfile().getDsFormatURI());
    editor.write(editorResult, lastModified, null);
    remote.flush();

    // test current editor
    assertTrue(lastModified < editor.getLastModified());
    long expectLastModified = editor.getLastModified();
    resultContent = JAXB.unmarshal(editor.read(), TestXml.class);
    assertEquals(new TestXml(expectedContent), resultContent);
    assertEquals(format, editor.getProfile().getDsFormatURI());

    // test new editor
    remote = fedora.find(local.getPid());
    editor = new RemoteXmlStreamEditor(remote, dsId);
    src = editor.read();
    assertNotNull(src);
    resultContent = JAXB.unmarshal(src, TestXml.class);
    assertEquals(new TestXml(expectedContent), resultContent);
    long resultLastModified = editor.getLastModified();
    assertEquals(expectLastModified, resultLastModified);
    assertEquals(format, editor.getProfile().getDsFormatURI());
}
 
Example 14
Source File: RomSetXmlGenerator.java    From ia-rcade with Apache License 2.0 4 votes vote down vote up
/**
 * Generate XML data for MachineRomSet
 */
public static void generateMachineChdSetXml(Document zipView) throws Exception {

    Pattern p;
    Matcher m;

    // Scrap collection id

    Element caption = zipView.select("caption").first();
    p = Pattern.compile("listing\\ of\\ (.+)\\.[tarzip]{3}");
    m = p.matcher(caption.text());
    if (!m.matches()) {
        throw new RuntimeException("Can't parse collection id from caption. Regex does not match");
    }
    String id = m.group(1);

    Elements trs = zipView.select("table[class=archext]").first().select("tr:has(td:has(a))");

    Map<String, Map<String, MachineChdSetFile>> files = new HashMap<>();

    for (Element tr : trs) {

        Element a = tr.child(0).child(0);

        String url = "http:" + a.attr("href").toString();
        p = Pattern.compile(".+/(.+)/(.+\\.chd)");
        m = p.matcher(a.text());

        if (!m.matches()) {
            System.err.println("Skip non rom file: " + url);
            continue;
        }

        // Scrap machine name

        String machineName = m.group(1);

        // Scrap software name

        String chd = m.group(2);

        // Scrap size
        //
        // There is scraping errors sometimes. To prevent this the size of
        // the children of tr is tested. A warning to stderr is reported in case

        String size;

        if (tr.children().size() <= 3) {
            System.err.println("Warning, can't parse size: " + tr);
            size = "0";
        } else {
            size = tr.child(3).text();
        }

        MachineChdSetFile file = new MachineChdSetFile(id, machineName, chd, new URL(url), Long.parseLong(size));

        if (!files.containsKey(machineName)) {
            files.put(machineName, new HashMap<String, MachineChdSetFile>());
        }

        files.get(machineName).put(chd, file);
    }

    MameVersion version = new MameVersion("0.150"); // Don't care

    MachineChdSet chdSet = new MachineChdSet(version, new HashSet<Collection>(), files);

    JAXB.marshal(chdSet, System.out);

}
 
Example 15
Source File: RomSetXmlGenerator.java    From ia-rcade with Apache License 2.0 4 votes vote down vote up
/**
 * Generate XML data for MachineRomSet
 */
public static void generateMachineRomSetXml(Document zipView) throws Exception {

    Pattern p;
    Matcher m;

    // Scrap collection id

    Element caption = zipView.select("caption").first();
    p = Pattern.compile("listing\\ of\\ (.+)\\.[ziptar]{3}");
    m = p.matcher(caption.text());
    if (!m.matches()) {
        throw new RuntimeException("Can't parse collection id from caption. Regex does not match");
    }
    String id = m.group(1);

    Elements trs = zipView.select("table[class=archext]").first().select("tr:has(td:has(a))");

    Map<String, MachineRomSetFile> files = new HashMap<>();

    for (Element tr : trs) {

        Element a = tr.child(0).child(0);

        // Scrap URL

        String url = "http:" + a.attr("href").toString();
        p = Pattern.compile(".+/(.+)\\.zip");
        m = p.matcher(a.text());

        if (!m.matches()) {
            System.err.println("Skip non rom file: " + url);
            continue;
        }

        // Scrap machine name

        String machineName = m.group(1);

        // Scrap size
        //
        // There is scraping errors sometimes. To prevent this the size of
        // the children of tr is tested. A warning to stderr is reported in case

        String size;

        if (tr.children().size() <= 3) {
            System.err.println("Warning, can't parse size: " + tr);
            size = "0";
        } else {
            size = tr.child(3).text();
        }

        MachineRomSetFile file = new MachineRomSetFile(id, machineName, new URL(url), Long.parseLong(size));

        files.put(machineName, file);
    }

    MameVersion version = new MameVersion("0.150"); // Don't care
    MachineRomSetFormat format = MachineRomSetFormat.MERGED;

    MachineRomSet romSet = new MachineRomSet(version, new HashSet<Collection>(), format, files);

    JAXB.marshal(romSet, System.out);

}
 
Example 16
Source File: RomSetXmlGenerator.java    From ia-rcade with Apache License 2.0 4 votes vote down vote up
public static void generateSoftwareListRomSetXml(Document zipView) throws Exception {

        Pattern p;
        Matcher m;

        // Scrap collection id

        Element caption = zipView.select("caption").first();
        p = Pattern.compile("listing\\ of\\ (.+)\\.zip");
        m = p.matcher(caption.text());
        if (!m.matches()) {
            throw new RuntimeException("Can't parse collection id from caption. Regex does not match");
        }
        String id = m.group(1);

        Elements trs = zipView.select("table[class=archext]").first().select("tr:has(td:has(a))");

        Map<String, Map<String, SoftwareListRomSetFile>> files = new HashMap<>();

        for (Element tr : trs) {

            Element a = tr.child(0).child(0);

            // Scrap URL

            String url = "http:" + a.attr("href").toString();
            p = Pattern.compile(".+/(.+)/(.+)\\.zip");
            // p = Pattern.compile("(.+)/(.+)\\.zip"); // use this is collection is splited
            // into separate zip files (like 0.202)
            m = p.matcher(a.text());

            if (!m.matches()) {
                System.err.println("youpi");
                System.err.println("Skip non rom file: " + url);
                continue;
            }

            // Scrap softwarelist name

            String listName = m.group(1);

            // Scrap software name

            String softwareName = m.group(2);

            // Scrap size
            //
            // There is scraping errors sometimes. To prevent this the size of
            // the children of tr is tested. A warning to stderr is reported in case

            String size;

            if (tr.children().size() <= 3) {
                System.err.println("Warning, can't parse size: " + tr);
                size = "0";
            } else {
                size = tr.child(3).text();
            }

            SoftwareListRomSetFile file = new SoftwareListRomSetFile(id, listName, softwareName, new URL(url),
                    Long.parseLong(size));

            if (!files.containsKey(listName)) {
                files.put(listName, new HashMap<String, SoftwareListRomSetFile>());
            }
            files.get(listName).put(softwareName, file);
        }

        MameVersion version = new MameVersion("0.150"); // Don't care

        SoftwareListRomSet romSet = new SoftwareListRomSet(version, new HashSet<Collection>(), files);

        JAXB.marshal(romSet, System.out);

    }
 
Example 17
Source File: ActionUtils.java    From curly with Apache License 2.0 4 votes vote down vote up
public static void saveToFile(File targetFile, List<Action> actions) {
    Actions out = new Actions();
    out.getAction().addAll(actions);
    JAXB.marshal(out, targetFile);
}
 
Example 18
Source File: XmlUtils.java    From terracotta-platform with Apache License 2.0 4 votes vote down vote up
static Element convertToElement(org.terracotta.data.config.DataDirectories dataDirectories) {
  DOMResult res = new DOMResult();
  JAXBElement<DataDirectories> jaxbElement = new ObjectFactory().createDataDirectories(dataDirectories);
  JAXB.marshal(jaxbElement, res);
  return ((Document)res.getNode()).getDocumentElement();
}
 
Example 19
Source File: BalanaPolicy.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
public BalanaPolicy(PolicyType policyType, ValueFactory vf) {
    super(policyType, vf);
    StringWriter sw = new StringWriter();
    JAXB.marshal(of.createPolicy(policyType), sw);
    this.abstractPolicy = stringToPolicy(sw.toString());
}
 
Example 20
Source File: Bean.java    From scelight with Apache License 2.0 3 votes vote down vote up
/**
 * Clones this bean by concatenating marshaling and unmarshaling operations.
 * 
 * <p>
 * This default bean cloning implementation is "very" slow, it even marshals and unmarshals primitive type values (like <code>int</code> or
 * <code>boolean</code>) and immutable objects (like {@link String}) which otherwise would not be necessary. But works for all beans without modification,
 * and does not require modification when a bean is modified or extended with new fields later on (<i>resilient</i> to changes).
 * </p>
 * <p>
 * Beans that are frequently cloned should override this method and implement a custom cloning. A custom cloning (which copies the fields) can be even 1000
 * times faster than this!
 * </p>
 * 
 * @param <T> dynamic type of the bean to return
 * @return a clone of this bean
 */
@Override
@SuppressWarnings( "unchecked" )
public < T extends IBean > T cloneBean() {
	final StringWriter sw = new StringWriter( 256 );
	JAXB.marshal( this, sw );
	
	return (T) JAXB.unmarshal( new StringReader( sw.toString() ), this.getClass() );
}