org.yangcentral.yangkit.model.impl.stmt.NotificationImpl Maven / Gradle / Ivy
package org.yangcentral.yangkit.model.impl.stmt;
import org.yangcentral.yangkit.base.BuildPhase;
import org.yangcentral.yangkit.base.YangBuiltinKeyword;
import org.yangcentral.yangkit.base.YangContext;
import org.yangcentral.yangkit.base.YangElement;
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.DataDefinition;
import org.yangcentral.yangkit.model.api.stmt.DataNode;
import org.yangcentral.yangkit.model.api.stmt.Grouping;
import org.yangcentral.yangkit.model.api.stmt.IfFeature;
import org.yangcentral.yangkit.model.api.stmt.Must;
import org.yangcentral.yangkit.model.api.stmt.Notification;
import org.yangcentral.yangkit.model.api.stmt.SchemaNode;
import org.yangcentral.yangkit.model.api.stmt.Typedef;
import org.yangcentral.yangkit.model.api.stmt.YangBuiltinStatement;
import org.yangcentral.yangkit.model.api.stmt.YangStatement;
import java.util.ArrayList;
import java.util.List;
public class NotificationImpl extends SchemaNodeImpl implements Notification {
private DataDefContainerImpl dataDefContainer = new DataDefContainerImpl();
private IfFeatureSupportImpl ifFeatureSupport = new IfFeatureSupportImpl();
private GroupingDefContainerImpl groupingDefContainer = new GroupingDefContainerImpl();
private TypedefContainerImpl typedefContainer = new TypedefContainerImpl();
private SchemaNodeContainerImpl schemaNodeContainer = new SchemaNodeContainerImpl(this);
private MustSupportImpl mustSupport = new MustSupportImpl();
private QName identifier;
public NotificationImpl(String argStr) {
super(argStr);
}
public void setContext(YangContext context) {
super.setContext(context);
this.dataDefContainer.setYangContext(context);
this.ifFeatureSupport.setYangContext(context);
this.groupingDefContainer.setYangContext(context);
this.typedefContainer.setYangContext(context);
this.schemaNodeContainer.setYangContext(context);
this.mustSupport.setContextNode(this);
this.mustSupport.setSelf(this);
}
public List getDataDefChildren() {
return this.dataDefContainer.getDataDefChildren();
}
public DataDefinition getDataDefChild(String name) {
return this.dataDefContainer.getDataDefChild(name);
}
public ValidatorResult addDataDefChild(DataDefinition dataDefinition) {
return this.dataDefContainer.addDataDefChild(dataDefinition);
}
public List getGroupings() {
return this.groupingDefContainer.getGroupings();
}
public Grouping getGrouping(String name) {
return this.groupingDefContainer.getGrouping(name);
}
public List getIfFeatures() {
return this.ifFeatureSupport.getIfFeatures();
}
public ValidatorResult addIfFeature(IfFeature ifFeature) {
return this.ifFeatureSupport.addIfFeature(ifFeature);
}
@Override
public IfFeature getIfFeature(String exp) {
return ifFeatureSupport.getIfFeature(exp);
}
@Override
public IfFeature removeIfFeature(String exp) {
return ifFeatureSupport.removeIfFeature(exp);
}
public void setIfFeatures(List ifFeatures) {
this.ifFeatureSupport.setIfFeatures(ifFeatures);
}
public boolean evaluateFeatures() {
return this.ifFeatureSupport.evaluateFeatures();
}
public List getSchemaNodeChildren() {
return this.schemaNodeContainer.getSchemaNodeChildren();
}
public ValidatorResult addSchemaNodeChild(SchemaNode schemaNode) {
return this.schemaNodeContainer.addSchemaNodeChild(schemaNode);
}
public ValidatorResult addSchemaNodeChildren(List schemaNodes) {
return this.schemaNodeContainer.addSchemaNodeChildren(schemaNodes);
}
public SchemaNode getSchemaNodeChild(QName identifier) {
return this.schemaNodeContainer.getSchemaNodeChild(identifier);
}
public DataNode getDataNodeChild(QName identifier) {
return this.schemaNodeContainer.getDataNodeChild(identifier);
}
public List getDataNodeChildren() {
return this.schemaNodeContainer.getDataNodeChildren();
}
@Override
public List getTreeNodeChildren() {
return schemaNodeContainer.getTreeNodeChildren();
}
@Override
public SchemaNode getTreeNodeChild(QName identifier) {
return schemaNodeContainer.getTreeNodeChild(identifier);
}
public void removeSchemaNodeChild(QName identifier) {
this.schemaNodeContainer.removeSchemaNodeChild(identifier);
}
public void removeSchemaNodeChild(SchemaNode schemaNode) {
this.schemaNodeContainer.removeSchemaNodeChild(schemaNode);
}
public SchemaNode getMandatoryDescendant() {
return this.schemaNodeContainer.getMandatoryDescendant();
}
public List getTypedefs() {
return this.typedefContainer.getTypedefs();
}
public Typedef getTypedef(int index) {
return this.typedefContainer.getTypedef(index);
}
public Typedef getTypedef(String defName) {
return this.typedefContainer.getTypedef(defName);
}
public QName getYangKeyword() {
return YangBuiltinKeyword.NOTIFICATION.getQName();
}
@Override
public boolean checkChild(YangStatement subStatement) {
boolean result = super.checkChild(subStatement);
if(!result){
return false;
}
YangBuiltinKeyword builtinKeyword = YangBuiltinKeyword.from(subStatement.getYangKeyword());
switch (builtinKeyword){
case TYPEDEF:{
if(getTypedef(subStatement.getArgStr()) != null){
return false;
}
return true;
}
case GROUPING:{
if(getGrouping(subStatement.getArgStr()) != null){
return false;
}
return true;
}
case CONTAINER:
case LIST:
case LEAF:
case LEAFLIST:
case ANYDATA:
case ANYXML:
case CHOICE: {
if(getContext().getSchemaNodeIdentifierCache().containsKey(subStatement.getArgStr())){
return false;
}
return true;
}
case MUST:{
if(getMust(subStatement.getArgStr()) != null){
return false;
}
return true;
}
case IFFEATURE:{
if(getIfFeature(subStatement.getArgStr())!= null){
return false;
}
return true;
}
default:{
return true;
}
}
}
@Override
protected void clearSelf() {
this.typedefContainer.removeTypedefs();
this.groupingDefContainer.removeGroupings();
this.dataDefContainer.removeDataDefs();
this.ifFeatureSupport.removeIfFeatures();
this.mustSupport.removeMusts();
this.schemaNodeContainer.removeSchemaNodeChildren();
super.clearSelf();
}
protected ValidatorResult initSelf() {
ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder();
validatorResultBuilder.merge(super.initSelf());
List subElements = this.getSubElements();
for (YangElement subElement : subElements) {
if (subElement instanceof YangBuiltinStatement) {
YangBuiltinStatement builtinStatement = (YangBuiltinStatement) subElement;
YangBuiltinKeyword builtinKeyword = YangBuiltinKeyword.from(builtinStatement.getYangKeyword());
switch (builtinKeyword) {
case TYPEDEF:
Typedef newTypedef = (Typedef) builtinStatement;
validatorResultBuilder.merge(this.typedefContainer.addTypedef(newTypedef));
break;
case GROUPING:
Grouping newGrouping = (Grouping) builtinStatement;
validatorResultBuilder.merge(this.groupingDefContainer.addGrouping(newGrouping));
break;
case CONTAINER:
case LIST:
case LEAF:
case LEAFLIST:
case ANYDATA:
case ANYXML:
case CHOICE:
case USES:
DataDefinition newDataDefinition = (DataDefinition) builtinStatement;
validatorResultBuilder.merge(this.addDataDefChild(newDataDefinition));
break;
case IFFEATURE:
IfFeature ifFeature = (IfFeature) builtinStatement;
validatorResultBuilder.merge(this.addIfFeature(ifFeature));
break;
case MUST:
Must must = (Must) builtinStatement;
validatorResultBuilder.merge(this.addMust(must));
}
}
}
return validatorResultBuilder.build();
}
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();
}
protected ValidatorResult validateSelf() {
ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder(super.validateSelf());
validatorResultBuilder.merge(this.validateMusts());
return validatorResultBuilder.build();
}
protected ValidatorResult buildSelf(BuildPhase phase) {
ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder(super.buildSelf(phase));
switch (phase) {
case SCHEMA_BUILD:
for (DataDefinition dataDefinition : this.getDataDefChildren()) {
validatorResultBuilder.merge(this.addSchemaNodeChild(dataDefinition));
}
default:
return validatorResultBuilder.build();
}
}
public boolean isConfig() {
return false;
}
public QName getIdentifier() {
if (this.identifier != null) {
return this.identifier;
} else {
this.identifier = new QName(this.getContext().getNamespace(), this.getArgStr());
return this.identifier;
}
}
@Override
public List getEffectiveSchemaNodeChildren(boolean ignoreNamespace) {
return schemaNodeContainer.getEffectiveSchemaNodeChildren(ignoreNamespace);
}
public List getEffectiveSubStatements() {
List statements = new ArrayList<>();
statements.addAll(getEffectiveSchemaNodeChildren());
statements.addAll(this.ifFeatureSupport.getIfFeatures());
statements.addAll(this.groupingDefContainer.getGroupings());
statements.addAll(this.typedefContainer.getTypedefs());
statements.addAll(this.mustSupport.getMusts());
statements.addAll(super.getEffectiveSubStatements());
return statements;
}
}