예제 #1
0
  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());
      }
    }
  }