public static void main(String[] args) { try { FileInputStream in = new FileInputStream("bean.xml"); JOXBeanInputStream joxIn = new JOXBeanInputStream(in); TestBean testBean = (TestBean) joxIn.readObject(TestBean.class); JOXBeanDOM beanDOM = new JOXBeanDOM(); Document doc = beanDOM.beanToDocument("testbean", testBean); Element element = doc.getDocumentElement(); dumpElement(element, ""); } catch (Exception exc) { exc.printStackTrace(); } }
public static JSmoothModelBean load(File fin) throws IOException { FileReader fr = new FileReader(fin); try { JSmoothModelBean jobj = new JSmoothModelBean(); String INVALID = "INVALID"; jobj.setSkeletonName(INVALID); JOXBeanReader jbr = new JOXBeanReader(fr); jbr.readObject(jobj); jbr.close(); fr.close(); if (jobj.getSkeletonName() == INVALID) { throw new Exception("Not a JOX File"); } // System.out.println("Loaded jobj " + jobj + " = " + jobj.getJarLocation()); if ((jobj.getJarLocation() != null) && (jobj.getJarLocation().length() > 0)) { jobj.setEmbeddedJar(true); // System.out.println("Set embeddedjar to " + jobj.getEmbeddedJar()); } return jobj; } catch (Exception exc) { fr.close(); try { FileInputStream fis = new FileInputStream(fin); XMLDecoder dec = new XMLDecoder(fis); JSmoothModelBean xobj = (JSmoothModelBean) dec.readObject(); fis.close(); if ((xobj.getJarLocation() != null) && (xobj.getJarLocation().length() > 0)) xobj.setEmbeddedJar(true); return xobj; } catch (Exception exc2) { exc2.printStackTrace(); throw new IOException(exc2.toString()); } } }
public static void save(File fout, JSmoothModelBean obj) throws IOException { // FileOutputStream fos = new FileOutputStream(fout); try { // XMLEncoder enc = new XMLEncoder(fos); // enc.writeObject(obj); // enc.close(); String jarloc = obj.getJarLocation(); if (obj.getEmbeddedJar() == false) obj.setJarLocation(null); FileWriter fw = new FileWriter(fout); JOXBeanWriter jbw = new JOXBeanWriter(fw); jbw.writeObject("jsmoothproject", obj); jbw.close(); fw.close(); obj.setJarLocation(jarloc); } catch (Exception ex) { throw new IOException(ex.toString()); } finally { // fos.close(); } }