コード例 #1
0
  /**
   * 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());
    }
  }
コード例 #2
0
 /**
  * Performs the writing of a {@link Font} object.
  *
  * @param tagName the tag name.
  * @param object the {@link Font} 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 Font font = (Font) object;
   final AttributeList attribs = new AttributeList();
   if (mPlexAttribute != null) {
     attribs.setAttribute(mPlexAttribute, mPlexValue);
   }
   attribs.setAttribute("family", font.getFamily());
   attribs.setAttribute("size", String.valueOf(font.getSize()));
   attribs.setAttribute("style", String.valueOf(getFontStyle(font)));
   writer.writeTag(tagName, attribs, true);
 }
コード例 #3
0
 /**
  * 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);
 }