/*
 * See LICENSE file in distribution for copyright and licensing information.
 */
package org.yaml.snakeyaml;

import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import org.yaml.snakeyaml.DumperOptions.FlowStyle;
import org.yaml.snakeyaml.resolver.Resolver;

/**
 * Convenience utility to serialise JavaBeans.
 */
public class JavaBeanDumper {
    private boolean useGlobalTag;
    private FlowStyle flowStyle;

    /**
     * Create Dumper for JavaBeans
     * 
     * @param useGlobalTag
     *            true to emit the global tag with the class name
     */
    public JavaBeanDumper(boolean useGlobalTag) {
        this.useGlobalTag = useGlobalTag;
        this.flowStyle = FlowStyle.BLOCK;
    }

    /**
     * Create Dumper for JavaBeans. Use "tag:yaml.org,2002:map" as the root tag.
     */
    public JavaBeanDumper() {
        this(false);
    }

    /**
     * Serialise JavaBean
     * 
     * @param data
     *            JavaBean instance to serialise
     * @param output
     *            destination
     */
    public void dump(Object data, Writer output) {
        DumperOptions options = new DumperOptions();
        if (!useGlobalTag) {
            options.setExplicitRoot("tag:yaml.org,2002:map");
        }
        options.setDefaultFlowStyle(flowStyle);
        Dumper dumper = new Dumper(options);
        List<Object> list = new ArrayList<Object>(1);
        list.add(data);
        dumper.dump(list.iterator(), output, new Resolver());
    }

    /**
     * Serialise JavaBean
     * 
     * @param data
     *            JavaBean instance to serialise
     * @return serialised YAML document
     */
    public String dump(Object data) {
        StringWriter buffer = new StringWriter();
        dump(data, buffer);
        return buffer.toString();
    }

    public boolean isUseGlobalTag() {
        return useGlobalTag;
    }

    public void setUseGlobalTag(boolean useGlobalTag) {
        this.useGlobalTag = useGlobalTag;
    }

    public FlowStyle getFlowStyle() {
        return flowStyle;
    }

    public void setFlowStyle(FlowStyle flowStyle) {
        this.flowStyle = flowStyle;
    }

}

@@ -354,25 +354,25 @@
 y to seriali
-s
+z
 e JavaBeans.
@@ -961,33 +961,33 @@
 %0D%0A     * Seriali
-s
+z
 e JavaBean%0D%0A    
@@ -1049,33 +1049,33 @@
 tance to seriali
-s
+z
 e%0D%0A     * @param
@@ -1603,17 +1603,17 @@
  Seriali
-s
+z
 e JavaBe
@@ -1691,17 +1691,17 @@
  seriali
-s
+z
 e%0D%0A     
@@ -1717,17 +1717,17 @@
  seriali
-s
+z
 ed YAML 

use 'serialiZe' in comments