All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alipay.v3.util.schema.model.attribute.SingleAttribute Maven / Gradle / Ivy

There is a newer version: 3.1.6.ALL
Show newest version
/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.alipay.v3.util.schema.model.attribute;

import com.alipay.v3.util.schema.exception.SchemaException;
import com.alipay.v3.util.schema.util.StringUtil;
import com.alipay.v3.util.schema.util.XmlUtils;
import org.dom4j.Element;

/**
 * 单值属性
 *
 * @author hongbi.wang
 * @version $Id: SingleAttribute.java, v 0.1 2021年02月26日 5:45 PM hongbi.wang Exp $
 */
public class SingleAttribute extends Attribute {

    private String value;

    @Override
    public Element toElement() throws SchemaException {
        checkAttribute();
        Element attributeNode = XmlUtils.createRootElement("attribute");
        attributeNode.addAttribute("id", this.getId());
        attributeNode.addAttribute("name", this.getName());
        attributeNode.addAttribute("type", this.getType().getType());
        attributeNode.addAttribute("valueType", this.getValueType().getCode());
        Element valueNode = XmlUtils.appendElement(attributeNode, "value");
        if (!StringUtil.isEmpty(this.value)) {
            valueNode.setText(value);
        }

        appendRulesElement(attributeNode, this.getRules(), this.getId());

        appendOptionsElement(attributeNode, this.getOptions(), this.getId());

        return attributeNode;
    }

    @Override
    public Element toValueElement() throws SchemaException {
        checkAttribute();
        Element attributeNode = XmlUtils.createRootElement("attribute");
        attributeNode.addAttribute("id", this.getId());
        attributeNode.addAttribute("name", this.getName());
        attributeNode.addAttribute("type", this.getType().getType());
        attributeNode.addAttribute("valueType", this.getValueType().getCode());
        Element valueNode = XmlUtils.appendElement(attributeNode, "value");
        if (!StringUtil.isEmpty(this.value)) {
            valueNode.setText(value);
        }

        return attributeNode;
    }

    /**
     * Getter method for property value.
     *
     * @return property value of value
     */
    public String getValue() {
        return value;
    }

    /**
     * Setter method for property value.
     *
     * @param value value to be assigned to property value
     */
    public void setValue(String value) {
        this.value = value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy