453bbbb21aab5b76ad9144abdd0531664d3c21c3
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / AbstractDataTreeCandidateNode.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.persisted;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Collection;
13 import java.util.Optional;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
18
19 /**
20  * Abstract base class for our internal implementation of {@link DataTreeCandidateNode},
21  * which we instantiate from a serialized stream. We do not retain the before-image and
22  * do not implement {@link #getModifiedChild(PathArgument)}, as that method is only
23  * useful for end users. Instances based on this class should never be leaked outside of
24  * this component.
25  */
26 abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
27     private final ModificationType type;
28
29     protected AbstractDataTreeCandidateNode(final ModificationType type) {
30         this.type = requireNonNull(type);
31     }
32
33     @Override
34     public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
35         throw new UnsupportedOperationException("Not implemented");
36     }
37
38     @Override
39     public final ModificationType getModificationType() {
40         return type;
41     }
42
43     @Override
44     public final Optional<NormalizedNode> getDataBefore() {
45         throw new UnsupportedOperationException("Before-image not available after serialization");
46     }
47
48     static DataTreeCandidateNode createUnmodified() {
49         return new AbstractDataTreeCandidateNode(ModificationType.UNMODIFIED) {
50             @Override
51             public PathArgument getIdentifier() {
52                 throw new UnsupportedOperationException("Root node does not have an identifier");
53             }
54
55             @Override
56             public Optional<NormalizedNode> getDataAfter() {
57                 throw new UnsupportedOperationException("After-image not available after serialization");
58             }
59
60             @Override
61             public Collection<DataTreeCandidateNode> getChildNodes() {
62                 throw new UnsupportedOperationException("Children not available after serialization");
63             }
64         };
65     }
66 }