2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.api.schema.tree;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 * DataTree configuration class.
21 * TreeConfig supports currently the following options:
24 * <li>enable/disable unique indexes and unique constraint validation</li>
25 * <li>enable/disable mandatory nodes validation</li>
29 * TreeConfig can be easily extended in order to support further data tree
30 * configuration options, like following:
32 * <li>enable/disable case exclusion validation</li>
33 * <li>enable/disable other indexes</li>
34 * <li>other schema aware validation options</li>
38 * This can be useful when strict validation is not required or useful for some
42 public class DataTreeConfiguration implements Immutable {
43 public static final DataTreeConfiguration DEFAULT_CONFIGURATION = new Builder(TreeType.CONFIGURATION)
44 .setMandatoryNodesValidation(true).build();
45 public static final DataTreeConfiguration DEFAULT_OPERATIONAL = new Builder(TreeType.OPERATIONAL)
46 .setMandatoryNodesValidation(true).build();
48 private final TreeType treeType;
49 private final YangInstanceIdentifier rootPath;
50 private final boolean uniqueIndexes;
51 private final boolean mandatoryNodesValidation;
53 DataTreeConfiguration(final TreeType treeType, final YangInstanceIdentifier rootPath, final boolean uniqueIndexes,
54 final boolean mandatoryNodesValidation) {
55 this.treeType = Preconditions.checkNotNull(treeType);
56 this.rootPath = Preconditions.checkNotNull(rootPath);
57 this.uniqueIndexes = uniqueIndexes;
58 this.mandatoryNodesValidation = mandatoryNodesValidation;
61 public @Nonnull YangInstanceIdentifier getRootPath() {
65 public @Nonnull TreeType getTreeType() {
69 public boolean isUniqueIndexEnabled() {
73 public boolean isMandatoryNodesValidationEnabled() {
74 return mandatoryNodesValidation;
78 public String toString() {
79 return MoreObjects.toStringHelper(this).add("type", treeType).add("root", rootPath)
80 .add("mandatory", mandatoryNodesValidation)
81 .add("unique", uniqueIndexes).toString();
84 public static DataTreeConfiguration getDefault(final TreeType treeType) {
85 Preconditions.checkNotNull(treeType);
88 return DEFAULT_CONFIGURATION;
90 return DEFAULT_OPERATIONAL;
92 return new DataTreeConfiguration(treeType, YangInstanceIdentifier.EMPTY, false, true);
96 public static class Builder implements org.opendaylight.yangtools.concepts.Builder<DataTreeConfiguration> {
97 private final TreeType treeType;
98 private YangInstanceIdentifier rootPath;
99 private boolean uniqueIndexes;
100 private boolean mandatoryNodesValidation;
102 public Builder(final TreeType treeType) {
103 this.treeType = Preconditions.checkNotNull(treeType);
104 this.rootPath = YangInstanceIdentifier.EMPTY;
107 public Builder setUniqueIndexes(final boolean uniqueIndexes) {
108 this.uniqueIndexes = uniqueIndexes;
112 public Builder setMandatoryNodesValidation(final boolean mandatoryNodesValidation) {
113 this.mandatoryNodesValidation = mandatoryNodesValidation;
117 public Builder setRootPath(final YangInstanceIdentifier rootPath) {
118 this.rootPath = rootPath.toOptimized();
123 public DataTreeConfiguration build() {
124 return new DataTreeConfiguration(treeType, rootPath, uniqueIndexes, mandatoryNodesValidation);