示例#1
0
 // obj: "object with properties" to write
 private void writeObject(Object obj)
     throws NoSuchMethodException, InstantiationException, InvocationTargetException,
         IllegalAccessException, SecurityException {
   // begin bean encoding:
   this.driver.startElement(DTD.ELEMENT_OBJECT);
   Class cls = obj.getClass();
   final String mappedName = this.context.aliasFor(cls);
   this.driver.setAttribute(
       DTD.ATTRIBUTE_CLASS, (mappedName != null ? mappedName : cls.getName()));
   // encode properties:
   while (cls != Object.class) { // process inheritance:
     for (Field f : cls.getDeclaredFields()) { // process composition:
       if (Modifier.isStatic(f.getModifiers())
           || !ReflectionUtil.hasClassFieldProperty(cls, f)
           || this.context.excluded(f)) {
         continue; // skip static or non-property or excluded field.
       }
       // get property field:
       if (!f.isAccessible()) {
         f.setAccessible(true);
       }
       // write property value:
       final String aliasedFieldName = this.context.aliasFor(f, f.getName());
       this.driver.startElement(aliasedFieldName);
       this.write0(f.get(obj));
       this.driver.endElement();
     }
     cls = cls.getSuperclass();
   }
   // end bean encoding:
   this.driver.endElement();
 }