⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modelwriter.java

📁 该源代码为一些通用的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ========================================================================
 * JCommon : a free general purpose class library for the Java(tm) platform
 * ========================================================================
 *
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 * 
 * Project Info:  http://www.jfree.org/jcommon/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 * 
 * ----------------
 * ModelWriter.java
 * ----------------
 * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * $Id: ModelWriter.java,v 1.3 2005/10/18 13:32:20 mungady Exp $
 *
 * Changes
 * -------------------------
 * 21.06.2003 : Initial version
 *
 */

package org.jfree.xml.generator;

import java.io.IOException;
import java.io.Writer;

import org.jfree.xml.generator.model.ClassDescription;
import org.jfree.xml.generator.model.Comments;
import org.jfree.xml.generator.model.DescriptionModel;
import org.jfree.xml.generator.model.IgnoredPropertyInfo;
import org.jfree.xml.generator.model.ManualMappingInfo;
import org.jfree.xml.generator.model.MultiplexMappingInfo;
import org.jfree.xml.generator.model.PropertyInfo;
import org.jfree.xml.generator.model.PropertyType;
import org.jfree.xml.generator.model.TypeInfo;
import org.jfree.xml.util.ClassModelTags;
import org.jfree.xml.writer.AttributeList;
import org.jfree.xml.writer.SafeTagList;
import org.jfree.xml.writer.XMLWriterSupport;

/**
 * A model writer.
 */
public class ModelWriter {

    /** The tags that can be split. */
    private static SafeTagList safeTags;

    /**
     * Returns the safe tag list.
     * 
     * @return The safe tag list.
     */
    public static SafeTagList getSafeTags() {
        if (safeTags == null) {
            safeTags = new SafeTagList();
            safeTags.add(ClassModelTags.OBJECTS_TAG);
            safeTags.add(ClassModelTags.OBJECT_TAG);
            safeTags.add(ClassModelTags.CONSTRUCTOR_TAG);
            safeTags.add(ClassModelTags.ELEMENT_PROPERTY_TAG);
            safeTags.add(ClassModelTags.LOOKUP_PROPERTY_TAG);
            safeTags.add(ClassModelTags.ATTRIBUTE_PROPERTY_TAG);
            safeTags.add(ClassModelTags.PARAMETER_TAG);
            safeTags.add(ClassModelTags.INCLUDE_TAG);
            safeTags.add(ClassModelTags.IGNORED_PROPERTY_TAG);
            safeTags.add(ClassModelTags.MANUAL_TAG);
            safeTags.add(ClassModelTags.MAPPING_TAG);
            safeTags.add(ClassModelTags.TYPE_TAG);
        }
        return safeTags;
    }

    /** A support class for writing XML tags. */
    private XMLWriterSupport writerSupport;
    
    /** A model containing class descriptions. */
    private DescriptionModel model;

    /**
     * Creates a new model writer instance.
     */
    public ModelWriter() {
        this.writerSupport = new XMLWriterSupport(getSafeTags(), 0);
    }

    /**
     * Returns the model.
     * 
     * @return The model.
     */
    public DescriptionModel getModel() {
        return this.model;
    }

    /**
     * Sets the model to be written.
     * 
     * @param model  the model.
     */
    public void setModel(final DescriptionModel model) {
        this.model = model;
    }

    /**
     * Writes an XML header.
     * 
     * @param writer  the writer.
     * 
     * @throws IOException if there is an I/O problem.
     */
    public static void writeXMLHeader(final Writer writer) throws IOException {
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        writer.write(XMLWriterSupport.getLineSeparator());
    }

    /**
     * Writes a set of comments.
     * 
     * @param writer  the writer.
     * @param comments  a set of comments.
     * 
     * @throws IOException if there is an I/O problem.
     */
    protected void writeStandardComment(final Writer writer, final Comments comments) throws IOException {
        if ((comments == null) || (comments.getOpenTagComment() == null)) {
            writer.write(
                "<!-- CVSTag: $Id: ModelWriter.java,v 1.3 2005/10/18 13:32:20 mungady Exp $ " 
                + comments + " -->"
            );
            writer.write(XMLWriterSupport.getLineSeparator());
        }
        else {
            writeComment(writer, comments.getOpenTagComment());
        }
    }

    /**
     * Writes a sequence of comments.
     * 
     * @param writer  the writer.
     * @param comments  the comments (<code>null</code> ignored).
     * 
     * @throws IOException if there is an I/O problem.
     */
    protected void writeComment(final Writer writer, final String[] comments) throws IOException {
        if (comments == null) {
            return;
        }
        for (int i = 0; i < comments.length; i++) {
            this.writerSupport.indent(writer, XMLWriterSupport.INDENT_ONLY);
            writer.write("<!--");
            writer.write(comments[i]);
            writer.write("-->");
            writer.write(XMLWriterSupport.getLineSeparator());
        }
    }

    /**
     * Writes the open comments from a set of comments.
     * 
     * @param writer  the writer.
     * @param comments  the set of comments.
     * 
     * @throws IOException if there is an I/O problem.
     */
    protected void writeOpenComment(final Writer writer, final Comments comments) throws IOException {
        if (comments == null) {
            return;
        }
        if (comments.getOpenTagComment() == null) {
            return;
        }
        writeComment(writer, comments.getOpenTagComment());
    }

    /**
     * Writes the close comments from a set of comments.
     * 
     * @param writer  the writer.
     * @param comments  the set of comments.
     * 
     * @throws IOException if there is an I/O problem.
     */
    protected void writeCloseComment(final Writer writer, final Comments comments) throws IOException {
        if (comments == null) {
            return;
        }
        if (comments.getCloseTagComment() == null) {
            return;
        }
        writeComment(writer, comments.getCloseTagComment());
    }

    /**
     * Writes a closed (short) tag with eventually nested comments.
     *
     * @param writer  the writer.
     * @param tagName  the tag name.
     * @param attributes  the attributes.
     * @param comments  the comments.
     * 
     * @throws IOException if there is an I/O problem.
     */
    protected void writeTag(final Writer writer, 
                            final String tagName,
                            final AttributeList attributes,
                            final Comments comments) throws IOException {
        if (comments == null) {
            this.writerSupport.writeTag(writer, tagName, attributes, XMLWriterSupport.CLOSE);
        }
        else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -