Skip to content

Save and Recovery one AST

Rubens de Oliveira Moraes Filho edited this page Apr 29, 2021 · 1 revision

An AST (iDSL object) can be saved and recovery using the methods saveSerializable and recoverySerializable from class SerializableController. All iDSL's objects are serializable and allow Java to serialize and save the solutions easily.

Saving an AST

line 1. String path = System.getProperty("user.dir").concat("/logs2/");
line 2. iDSL script1 = BuilderDSLTreeSingleton.getInstance().buildS1Grammar();
line 3. SerializableController.saveSerializable(script1, "dsl_test_id_.ser", path);

Recovering an AST - With JFileChooser

line 1. BuilderDSLTreeSingleton builder = BuilderDSLTreeSingleton.getInstance();
line 2. final JFileChooser fc = new JFileChooser();
line 3. fc.setCurrentDirectory(new File(System.getProperty("user.home")));
line 4. int result = fc.showOpenDialog(new JDialog());
line 5. if (result == JFileChooser.APPROVE_OPTION) {
line 6. ...File selectedFile = fc.getSelectedFile();
line 7. ...System.out.println("Selected file: " + selectedFile.getAbsolutePath());
line 8. ...iDSL ast = SerializableController.recoverySerializable(selectedFile.getName(),
line 8. ...............selectedFile.getAbsolutePath().replace(selectedFile.getName(),
line 8. ...............""));
line 9. };

Clone this wiki locally