com.alipay.v3.util.schema.model.rule.AttributeRule Maven / Gradle / Ivy
/**
* Alipay.com Inc.
* Copyright (c) 2004-2021 All Rights Reserved.
*/
package com.alipay.v3.util.schema.model.rule;
import com.alipay.v3.util.schema.exception.SchemaException;
import com.alipay.v3.util.schema.model.enums.AttrRuleTypeEnum;
import com.alipay.v3.util.schema.model.enums.SchemaErrorEnum;
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: AttributeRule.java, v 0.1 2021年03月01日 11:13 AM hongbi.wang Exp $
*/
public class AttributeRule {
private String name;
private AttrRuleTypeEnum type;
private String value;
public Element toElement(String attributeId) throws SchemaException {
Element rule = XmlUtils.createRootElement("rule");
if (type == null) {
throw new SchemaException(SchemaErrorEnum.ATTR_RULE_TYPE_ERROR, attributeId);
}
if (StringUtil.isEmpty(this.name)) {
throw new SchemaException(SchemaErrorEnum.ATTR_RULE_NAME_ERROR, attributeId);
}
if (StringUtil.isEmpty(this.value)) {
throw new SchemaException(SchemaErrorEnum.ATTR_RULE_VALUE_ERROR, attributeId);
}
rule.addAttribute("type", this.getType().getCode());
rule.addAttribute("name", this.name);
rule.addAttribute("value", this.value);
//for Special
return rule;
}
/**
* Getter method for property name.
*
* @return property value of name
*/
public String getName() {
return name;
}
/**
* Setter method for property name.
*
* @param name value to be assigned to property name
*/
public void setName(String name) {
this.name = name;
}
/**
* Getter method for property type.
*
* @return property value of type
*/
public AttrRuleTypeEnum getType() {
return type;
}
/**
* Setter method for property type.
*
* @param type value to be assigned to property type
*/
public void setType(AttrRuleTypeEnum type) {
this.type = type;
}
/**
* 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;
}
}