package me.chyxion.tigon.mybatis;

import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Feb 22, 2017 11:13:43
 */
public class ColsXmlProcessor extends AbstractOnMissingCreateProcessor {

    /**
     * {@inheritDoc}
     */
    @Override
    protected String missingXPathExpression() {
        return "/mapper/sql[@id='cols']";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Element elementToAppend(Class<BaseMapper<?, ?>> mapperClass, Document doc) {
        Element colEl = doc.createElement("sql");
        colEl.setAttribute("id", "cols");
        colEl.setTextContent(
            StringUtils.join(newModelObj(getModelClass(mapperClass)).cols(), ", "));
        return colEl;
    }
}
