/**
   * Performs the writing of a generic object.
   *
   * @param tagName the tag name.
   * @param object the generic object.
   * @param writer the writer.
   * @param mPlexAttribute ??.
   * @param mPlexValue ??.
   * @throws IOException if there is an I/O error.
   * @throws XMLWriterException if there is a writer error.
   */
  public void write(
      String tagName, Object object, XMLWriter writer, String mPlexAttribute, String mPlexValue)
      throws IOException, XMLWriterException {

    try {
      this.factory.readProperties(object);

      AttributeList attributes = new AttributeList();
      if (mPlexAttribute != null) {
        attributes.setAttribute(mPlexAttribute, mPlexValue);
      }
      AttributeDefinition[] attribDefs = this.factory.getAttributeDefinitions();
      ArrayList properties = new ArrayList();
      for (int i = 0; i < attribDefs.length; i++) {
        AttributeDefinition adef = attribDefs[i];
        String pName = adef.getAttributeName();
        Object propValue = this.factory.getProperty(adef.getPropertyName());
        if (propValue != null) {
          Log.debug("Here: " + this.factory.getBaseClass() + " -> " + adef.getPropertyName());
          String value = adef.getHandler().toAttributeValue(propValue);
          if (value != null) {
            attributes.setAttribute(pName, value);
          }
        }
        properties.add(adef.getPropertyName());
      }
      writer.writeTag(tagName, attributes, false);
      writer.startBlock();

      PropertyDefinition[] propertyDefs = this.factory.getPropertyDefinitions();
      RootXmlWriteHandler rootHandler = getRootHandler();
      for (int i = 0; i < propertyDefs.length; i++) {
        PropertyDefinition pDef = propertyDefs[i];
        String elementName = pDef.getElementName();
        // System.out.println("Searching: " + elementName + " [" + object.getClass() + "]");
        rootHandler.write(
            elementName,
            this.factory.getProperty(pDef.getPropertyName()),
            this.factory.getTypeForTagName(elementName),
            writer);
      }
      writer.endBlock();
      writer.writeCloseTag(tagName);
    } catch (ObjectDescriptionException ode) {
      Log.warn("Unable to write element", ode);
      throw new IOException(ode.getMessage());
    }
  }
 /**
  * Performs the writing of a {@link GradientPaint} object.
  *
  * @param tagName the tag name.
  * @param object the {@link GradientPaint} object.
  * @param writer the writer.
  * @param mPlexAttribute ??.
  * @param mPlexValue ??.
  * @throws IOException if there is an I/O error.
  * @throws XMLWriterException if there is a writer error.
  */
 public void write(
     final String tagName,
     final Object object,
     final XMLWriter writer,
     final String mPlexAttribute,
     final String mPlexValue)
     throws IOException, XMLWriterException {
   final GradientPaint paint = (GradientPaint) object;
   writer.writeTag(tagName, mPlexAttribute, mPlexValue, false);
   writer.startBlock();
   final RootXmlWriteHandler rootHandler = getRootHandler();
   rootHandler.write("color1", paint.getColor1(), Color.class, writer);
   writer.allowLineBreak();
   rootHandler.write("color2", paint.getColor2(), Color.class, writer);
   writer.allowLineBreak();
   rootHandler.write("point1", paint.getPoint1(), Point2D.class, writer);
   writer.allowLineBreak();
   rootHandler.write("point2", paint.getPoint2(), Point2D.class, writer);
   writer.endBlock();
   writer.writeCloseTag(tagName);
 }