-/**
+/*
* Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
private static final String MOUNT_NODE = "mount";
- private static final Charset URI_ENCODING_CHARSET = StandardCharsets.ISO_8859_1;
+ private static final Charset URI_ENCODING_CHARSET = StandardCharsets.UTF_8;
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
return toIdentifier(restconfInstance, true);
}
- private InstanceIdentifierContext<?> toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
+ private InstanceIdentifierContext<?> toIdentifier(final String restconfInstance,
+ final boolean toMountPointIdentifier) {
checkPreconditions();
- if(restconfInstance == null) {
+ if (restconfInstance == null) {
return new InstanceIdentifierContext<>(YangInstanceIdentifier.EMPTY, this.globalSchema, null,
this.globalSchema);
}
final Module latestModule = this.globalSchema.findModuleByName(startModule, null);
if (latestModule == null) {
- throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
+ throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.",
+ ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
}
- final InstanceIdentifierContext<?> iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null,
- toMountPointIdentifier);
+ final InstanceIdentifierContext<?> iiWithSchemaNode =
+ collectPathArguments(builder, pathArgs, latestModule, null, toMountPointIdentifier);
if (iiWithSchemaNode == null) {
throw new RestconfDocumentedException("URI has bad format", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
return list;
}
+
public Module findModuleByName(final String moduleName) {
checkPreconditions();
Preconditions.checkArgument((moduleName != null) && !moduleName.isEmpty());
public Module findModuleByNameAndRevision(final QName module) {
checkPreconditions();
- Preconditions.checkArgument((module != null) && (module.getLocalName() != null) && (module.getRevision() != null));
+ Preconditions
+ .checkArgument((module != null) && (module.getLocalName() != null) && (module.getRevision() != null));
return this.globalSchema.findModuleByName(module.getLocalName(), module.getRevision());
}
public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final QName module) {
checkPreconditions();
- Preconditions.checkArgument((module != null) && (module.getLocalName() != null) && (module.getRevision() != null)
+ Preconditions
+ .checkArgument((module != null) && (module.getLocalName() != null) && (module.getRevision() != null)
&& (mountPoint != null));
final SchemaContext schemaContext = mountPoint.getSchemaContext();
if (!(element instanceof AugmentationIdentifier)) {
final QName _nodeType = element.getNodeType();
final DataSchemaNode potentialNode = childByQName(node, _nodeType);
- if (!((element instanceof NodeIdentifier) && (potentialNode instanceof ListSchemaNode)) &&
- !(potentialNode instanceof ChoiceSchemaNode)) {
+ if (!((element instanceof NodeIdentifier) && (potentialNode instanceof ListSchemaNode))
+ && !(potentialNode instanceof ChoiceSchemaNode)) {
builder.append(convertToRestconfIdentifier(element, potentialNode, mount));
if (potentialNode instanceof DataNodeContainer) {
node = (DataNodeContainer) potentialNode;
final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
final Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings,
- g -> RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
+ g -> RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
final Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings,
- g -> RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
+ g -> RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
final List<DataSchemaNode> instanceDataChildrenByName = findInstanceDataChildrenByName(restconfGrouping,
return null;
}
+
+ private static DataSchemaNode childByQName(final Object container, final QName name) {
+ if (container instanceof ChoiceCaseNode) {
+ return childByQName((ChoiceCaseNode) container, name);
+ } else if (container instanceof ChoiceSchemaNode) {
+ return childByQName((ChoiceSchemaNode) container, name);
+ } else if (container instanceof ContainerSchemaNode) {
+ return childByQName((ContainerSchemaNode) container, name);
+ } else if (container instanceof ListSchemaNode) {
+ return childByQName((ListSchemaNode) container, name);
+ } else if (container instanceof DataSchemaNode) {
+ return childByQName((DataSchemaNode) container, name);
+ } else if (container instanceof Module) {
+ return childByQName((Module) container, name);
+ } else {
+ throw new IllegalArgumentException("Unhandled parameter types: "
+ + Arrays.<Object>asList(container, name).toString());
+ }
+ }
+
private static DataSchemaNode dataNodeChildByQName(final DataNodeContainer container, final QName name) {
final DataSchemaNode ret = container.getDataChildByName(name);
if (ret == null) {
private InstanceIdentifierContext<?> collectPathArguments(final InstanceIdentifierBuilder builder,
final List<String> strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint,
final boolean returnJustMountPoint) {
- Preconditions.<List<String>> checkNotNull(strings);
+ Preconditions.<List<String>>checkNotNull(strings);
if (parentNode == null) {
return null;
ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
- final Module moduleBehindMountPoint = mountPointSchema.findModuleByName(moduleNameBehindMountPoint, null);
+ final Module moduleBehindMountPoint =
+ mountPointSchema.findModuleByName(moduleNameBehindMountPoint, null);
if (moduleBehindMountPoint == null) {
throw new RestconfDocumentedException("\"" + moduleNameBehindMountPoint
+ "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
throw new RestconfDocumentedException(
"URI has bad format. Node \""
- + nodeName
- + "\" is added as augment from more than one module. "
- + "Therefore the node must have module name and it has to be in format \"moduleName:nodeName\"."
+ + nodeName + "\" is added as augment from more than one module. "
+ + "Therefore the node must have module name "
+ + "and it has to be in format \"moduleName:nodeName\"."
+ "\nThe node is added as augment from modules with namespaces:\n"
+ strBuilder.toString(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final List<String> uriKeyValues = strings.subList(consumed, consumed + keysSize);
final HashMap<QName, Object> keyValues = new HashMap<>();
- int i = 0;
+ int index = 0;
for (final QName key : listNode.getKeyDefinition()) {
{
- final String uriKeyValue = uriKeyValues.get(i);
+ final String uriKeyValue = uriKeyValues.get(index);
if (uriKeyValue.equals(NULL_VALUE)) {
throw new RestconfDocumentedException("URI has bad format. List \""
+ listNode.getQName().getLocalName() + "\" cannot contain \"null\" value as a key.",
}
addKeyValue(keyValues, listNode.getDataChildByName(key), uriKeyValue, mountPoint);
- i++;
+ index++;
}
}
- consumed = consumed + i;
+ consumed = consumed + index;
builder.nodeWithKey(targetNode.getQName(), keyValues);
} else {
builder.node(targetNode.getQName());
String additionalInfo = "";
if (decoded == null) {
if ((typedef instanceof IdentityrefTypeDefinition)) {
- decoded = toQName(urlDecoded, null);
+ final SchemaContext schemaContext =
+ mountPoint == null ? this.globalSchema : mountPoint.getSchemaContext();
+ decoded = toQName(schemaContext, urlDecoded, null);
additionalInfo =
"For key which is of type identityref it should be in format module_name:identity_name.";
}
return str.substring(idx + 1);
}
- private QName toQName(final String name, final Date revisionDate) {
+ private QName toQName(final SchemaContext schemaContext, final String name, final Date revisionDate) {
checkPreconditions();
final String module = toModuleName(name);
final String node = toNodeName(name);
- final Module m = this.globalSchema.findModuleByName(module, revisionDate);
+ final Module m = schemaContext.findModuleByName(module, revisionDate);
return m == null ? null : QName.create(m.getQNameModule(), node);
}
}
public RpcDefinition getRpcDefinition(final String name, final Date revisionDate) {
- final QName validName = toQName(name, revisionDate);
+ final QName validName = toQName(this.globalSchema, name, revisionDate);
return validName == null ? null : this.qnameToRpc.get().get(validName);
}
return builder.toString();
}
- private static DataSchemaNode childByQName(final Object container, final QName name) {
- if (container instanceof ChoiceCaseNode) {
- return childByQName((ChoiceCaseNode) container, name);
- } else if (container instanceof ChoiceSchemaNode) {
- return childByQName((ChoiceSchemaNode) container, name);
- } else if (container instanceof ContainerSchemaNode) {
- return childByQName((ContainerSchemaNode) container, name);
- } else if (container instanceof ListSchemaNode) {
- return childByQName((ListSchemaNode) container, name);
- } else if (container instanceof DataSchemaNode) {
- return childByQName((DataSchemaNode) container, name);
- } else if (container instanceof Module) {
- return childByQName((Module) container, name);
- } else {
- throw new IllegalArgumentException("Unhandled parameter types: "
- + Arrays.<Object> asList(container, name).toString());
- }
- }
-
public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
try {
return this.dataNormalizer.toNormalized(legacy);