Example usage for java.beans XMLEncoder writeObject

List of usage examples for java.beans XMLEncoder writeObject

Introduction

In this page you can find the example usage for java.beans XMLEncoder writeObject.

Prototype

public void writeObject(Object o) 

Source Link

Document

Write an XML representation of the specified object to the output.

Usage

From source file:resources.ResourceManager.java

public static void saveLayoutTable(File file, LayoutTableModel tableModel) {
    try {/*from ww w.  j a  v a2 s .co m*/
        final XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file)));
        encoder.writeObject(tableModel.getLayoutTableItemList());
        encoder.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.clickframes.testframes.TestRunner.java

/**
 * Use this advanced interface to only run tests approved by this filter
 *
 * @param appspec/*from   w  w w. j av  a 2  s .c o m*/
 * @param filenameFilter
 * @return
 * @throws Exception
 *
 * @author Vineet Manohar
 */
private static ProjectTestResults runAllTestSuits(TestProfile testProfile, Techspec techspec, Appspec appspec,
        String filterName, FileFilter fileFilter) throws Exception {
    // prepare tests
    TestPreparationUtil.prepareAllTestSuites(testProfile, techspec, appspec, filterName, fileFilter);

    File suiteTargetDirectory = new File(
            "target" + File.separator + "clickframes" + File.separator + "selenium" + File.separator
                    + ClickframeUtils.convertSlashToPathSeparator(filterName) + File.separator + "tests");

    Properties properties = new Properties();

    properties.put("browser", testProfile.getBrowser());

    properties.put("suite", suiteTargetDirectory.getAbsolutePath());

    if (testProfile.getBaseUrl() != null) {
        properties.put("startURL", testProfile.getBaseUrl());
    }

    File resultsDir = new File(
            "target" + File.separator + "clickframes" + File.separator + "selenium" + File.separator
                    + ClickframeUtils.convertSlashToPathSeparator(filterName) + File.separator + "results");

    FileUtils.deleteDirectory(resultsDir);
    resultsDir.mkdirs();
    properties.put("result", resultsDir.getAbsolutePath());

    // prepare user extensions
    File userExtensionsFile = new File(System.getProperty("java.io.tmpdir"), "user-extensions.js");
    if (userExtensionsFile.exists()) {
        userExtensionsFile.delete();
    }

    IOUtils.copy(TestRunner.class.getResourceAsStream("/user-extensions.js"),
            new FileOutputStream(userExtensionsFile));
    properties.put("userExtensions", userExtensionsFile.getAbsolutePath());

    MultiHTMLSuiteRunner runner = null;

    boolean hasFiles = true;

    if (hasFiles) {
        runner = MultiHTMLSuiteRunner.execute(properties);
    }

    ProjectTestResults projectTestResults = createFrom(runner);

    // serialize the projectTestResults using java serialization
    XMLEncoder e = new XMLEncoder(
            new BufferedOutputStream(new FileOutputStream(new File(resultsDir, "testResults.xml"))));
    e.writeObject(projectTestResults);
    e.close();

    // write test result summary
    writeTestResultSummaryFile(techspec, appspec, projectTestResults, filterName);

    // aggregrateTestResults(techspec, appspec, filterName);

    return projectTestResults;
}

From source file:com.clustercontrol.plugin.impl.AsyncTask.java

/**
 * SerializableXML???//from  w w  w.  j  a v a 2  s. c o m
 * @param obj Serializable
 * @return ??XML
 * @throws IOException
 */
public static String encodeXML(Serializable obj) throws IOException {
    ByteArrayOutputStream baos = null;
    XMLEncoder enc = null;
    String xml = null;

    try {
        baos = new ByteArrayOutputStream();
        enc = new XMLEncoder(baos);
        enc.writeObject(obj);
        xml = baos.toString("UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.warn(e);
    } finally {
        if (enc != null) {
            enc.close();
        }
        if (baos != null) {
            baos.close();
        }
    }

    return xml;
}

From source file:org.dawnsci.common.richbeans.beans.BeanUI.java

/**
 * Used externally to the GDA./*from   ww  w  .ja v a2 s.  c  o  m*/
 * 
 * @param bean
 * @return the string
 */
public static String getString(Object bean) throws Exception {

    final ByteArrayOutputStream stream = new ByteArrayOutputStream();

    final ClassLoader original = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(bean.getClass().getClassLoader());
        XMLEncoder e = new XMLEncoder(new BufferedOutputStream(stream));
        e.writeObject(bean);
        e.close();
        return stream.toString("UTF-8");
    } finally {
        Thread.currentThread().setContextClassLoader(original);
        stream.close();
    }
}

From source file:gov.llnl.lc.smt.command.config.SmtConfig.java

public static boolean writeConfigFile(String fileName, Map<String, String> config) {
    boolean success = false;
    logger.info("Writing config to: " + fileName);
    if ((fileName != null) && (config != null)) {
        FileOutputStream fos;/*  w  w w  .  j a  v  a  2 s  .  co  m*/
        try {
            fos = new FileOutputStream(fileName);
            XMLEncoder xenc = new XMLEncoder(fos);

            // save this file name within the config
            config.put(SmtProperty.SMT_WRITE_CONFIG.getName(), fileName);

            // Write object.
            xenc.writeObject(config);
            xenc.close();
            success = true;
        } catch (FileNotFoundException e) {
            logger.severe("Unable to write to: " + fileName);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {

    }
    return success;
}

From source file:org.scantegrity.scanner.Scanner.java

private static void writeCounters() {
    ListIterator<String> it = c_outDirs.listIterator();
    while (it.hasNext()) {
        try {/*from ww  w.ja  va2  s.  co  m*/
            XMLEncoder l_countFile = new XMLEncoder(
                    new BufferedOutputStream(new FileOutputStream(it.next() + File.separator + "count.xml")));

            l_countFile.writeObject("Scan Count");
            l_countFile.writeObject(c_scanCount);
            l_countFile.writeObject("Ballot Count");
            l_countFile.writeObject(c_ballotCount);
            l_countFile.writeObject("Error Count");
            l_countFile.writeObject(c_errorCount);
            l_countFile.close();
        } catch (FileNotFoundException e) {
            c_log.log(Level.SEVERE, "Unable to create count.xml");
        }
    }
}

From source file:de.willuhn.jameica.hbci.io.csv.ProfileUtil.java

/**
 * Speichert die Profile.//ww  w . j  a  va 2 s  . c o  m
 * @param format das Format.
 * @param profiles die zu speichernden Profile.
 */
public static void store(Format format, List<Profile> profiles) {
    if (format == null) {
        Application.getMessagingFactory().sendMessage(
                new StatusBarMessage(i18n.tr("Kein Format ausgewhlt"), StatusBarMessage.TYPE_ERROR));
        return;
    }

    if (profiles == null) {
        Application.getMessagingFactory().sendMessage(
                new StatusBarMessage(i18n.tr("Keine Profile angegeben"), StatusBarMessage.TYPE_ERROR));
        return;
    }

    // 2. Mal schauen, ob wir ein gespeichertes Profil fuer das Format haben
    File dir = new File(Application.getPluginLoader().getPlugin(HBCI.class).getResources().getWorkPath(),
            "csv");
    if (!dir.exists()) {
        Logger.info("creating dir: " + dir);
        if (!dir.mkdirs()) {
            Application.getMessagingFactory()
                    .sendMessage(new StatusBarMessage(
                            i18n.tr("Ordner {0} kann nicht erstellt werden", dir.getAbsolutePath()),
                            StatusBarMessage.TYPE_ERROR));
            return;
        }
    }

    File file = new File(dir, format.getClass().getName() + ".xml");

    Logger.info("writing csv profile " + file);
    XMLEncoder encoder = null;
    try {
        encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file)));
        encoder.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                throw new RuntimeException(e);
            }
        });

        for (Profile p : profiles) {
            // Das System-Profil wird nicht mit gespeichert
            if (p.isSystem())
                continue;

            // Ebenso Profile ohne Namen.
            if (StringUtils.trimToNull(p.getName()) == null)
                continue;

            encoder.writeObject(p);
        }
    } catch (Exception e) {
        Logger.error("unable to store profile " + file, e);
    } finally {
        if (encoder != null) {
            try {
                encoder.close();
            } catch (Exception e) {
                /* useless */}
        }
    }
}

From source file:com.db4o.sync4o.ui.Db4oSyncSourceConfigPanel.java

private static void showTestUI() {

    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create and set up the window.
    JFrame frame = new JFrame("Db4oSyncSourceConfigPanel Test Harness");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    final Db4oSyncSource source = new Db4oSyncSource();
    Db4oSyncSourceConfigPanel p = new Db4oSyncSourceConfigPanel();
    p.setManagementObject(new SyncSourceManagementObject(source, null, null, null, null));
    p.updateForm();/*  w w  w  . ja  va2s. c  o  m*/
    p.setOpaque(true); // content panes must be opaque
    frame.setContentPane(p);

    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent ev) {

            XMLEncoder encoder = null;
            try {
                FileOutputStream s = new FileOutputStream("test.xml");
                encoder = new XMLEncoder(s);
                encoder.setExceptionListener(new ExceptionListener() {
                    public void exceptionThrown(Exception exception) {
                        exception.printStackTrace();
                    }
                });
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                System.exit(-1);
            }
            encoder.writeObject((Object) source);
            encoder.flush();
            encoder.close();

        }

    });

    // Display the window.
    frame.pack();
    frame.setVisible(true);

}

From source file:psidev.psi.mi.filemakers.xmlMaker.structure.FlatFileContainer.java

public void save(XMLEncoder oos) {
    oos.writeObject(flatFiles);
}

From source file:com.jaspersoft.jasperserver.export.modules.repository.OlapUnitViewOptionsDataProvider.java

public InputStream getData(ExporterModuleContext exportContext, Resource resource) {

    OlapUnit unit = (OlapUnit) resource;
    InputStream dataStream;/*  ww  w. j  a  v a2s.co  m*/
    Object viewOptions = unit.getOlapViewOptions();
    if (viewOptions == null) {
        dataStream = null;
    } else {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLEncoder e = new XMLEncoder(new BufferedOutputStream(baos));
        e.writeObject(unit.getOlapViewOptions());
        e.flush();
        e.close();
        dataStream = new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray()));
    }
    return dataStream;
}