import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-
+import com.google.common.collect.Lists;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
public final class YangSchemaUtils {
-
- private static final Function<PathArgument, QName> QNAME_FROM_PATH_ARGUMENT = new Function<PathArgument, QName>(){
-
- @Override
- public QName apply(final PathArgument input) {
- if(input == null) {
- return null;
- }
- return input.getNodeType();
- }
- };
-
private YangSchemaUtils() {
throw new UnsupportedOperationException("Utility class.");
}
- public static DataSchemaNode getSchemaNode(final SchemaContext schema,final YangInstanceIdentifier path) {
- checkArgument(schema != null,"YANG Schema must not be null.");
- checkArgument(path != null,"Path must not be null.");
- return getSchemaNode(schema, FluentIterable.from(path.getPathArguments()).transform(QNAME_FROM_PATH_ARGUMENT));
+ public static DataSchemaNode getSchemaNode(final SchemaContext schema, final YangInstanceIdentifier path) {
+ checkArgument(schema != null, "YANG Schema must not be null.");
+ checkArgument(path != null, "Path must not be null.");
+ return getSchemaNode(schema, Lists.transform(path.getPathArguments(), PathArgument::getNodeType));
}
- public static DataSchemaNode getSchemaNode(final SchemaContext schema,final Iterable<QName> path) {
- checkArgument(schema != null,"YANG Schema must not be null.");
- checkArgument(path != null,"Path must not be null.");
- if(!path.iterator().hasNext()){
+ public static DataSchemaNode getSchemaNode(final SchemaContext schema, final Iterable<QName> path) {
+ checkArgument(schema != null, "YANG Schema must not be null.");
+ checkArgument(path != null, "Path must not be null.");
+ if (!path.iterator().hasNext()) {
return toRootDataNode(schema);
}
QName firstNode = path.iterator().next();
- DataNodeContainer previous = schema.findModuleByNamespaceAndRevision(firstNode.getNamespace(),
- firstNode.getRevision());
+ DataNodeContainer previous = schema.findModule(firstNode.getModule()).orElse(null);
Iterator<QName> iterator = path.iterator();
while (iterator.hasNext()) {
- checkArgument(previous!= null, "Supplied path does not resolve into valid schema node.");
+ checkArgument(previous != null, "Supplied path does not resolve into valid schema node.");
QName arg = iterator.next();
DataSchemaNode currentNode = previous.getDataChildByName(arg);
- if (currentNode == null && previous instanceof DataNodeContainer) {
+ if (currentNode == null) {
currentNode = searchInChoices(previous, arg);
}
if (currentNode instanceof DataNodeContainer) {
checkArgument(!iterator.hasNext(), "Path nests inside leaf node, which is not allowed.");
return currentNode;
}
- checkState(currentNode != null, "Current node should not be null for %s",path);
+ checkState(currentNode != null, "Current node should not be null for %s", path);
}
- checkState(previous instanceof DataSchemaNode, "Schema node for %s should be instance of DataSchemaNode. Found %s",path,previous);
+ checkState(previous instanceof DataSchemaNode,
+ "Schema node for %s should be instance of DataSchemaNode. Found %s", path, previous);
return (DataSchemaNode) previous;
}
}
private static DataSchemaNode searchInCases(final ChoiceSchemaNode choiceNode, final QName arg) {
- Set<ChoiceCaseNode> cases = choiceNode.getCases();
- for (ChoiceCaseNode caseNode : cases) {
+ for (CaseSchemaNode caseNode : choiceNode.getCases().values()) {
DataSchemaNode node = caseNode.getDataChildByName(arg);
if (node != null) {
return node;
private static final class NetconfDataRootNode implements ContainerSchemaNode {
- public NetconfDataRootNode(final SchemaContext schema) {
+ NetconfDataRootNode(final SchemaContext schema) {
// TODO Auto-generated constructor stub
}
}
@Override
- public DataSchemaNode getDataChildByName(final QName name) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public DataSchemaNode getDataChildByName(final String name) {
+ public Optional<DataSchemaNode> findDataChildByName(final QName name) {
// TODO Auto-generated method stub
return null;
}
}
@Override
- public Set<AugmentationSchema> getAvailableAugmentations() {
+ public Set<AugmentationSchemaNode> getAvailableAugmentations() {
// TODO Auto-generated method stub
return null;
}
}
@Override
- public ConstraintDefinition getConstraints() {
+ public QName getQName() {
// TODO Auto-generated method stub
return null;
}
@Override
- public QName getQName() {
+ public SchemaPath getPath() {
// TODO Auto-generated method stub
return null;
}
@Override
- public SchemaPath getPath() {
+ public Optional<String> getDescription() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<String> getReference() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Status getStatus() {
// TODO Auto-generated method stub
return null;
}
@Override
- public String getDescription() {
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
// TODO Auto-generated method stub
return null;
}
@Override
- public String getReference() {
+ public boolean isPresenceContainer() {
// TODO Auto-generated method stub
- return null;
+ return false;
}
@Override
- public Status getStatus() {
+ public Set<NotificationDefinition> getNotifications() {
// TODO Auto-generated method stub
return null;
}
@Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ public Set<ActionDefinition> getActions() {
// TODO Auto-generated method stub
return null;
}
@Override
- public boolean isPresenceContainer() {
+ public Optional<RevisionAwareXPath> getWhenCondition() {
// TODO Auto-generated method stub
- return false;
+ return null;
}
+ @Override
+ public Collection<MustDefinition> getMustConstraints() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
}