85c5403b709fe0fed96efd6a42cc54c36b058900
[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 com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
17
18 /**
19  * Abstract base class for our internal implementation of {@link DataTreeCandidateNode},
20  * which we instantiate from a serialized stream. We do not retain the before-image and
21  * do not implement {@link #getModifiedChild(PathArgument)}, as that method is only
22  * useful for end users. Instances based on this class should never be leaked outside of
23  * this component.
24  */
25 abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
26     private final ModificationType type;
27
28     protected AbstractDataTreeCandidateNode(final ModificationType type) {
29         this.type = Preconditions.checkNotNull(type);
30     }
31
32     @Override
33     public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
34         throw new UnsupportedOperationException("Not implemented");
35     }
36
37     @Override
38     public final ModificationType getModificationType() {
39         return type;
40     }
41
42     @Override
43     public final Optional<NormalizedNode<?, ?>> getDataBefore() {
44         throw new UnsupportedOperationException("Before-image not available after serialization");
45     }
46
47     static DataTreeCandidateNode createUnmodified() {
48         return new AbstractDataTreeCandidateNode(ModificationType.UNMODIFIED) {
49             @Override
50             public PathArgument getIdentifier() {
51                 throw new UnsupportedOperationException("Root node does not have an identifier");
52             }
53
54             @Override
55             public Optional<NormalizedNode<?, ?>> getDataAfter() {
56                 throw new UnsupportedOperationException("After-image not available after serialization");
57             }
58
59             @Override
60             public Collection<DataTreeCandidateNode> getChildNodes() {
61                 throw new UnsupportedOperationException("Children not available after serialization");
62             }
63         };
64     }
65 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.