public synchronized void write(GenericObject object) throws IOException
  {
    if (!headerWritten)
    {
      Logger.debug("writing xml header");
      os.write(("<?xml version=\"1.0\" encoding=\"" + ENCODING + "\"?>\n<objects>\n").getBytes(ENCODING));
      headerWritten = true;
    }
    Logger.debug("serializing object: " + object.getClass().getName() + ":" + object.getID());
    StringBuffer sb = new StringBuffer();
    sb.append("  <object type=\"");
    sb.append(object.getClass().getName());
    sb.append("\" id=\"");
    sb.append(object.getID());
    sb.append("\">\n");
    String[] names = getAttributeNames(object);
    for (int i=0;i<names.length;++i)
    {
      Object o = object.getAttribute(names[i]);
      if (o == null)
        continue;

      String type = o.getClass().getName();
      if (o instanceof GenericObject)
      {
        type = Integer.class.getName();
        o = ((GenericObject)o).getID();
      }

      sb.append("    <");
      sb.append(names[i]);
      sb.append(" type=\"");
      sb.append(type);
      sb.append("\">");
      
      Value v = (Value) valueMap.get(type);
      if (v == null) v = (Value) valueMap.get(null);
      
      sb.append(encode(v.serialize(o)));
      sb.append("</");
      sb.append(names[i]);
      sb.append(">\n");
    }
    sb.append("  </object>\n");
    os.write(sb.toString().getBytes(ENCODING));
  }