-final class LazyDataObjectModification<T extends DataObject> implements DataObjectModification<T> {
-
- private static final Logger LOG = LoggerFactory.getLogger(LazyDataObjectModification.class);
-
- private final BindingCodecTreeNode<T> codec;
- private final DataTreeCandidateNode domData;
- private final PathArgument identifier;
-
- private volatile Collection<LazyDataObjectModification<? extends DataObject>> childNodesCache;
- private volatile ModificationType modificationType;
-
- private LazyDataObjectModification(final BindingCodecTreeNode<T> codec, final DataTreeCandidateNode domData) {
- this.codec = requireNonNull(codec);
- this.domData = requireNonNull(domData);
- this.identifier = codec.deserializePathArgument(domData.getIdentifier());
- }
-
- static <T extends DataObject> LazyDataObjectModification<T> create(final BindingCodecTreeNode<T> codec,
- final DataTreeCandidateNode domData) {
- return new LazyDataObjectModification<>(codec, domData);
- }
-
- private static Collection<LazyDataObjectModification<? extends DataObject>> from(final BindingCodecTreeNode<?>
- parentCodec, final Collection<DataTreeCandidateNode> domChildNodes) {
- final List<LazyDataObjectModification<? extends DataObject>> result = new ArrayList<>(domChildNodes.size());
- populateList(result, parentCodec, domChildNodes);
- return result;
- }
-
- private static void populateList(final List<LazyDataObjectModification<? extends DataObject>> result,
- final BindingCodecTreeNode<?> parentCodec, final Collection<DataTreeCandidateNode> domChildNodes) {
- for (final DataTreeCandidateNode domChildNode : domChildNodes) {
- if (domChildNode.getModificationType() != UNMODIFIED) {
- final BindingStructuralType type = BindingStructuralType.from(domChildNode);
- if (type != BindingStructuralType.NOT_ADDRESSABLE) {
- /*
- * Even if type is UNKNOWN, from perspective of BindingStructuralType
- * we try to load codec for it. We will use that type to further specify
- * debug log.
- */
- try {
- final BindingCodecTreeNode<?> childCodec =
- parentCodec.yangPathArgumentChild(domChildNode.getIdentifier());
- populateList(result, type, childCodec, domChildNode);
- } catch (final IllegalArgumentException e) {
- if (type == BindingStructuralType.UNKNOWN) {
- LOG.debug("Unable to deserialize unknown DOM node {}", domChildNode, e);
- } else {
- LOG.debug("Binding representation for DOM node {} was not found", domChildNode, e);
- }
- }
- }
- }
- }
- }
-
- private static void populateList(final List<LazyDataObjectModification<? extends DataObject>> result,
- final BindingStructuralType type, final BindingCodecTreeNode<?> childCodec,
- final DataTreeCandidateNode domChildNode) {
- switch (type) {
- case INVISIBLE_LIST:
- // We use parent codec intentionally.
- populateListWithSingleCodec(result, childCodec, domChildNode.getChildNodes());
- break;
- case INVISIBLE_CONTAINER:
- populateList(result, childCodec, domChildNode.getChildNodes());
- break;
- case UNKNOWN:
- case VISIBLE_CONTAINER:
- result.add(create(childCodec, domChildNode));
- break;
- default:
- }
- }
-
- private static void populateListWithSingleCodec(final List<LazyDataObjectModification<? extends DataObject>> result,
- final BindingCodecTreeNode<?> codec, final Collection<DataTreeCandidateNode> childNodes) {
- for (final DataTreeCandidateNode child : childNodes) {
- if (child.getModificationType() != UNMODIFIED) {
- result.add(create(codec, child));
- }
- }
- }
-
- @Override
- public T getDataBefore() {
- return deserialize(domData.getDataBefore());
- }
-
- @Override
- public T getDataAfter() {
- return deserialize(domData.getDataAfter());
- }
-
- @Override
- public Class<T> getDataType() {
- return codec.getBindingClass();
- }
-
- @Override
- public PathArgument getIdentifier() {
- return identifier;