org.yangcentral.yangkit.model.impl.stmt.DataNodeImpl Maven / Gradle / Ivy
package org.yangcentral.yangkit.model.impl.stmt;
import org.yangcentral.yangkit.base.YangBuiltinKeyword;
import org.yangcentral.yangkit.base.YangContext;
import org.yangcentral.yangkit.common.api.QName;
import org.yangcentral.yangkit.common.api.validate.ValidatorResult;
import org.yangcentral.yangkit.common.api.validate.ValidatorResultBuilder;
import org.yangcentral.yangkit.model.api.stmt.DataNode;
import org.yangcentral.yangkit.model.api.stmt.Must;
import org.yangcentral.yangkit.model.api.stmt.YangStatement;
import java.util.ArrayList;
import java.util.List;
public abstract class DataNodeImpl extends SchemaDataNodeImpl implements DataNode {
private MustSupportImpl mustSupport = new MustSupportImpl();
private QName identifier;
public DataNodeImpl(String argStr) {
super(argStr);
}
public void setContext(YangContext context) {
super.setContext(context);
this.mustSupport.setContextNode(this);
this.mustSupport.setSelf(this);
}
public Must getMust(int index) {
return this.mustSupport.getMust(index);
}
public Must getMust(String condition) {
return this.mustSupport.getMust(condition);
}
public List getMusts() {
return this.mustSupport.getMusts();
}
public void setMusts(List musts) {
this.mustSupport.setMusts(musts);
}
public ValidatorResult addMust(Must must) {
return this.mustSupport.addMust(must);
}
public void removeMust(String condition) {
this.mustSupport.removeMust(condition);
}
public ValidatorResult updateMust(Must must) {
return this.mustSupport.updateMust(must);
}
public ValidatorResult validateMusts() {
return this.mustSupport.validateMusts();
}
@Override
public boolean checkChild(YangStatement subStatement) {
boolean result = super.checkChild(subStatement);
if(!result){
return false;
}
YangBuiltinKeyword builtinKeyword = YangBuiltinKeyword.from(subStatement.getYangKeyword());
switch (builtinKeyword){
case MUST:{
if(getMust(subStatement.getArgStr()) != null){
return false;
}
return true;
}
default:{
return true;
}
}
}
@Override
protected void clearSelf() {
this.mustSupport.removeMusts();
identifier = null;
super.clearSelf();
}
protected ValidatorResult initSelf() {
ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder();
validatorResultBuilder.merge(super.initSelf());
List matched = this.getSubStatement(YangBuiltinKeyword.MUST.getQName());
if (matched.size() != 0) {
for (YangStatement statement : matched) {
validatorResultBuilder.merge(this.mustSupport.addMust((Must) statement));
}
}
return validatorResultBuilder.build();
}
protected ValidatorResult validateSelf() {
ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder(super.validateSelf());
validatorResultBuilder.merge(this.validateMusts());
return validatorResultBuilder.build();
}
public QName getIdentifier() {
if (this.identifier != null) {
return this.identifier;
} else {
this.identifier = new QName(this.getContext().getNamespace(), this.getArgStr());
return this.identifier;
}
}
public List getEffectiveSubStatements() {
List statements = new ArrayList<>();
statements.addAll(this.mustSupport.getMusts());
statements.addAll(super.getEffectiveSubStatements());
return statements;
}
}