// Path: src/main/java/me/hao0/wechat/exception/XmlException.java
// public class XmlException extends RuntimeException {
// 
//     public XmlException() {
//         super();
//     }
// 
//     public XmlException(String message) {
//         super(message);
//     }
// 
//     public XmlException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public XmlException(Throwable cause) {
//         super(cause);
//     }
// 
//     protected XmlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }


import me.hao0.wechat.exception.XmlException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package me.hao0.wechat.utils;


/**
 * 一个简陋的微信XML构建器
 * Author: haolin
 * Email: haolin.h0@gmail.com
 * Date: 6/11/15
 */
public class XmlWriters {

    List<E> es = new ArrayList<>();

    private XmlWriters(){}

    public static XmlWriters create(){
        return new XmlWriters();
    }

    public XmlWriters element(String name, String text){
        E e = new TextE(name, text);
        es.add(e);
        return this;
    }

    public XmlWriters element(String name, Number number){
        E e = new NumberE(name, number);
        es.add(e);
        return this;
    }

    public XmlWriters element(String parentName, String childName, String childText){
        return element(parentName, new TextE(childName, childText));
    }

    public XmlWriters element(String parentName, String childName, Number childNumber){
        return element(parentName, new NumberE(childName, childNumber));
    }

    /**
     * 构建包含多个子元素的元素
     * @param parentName 父元素标签名
     * @param childPairs childName1, childValue1, childName2, childValu2, ...，长度必读为2的倍数
     * @return this
     */
    public XmlWriters element(String parentName, Object... childPairs){
        if (childPairs.length % 2 != 0){
// Path: src/main/java/me/hao0/wechat/exception/XmlException.java
// public class XmlException extends RuntimeException {
// 
//     public XmlException() {
//         super();
//     }
// 
//     public XmlException(String message) {
//         super(message);
//     }
// 
//     public XmlException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public XmlException(Throwable cause) {
//         super(cause);
//     }
// 
//     protected XmlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }


// Path: src/main/java/me/hao0/wechat/utils/XmlWriters.java
import me.hao0.wechat.exception.XmlException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

package me.hao0.wechat.utils;


/**
 * 一个简陋的微信XML构建器
 * Author: haolin
 * Email: haolin.h0@gmail.com
 * Date: 6/11/15
 */
public class XmlWriters {

    List<E> es = new ArrayList<>();

    private XmlWriters(){}

    public static XmlWriters create(){
        return new XmlWriters();
    }

    public XmlWriters element(String name, String text){
        E e = new TextE(name, text);
        es.add(e);
        return this;
    }

    public XmlWriters element(String name, Number number){
        E e = new NumberE(name, number);
        es.add(e);
        return this;
    }

    public XmlWriters element(String parentName, String childName, String childText){
        return element(parentName, new TextE(childName, childText));
    }

    public XmlWriters element(String parentName, String childName, Number childNumber){
        return element(parentName, new NumberE(childName, childNumber));
    }

    /**
     * 构建包含多个子元素的元素
     * @param parentName 父元素标签名
     * @param childPairs childName1, childValue1, childName2, childValu2, ...，长度必读为2的倍数
     * @return this
     */
    public XmlWriters element(String parentName, Object... childPairs){
        if (childPairs.length % 2 != 0){
            throw new XmlException("var args's length must % 2 = 0");