/* * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.data.api.schema.tree; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; /** * DataTree configuration class. * *
* TreeConfig supports currently the following options: *
* TreeConfig can be easily extended in order to support further data tree * configuration options, like following: *
* This can be useful when strict validation is not required or useful for some
* reasons.
*/
@Beta
public class DataTreeConfiguration implements Immutable {
public static final DataTreeConfiguration DEFAULT_CONFIGURATION = new Builder(TreeType.CONFIGURATION)
.setMandatoryNodesValidation(true).build();
public static final DataTreeConfiguration DEFAULT_OPERATIONAL = new Builder(TreeType.OPERATIONAL).build();
private final TreeType treeType;
private final YangInstanceIdentifier rootPath;
private final boolean uniqueIndexes;
private final boolean mandatoryNodesValidation;
DataTreeConfiguration(final TreeType treeType, final YangInstanceIdentifier rootPath, final boolean uniqueIndexes,
final boolean mandatoryNodesValidation) {
this.treeType = Preconditions.checkNotNull(treeType);
this.rootPath = Preconditions.checkNotNull(rootPath);
this.uniqueIndexes = uniqueIndexes;
this.mandatoryNodesValidation = mandatoryNodesValidation;
}
public @Nonnull YangInstanceIdentifier getRootPath() {
return rootPath;
}
public @Nonnull TreeType getTreeType() {
return treeType;
}
public boolean isUniqueIndexEnabled() {
return uniqueIndexes;
}
public boolean isMandatoryNodesValidationEnabled() {
return mandatoryNodesValidation;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("type", treeType).add("root", rootPath)
.add("mandatory", mandatoryNodesValidation)
.add("unique", uniqueIndexes).toString();
}
public static DataTreeConfiguration getDefault(final TreeType treeType) {
Preconditions.checkNotNull(treeType);
switch (treeType) {
case CONFIGURATION:
return DEFAULT_CONFIGURATION;
case OPERATIONAL:
return DEFAULT_OPERATIONAL;
default:
return new DataTreeConfiguration(treeType, YangInstanceIdentifier.EMPTY, false, true);
}
}
public static class Builder implements org.opendaylight.yangtools.concepts.Builder