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

org.yangcentral.yangkit.data.codec.xml.YangDataXmlCodecException Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
package org.yangcentral.yangkit.data.codec.xml;

import org.yangcentral.yangkit.common.api.exception.ErrorMessage;
import org.yangcentral.yangkit.common.api.exception.ErrorTag;
import org.yangcentral.yangkit.common.api.exception.Severity;
import org.yangcentral.yangkit.common.api.validate.ValidatorRecord;
import org.dom4j.Element;

import java.util.Objects;

public class YangDataXmlCodecException extends Exception implements ValidatorRecord {
    private String errorPath;
    private Element badElement;
    private ErrorTag errorTag;
    private ErrorMessage errorMessage;
    private String errorAppTag;

    public YangDataXmlCodecException(String errorPath, Element badElement, ErrorTag errorTag, String errorAppTag,
                                     ErrorMessage errorMessage) {
        this.errorPath = errorPath;
        this.badElement = badElement;
        this.errorTag = errorTag;
        this.errorAppTag = errorAppTag;
        this.errorMessage = errorMessage;
    }
    public YangDataXmlCodecException(String errorPath, Element badElement, ErrorTag errorTag, String errorMessage) {
        this.errorPath = errorPath;
        this.badElement = badElement;
        this.errorTag = errorTag;
        this.errorMessage = new ErrorMessage(errorMessage);
    }
    public YangDataXmlCodecException(String errorPath, Element badElement, ErrorTag errorTag) {
        this.errorPath = errorPath;
        this.badElement = badElement;
        this.errorTag = errorTag;
    }

    public String getErrorPath() {
        return errorPath;
    }

    public Element getBadElement() {
        return badElement;
    }

    @Override
    public ErrorMessage getErrorMsg() {
        return errorMessage;
    }

    @Override
    public Severity getSeverity() {
        return Severity.ERROR;
    }

    public ErrorTag getErrorTag() {
        return errorTag;
    }

    @Override
    public String getErrorAppTag() {
        return null;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof YangDataXmlCodecException)) return false;
        YangDataXmlCodecException that = (YangDataXmlCodecException) o;
        return getErrorPath().equals(that.getErrorPath()) &&
                getBadElement().equals(that.getBadElement()) &&
                getErrorTag() == that.getErrorTag() &&
                Objects.equals(getErrorMsg(), that.getErrorMsg());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getErrorPath(), getBadElement(), getErrorTag(), getErrorMsg());
    }

    @Override
    public String toString() {
        return "YangDataXmlCodecException{" +
                "errorPath=" + errorPath +
                ", badElement=" + badElement +
                ", errorTag=" + errorTag +
                ", errorMessage=" + errorMessage.getMessage() +
                '}';
    }

    @Override
    public int compareTo(ValidatorRecord o) {
        if(this.getErrorPath().hashCode() != o.getErrorPath().hashCode()){
            return this.getErrorPath().hashCode() - o.getErrorPath().hashCode();
        }
        return this.hashCode() - o.hashCode();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy