+
+ this.childAddressabilitySummary = computeChildAddressabilitySummary(nodeSchema);
+ }
+
+ private static ChildAddressabilitySummary computeChildAddressabilitySummary(final Object nodeSchema) {
+ if (nodeSchema instanceof DataNodeContainer) {
+ boolean haveAddressable = false;
+ boolean haveUnaddressable = false;
+ for (DataSchemaNode child : ((DataNodeContainer) nodeSchema).getChildNodes()) {
+ if (child instanceof ContainerSchemaNode || child instanceof AugmentationSchema) {
+ haveAddressable = true;
+ } else if (child instanceof ListSchemaNode) {
+ if (((ListSchemaNode) child).getKeyDefinition().isEmpty()) {
+ haveUnaddressable = true;
+ } else {
+ haveAddressable = true;
+ }
+ } else if (child instanceof AnyDataSchemaNode || child instanceof AnyXmlSchemaNode
+ || child instanceof TypedSchemaNode) {
+ haveUnaddressable = true;
+ } else if (child instanceof ChoiceSchemaNode) {
+ switch (computeChildAddressabilitySummary(child)) {
+ case ADDRESSABLE:
+ haveAddressable = true;
+ break;
+ case MIXED:
+ haveAddressable = true;
+ haveUnaddressable = true;
+ break;
+ case UNADDRESSABLE:
+ haveUnaddressable = true;
+ break;
+ default:
+ throw new IllegalStateException("Unhandled accessibility summary for " + child);
+ }
+ } else {
+ LOG.warn("Unhandled child node {}", child);
+ }
+ }
+
+ if (!haveAddressable) {
+ // Empty or all are unaddressable
+ return ChildAddressabilitySummary.UNADDRESSABLE;
+ }
+
+ return haveUnaddressable ? ChildAddressabilitySummary.MIXED : ChildAddressabilitySummary.ADDRESSABLE;
+ } else if (nodeSchema instanceof ChoiceSchemaNode) {
+ boolean haveAddressable = false;
+ boolean haveUnaddressable = false;
+ for (ChoiceCaseNode child : ((ChoiceSchemaNode) nodeSchema).getCases()) {
+ switch (computeChildAddressabilitySummary(child)) {
+ case ADDRESSABLE:
+ haveAddressable = true;
+ break;
+ case UNADDRESSABLE:
+ haveUnaddressable = true;
+ break;
+ case MIXED:
+ // A child is mixed, which means we are mixed, too
+ return ChildAddressabilitySummary.MIXED;
+ default:
+ throw new IllegalStateException("Unhandled accessibility summary for " + child);
+ }
+ }
+
+ if (!haveAddressable) {
+ // Empty or all are unaddressable
+ return ChildAddressabilitySummary.UNADDRESSABLE;
+ }
+
+ return haveUnaddressable ? ChildAddressabilitySummary.MIXED : ChildAddressabilitySummary.ADDRESSABLE;
+ }
+
+ // No child nodes possible: return unaddressable
+ return ChildAddressabilitySummary.UNADDRESSABLE;