+ public static Boolean getConfig(final ParseTree ctx, final Builder parent, final String moduleName, final int line) {
+ Boolean result = null;
+ // parse configuration statement
+ Boolean configuration = null;
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ ParseTree child = ctx.getChild(i);
+ if (child instanceof Config_stmtContext) {
+ configuration = parseConfig((Config_stmtContext) child);
+ break;
+ }
+ }
+
+ // If 'config' is not specified, the default is the same as the parent
+ // schema node's 'config' value
+ if (configuration == null) {
+ if (parent instanceof ConfigNode) {
+ Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+ // If the parent node is a rpc input or output, it can has
+ // config set to null
+ result = parentConfig == null ? true : parentConfig;
+ } else if (parent instanceof ChoiceCaseBuilder) {
+ // If the parent node is a 'case' node, the value is the same as
+ // the 'case' node's parent 'choice' node
+ ChoiceCaseBuilder choiceCase = (ChoiceCaseBuilder) parent;
+ ChoiceBuilder choice = choiceCase.getParent();
+ Boolean parentConfig = null;
+ if (choice == null) {
+ parentConfig = true;
+ } else {
+ parentConfig = choice.isConfiguration();
+ }
+ result = parentConfig;
+ } else {
+ result = true;
+ }
+ } else {
+ // Check first: if a node has 'config' set to 'false', no node
+ // underneath it can have 'config' set to 'true'
+ if (parent instanceof ConfigNode) {
+ Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+ if (parentConfig == false && configuration == true) {
+ throw new YangParseException(moduleName, line,
+ "Can not set 'config' to 'true' if parent node has 'config' set to 'false'");
+ }
+ }
+ result = configuration;
+ }
+
+ return result;
+ }
+