1 package test; 2 3 import javax.xml.stream.*; 4 5 public class Bind { 6 public static void main(String args[]) throws Exception { 7 Employee e = new Employee(); 8 Job j = new Job(); 9 j.setTitle("Engineer"); 10 j.setYearsEmployed(2); 11 e.setName("Chris Fry"); 12 e.setJob(j); 13 14 System.out.println("Created the Employee Bean"); 15 16 XMLOutputFactory f = XMLOutputFactory.newInstance(); 17 java.io.OutputStream out = new java.io.FileOutputStream ("emp.xml"); 18 XMLStreamWriter w = f.createXMLStreamWriter(out); 19 EmployeeCodec.serialize(e,w); 20 w.close(); 21 System.out.println("Serialized the Employee Bean to 'emp.xml'"); 22 23 XMLInputFactory i = XMLInputFactory.newInstance(); 24 java.io.InputStream in = new java.io.FileInputStream ("emp.xml"); 25 XMLStreamReader r = i.createXMLStreamReader(in); 26 Employee e2 = EmployeeCodec.deserialize(r); 27 28 System.out.println("Deserialized the Employee Bean from 'emp.xml'"); 29 System.out.println("Emp: "+e2.getName()+" "+ 30 e2.getJob().getTitle()+" "+ 31 e2.getJob().getYearsEmployed()); 32 System.out.println("Successful execution"); 33 } 34 } 35 | Popular Tags |