Esempio n. 1
0
 /**
  * @param element The element.
  * @return The object.
  */
 public Object deserialize(Element element) throws XMLException {
   String tagname = element.getTagName();
   String classname = element.getAttribute("class"); // use class attribute...
   if (classname == null || classname.equals("")) {
     classname = getFactory().mapToClassname(tagname); // ... or preset-table
   }
   if (classname != null) {
     Class cl;
     try {
       cl = this.getClass().getClassLoader().loadClass(classname);
     } catch (ClassNotFoundException cnfe) {
       throw new XMLException("cannot load class " + classname);
     }
     Object o;
     try {
       o = cl.newInstance();
     } catch (Exception e) {
       throw new XMLException("cannot instanciate class " + classname);
     }
     XMLSerializable x = (XMLSerializable) o;
     x.getXMLHandler().parseXML(element, this);
     return x;
   } else {
     throw new XMLException("cannot deserialize, unknown tag <" + tagname + ">");
   }
 }
Esempio n. 2
0
 /**
  * @param object The object.
  * @param document The document.
  * @return The element.
  */
 public Element serialize(XMLSerializable object, Document document) {
   Class cl = object.getClass();
   String tagname;
   tagname = getFactory().mapToTagname(cl.getName());
   Element e = document.createElement(tagname);
   object.getXMLHandler().toXML(e, this);
   return e;
 }