- private void checkValidIdentifierStart() {
- checkValid(YangNames.IDENTIFIER_START.matches(currentChar()), ErrorTag.MALFORMED_MESSAGE,
- "Identifier must start with character from set 'a-zA-Z_'");
- }
-
- private RestconfDocumentedException getParsingCharFailedException() {
- return createParsingException(ErrorTag.MALFORMED_MESSAGE,
- "Bad char '" + currentChar() + "' on the current position.");
- }
-
- private RestconfDocumentedException createParsingException(final ErrorTag errorTag, final String reason) {
- return new RestconfDocumentedException(
- "Could not parse Instance Identifier '" + data + "'. Offset: '" + offset + "' : Reason: " + reason,
- ErrorType.PROTOCOL, errorTag);
- }
-
- private char currentChar() {
- return data.charAt(offset);
- }
-
- private void skipCurrentChar() {
- offset++;
- }
-
- private String nextIdentifierFromNextSequence(final CharMatcher matcher) {
- final int start = offset;
- while (!allCharsConsumed() && matcher.matches(currentChar())) {
- skipCurrentChar();
- }
- return data.substring(start, offset);
- }
-
- private void validArg() {
- // every identifier except of the first MUST start with slash
- if (offset != 0) {
- checkValid('/' == currentChar(), ErrorTag.MALFORMED_MESSAGE, "Identifier must start with '/'.");
-
- // skip consecutive slashes, users often assume restconf URLs behave just as HTTP does by squashing
- // multiple slashes into a single one
- while (!allCharsConsumed() && '/' == currentChar()) {
- skipCurrentChar();
- }
-
- // check if slash is not also the last char in identifier
- checkValid(!allCharsConsumed(), ErrorTag.MALFORMED_MESSAGE, "Identifier cannot end with '/'.");
- }
- }
-
- private QName getQNameOfDataSchemaNode(final String nodeName) {
- final DataSchemaNode dataSchemaNode = current.getDataSchemaNode();
- if (dataSchemaNode instanceof ContainerLike) {
- return getQNameOfDataSchemaNode((ContainerLike) dataSchemaNode, nodeName);
- } else if (dataSchemaNode instanceof ListSchemaNode) {
- return getQNameOfDataSchemaNode((ListSchemaNode) dataSchemaNode, nodeName);
- }
-
- throw new UnsupportedOperationException("Unsupported schema node " + dataSchemaNode);
- }
-
- private static <T extends DataNodeContainer & SchemaNode & ActionNodeContainer> QName getQNameOfDataSchemaNode(
- final T parent, final String nodeName) {
- final Optional<? extends ActionDefinition> actionDef = findActionDefinition(parent, nodeName);
- final SchemaNode node;
- if (actionDef.isPresent()) {
- node = actionDef.get();
- } else {
- node = RestconfSchemaUtil.findSchemaNodeInCollection(parent.getChildNodes(), nodeName);
- }
- return node.getQName();
- }
-
- private static Optional<? extends ActionDefinition> findActionDefinition(final SchemaNode dataSchemaNode,