From 8a7686520779b883d4bc0302704276772e521343 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 Jul 2020 13:34:06 +0200 Subject: [PATCH] Remove org.opendaylight.restconf.nb.rfc8040.utils.parser.builder This package holds only a few constants, which are better redistributed and kept where they are actually used. Change-Id: I0fc614072e17df463615b1ea3544a3fae0fd659d Signed-off-by: Robert Varga --- .../rests/utils/RestconfStreamsConstants.java | 3 +- .../rfc8040/utils/parser/ParserConstants.java | 31 +++++++ .../utils/parser/ParserFieldsParameter.java | 3 +- .../utils/parser/ParserIdentifier.java | 5 +- .../YangInstanceIdentifierDeserializer.java | 54 ++++++------- .../YangInstanceIdentifierSerializer.java | 41 +++++----- .../builder/ParserBuilderConstants.java | 81 ------------------- .../YangInstanceIdentifierSerializerTest.java | 5 +- 8 files changed, 85 insertions(+), 138 deletions(-) create mode 100644 restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserConstants.java delete mode 100644 restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/builder/ParserBuilderConstants.java diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java index 607e23243e..ffa08159de 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java @@ -12,7 +12,6 @@ import java.net.URI; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.restconf.common.util.DataChangeScope; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; @@ -54,7 +53,7 @@ public final class RestconfStreamsConstants { public static final DataChangeScope DEFAULT_SCOPE = DataChangeScope.BASE; public static final LogicalDatastoreType DEFAULT_DS = LogicalDatastoreType.CONFIGURATION; - public static final char EQUAL = ParserBuilderConstants.Deserializer.EQUAL; + public static final char EQUAL = '='; public static final String DS_URI = RestconfConstants.SLASH + DATASTORE_PARAM_NAME + EQUAL; public static final String SCOPE_URI = RestconfConstants.SLASH + SCOPE_PARAM_NAME + EQUAL; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserConstants.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserConstants.java new file mode 100644 index 0000000000..e2de0ed8ce --- /dev/null +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserConstants.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.restconf.nb.rfc8040.utils.parser; + +import com.google.common.base.CharMatcher; + +/** + * Various constants related to RFC3986 (URI) and RFC7950 (YANG) parsing in the context of RFC8040. + */ +final class ParserConstants { + // Reserved characters as per https://tools.ietf.org/html/rfc3986#section-2.2 + static final String RFC3986_RESERVED_CHARACTERS = ":/?#[]@" + "!$&'()*+,;=" + // FIXME: this space should not be here, but that was a day-0 bug and we have asserts on this + + " "; + + // First character of RFC7950 "identifier" rule + static final CharMatcher YANG_IDENTIFIER_START = + CharMatcher.inRange('A', 'Z').or(CharMatcher.inRange('a', 'z').or(CharMatcher.is('_'))).precomputed(); + // Subsequent characters of RFC7950 "identifier" rule + static final CharMatcher YANG_IDENTIFIER_PART = + YANG_IDENTIFIER_START.or(CharMatcher.inRange('0', '9')).or(CharMatcher.anyOf("-.")).precomputed(); + + private ParserConstants() { + // Hidden on purpose + } +} diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java index cc6cbda14a..50b1d1f0a6 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java @@ -18,7 +18,6 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode; @@ -85,7 +84,7 @@ public final class ParserFieldsParameter { while (currentPosition < input.length()) { final char currentChar = input.charAt(currentPosition); - if (Deserializer.IDENTIFIER.matches(currentChar) || currentChar == '/') { + if (ParserConstants.YANG_IDENTIFIER_PART.matches(currentChar) || currentChar == '/') { if (currentChar == SLASH) { // add parsed identifier to results for current level currentNode = addChildToResult( diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java index 4f8e1e0cb0..02ab4d765d 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java @@ -30,7 +30,6 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.common.schema.SchemaExportContext; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -299,12 +298,12 @@ public final class ParserIdentifier { final String name = moduleName.next(); RestconfDocumentedException.throwIf( - name.isEmpty() || !ParserBuilderConstants.Deserializer.IDENTIFIER_FIRST_CHAR.matches(name.charAt(0)), + name.isEmpty() || !ParserConstants.YANG_IDENTIFIER_START.matches(name.charAt(0)), "Identifier must start with character from set 'a-zA-Z_", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); RestconfDocumentedException.throwIf(name.toUpperCase(Locale.ROOT).startsWith("XML"), "Identifier must NOT start with XML ignore case.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); RestconfDocumentedException.throwIf( - !ParserBuilderConstants.Deserializer.IDENTIFIER.matchesAllOf(name.substring(1)), + !ParserConstants.YANG_IDENTIFIER_PART.matchesAllOf(name.substring(1)), "Supplied name has not expected identifier format.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); return name; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java index c2f7ea8f6b..acbb65a60b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java @@ -9,17 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040.utils.parser; import static java.util.Objects.requireNonNull; import static org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants.SLASH; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.COLON; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.COMMA; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.EMPTY_STRING; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.EQUAL; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.FIRST_ENCODED_CHAR; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.IDENTIFIER; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.IDENTIFIER_FIRST_CHAR; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.IDENTIFIER_PREDICATE; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.LAST_ENCODED_CHAR; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.PERCENT_ENCODED_RADIX; -import static org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Deserializer.PERCENT_ENCODING; import com.google.common.base.CharMatcher; import com.google.common.collect.ImmutableList; @@ -63,8 +52,17 @@ import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; * Deserializer for {@link String} to {@link YangInstanceIdentifier} for restconf. */ public final class YangInstanceIdentifierDeserializer { + private static final CharMatcher IDENTIFIER_PREDICATE = + CharMatcher.noneOf(ParserConstants.RFC3986_RESERVED_CHARACTERS).precomputed(); private static final String PARSING_FAILED_MESSAGE = "Could not parse Instance Identifier '%s'. " + "Offset: '%d' : Reason: "; + private static final CharMatcher PERCENT_ENCODING = CharMatcher.is('%'); + // position of the first encoded char after percent sign in percent encoded string + private static final int FIRST_ENCODED_CHAR = 1; + // position of the last encoded char after percent sign in percent encoded string + private static final int LAST_ENCODED_CHAR = 3; + // percent encoded radix for parsing integers + private static final int PERCENT_ENCODED_RADIX = 16; private final SchemaContext schemaContext; private final String data; @@ -100,7 +98,7 @@ public final class YangInstanceIdentifierDeserializer { if (allCharsConsumed() || currentChar() == SLASH) { prepareIdentifier(qname, path); path.add(current == null ? NodeIdentifier.create(qname) : current.getIdentifier()); - } else if (currentChar() == EQUAL) { + } else if (currentChar() == '=') { if (nextContextNode(qname, path).getDataSchemaNode() instanceof ListSchemaNode) { prepareNodeWithPredicates(qname, path, (ListSchemaNode) current.getDataSchemaNode()); } else { @@ -128,8 +126,8 @@ public final class YangInstanceIdentifierDeserializer { while (keys.hasNext() && !allCharsConsumed() && currentChar() != SLASH) { // empty key value - if (currentChar() == COMMA) { - values.put(keys.next(), EMPTY_STRING); + if (currentChar() == ',') { + values.put(keys.next(), ""); skipCurrentChar(); continue; } @@ -149,7 +147,7 @@ public final class YangInstanceIdentifierDeserializer { values.put(key, valueByType); // skip comma - if (keys.hasNext() && !allCharsConsumed() && currentChar() == COMMA) { + if (keys.hasNext() && !allCharsConsumed() && currentChar() == ',') { skipCurrentChar(); } } @@ -157,7 +155,7 @@ public final class YangInstanceIdentifierDeserializer { // the last key is considered to be empty if (keys.hasNext()) { // at this point, it must be true that current char is '/' or all chars have already been consumed - values.put(keys.next(), EMPTY_STRING); + values.put(keys.next(), ""); // there should be no more missing keys RestconfDocumentedException.throwIf(keys.hasNext(), ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE, @@ -192,7 +190,7 @@ public final class YangInstanceIdentifierDeserializer { private QName prepareQName() { checkValidIdentifierStart(); - final String preparedPrefix = nextIdentifierFromNextSequence(IDENTIFIER); + final String preparedPrefix = nextIdentifierFromNextSequence(ParserConstants.YANG_IDENTIFIER_PART); final String prefix; final String localName; @@ -201,17 +199,17 @@ public final class YangInstanceIdentifierDeserializer { } switch (currentChar()) { - case SLASH: - case EQUAL: + case '/': + case '=': prefix = preparedPrefix; return getQNameOfDataSchemaNode(prefix); - case COLON: + case ':': prefix = preparedPrefix; skipCurrentChar(); checkValidIdentifierStart(); - localName = nextIdentifierFromNextSequence(IDENTIFIER); + localName = nextIdentifierFromNextSequence(ParserConstants.YANG_IDENTIFIER_PART); - if (!allCharsConsumed() && currentChar() == EQUAL) { + if (!allCharsConsumed() && currentChar() == '=') { return getQNameOfDataSchemaNode(localName); } else { final Module module = moduleForPrefix(prefix); @@ -292,7 +290,7 @@ public final class YangInstanceIdentifierDeserializer { } private void checkValidIdentifierStart() { - checkValid(IDENTIFIER_FIRST_CHAR.matches(currentChar()), ErrorTag.MALFORMED_MESSAGE, + checkValid(ParserConstants.YANG_IDENTIFIER_START.matches(currentChar()), ErrorTag.MALFORMED_MESSAGE, "Identifier must start with character from set 'a-zA-Z_'"); } @@ -368,15 +366,15 @@ public final class YangInstanceIdentifierDeserializer { } private static String findAndParsePercentEncoded(final String preparedPrefix) { - if (preparedPrefix.indexOf(PERCENT_ENCODING) == -1) { + if (preparedPrefix.indexOf('%') == -1) { return preparedPrefix; } + // FIXME: this is extremely inefficient: we should be converting ranges of characters, not driven by + // CharMatcher, but by String.indexOf() final StringBuilder parsedPrefix = new StringBuilder(preparedPrefix); - final CharMatcher matcher = CharMatcher.is(PERCENT_ENCODING); - - while (matcher.matchesAnyOf(parsedPrefix)) { - final int percentCharPosition = matcher.indexIn(parsedPrefix); + while (PERCENT_ENCODING.matchesAnyOf(parsedPrefix)) { + final int percentCharPosition = PERCENT_ENCODING.indexIn(parsedPrefix); parsedPrefix.replace(percentCharPosition, percentCharPosition + LAST_ENCODED_CHAR, String.valueOf((char) Integer.parseInt(parsedPrefix.substring( percentCharPosition + FIRST_ENCODED_CHAR, percentCharPosition + LAST_ENCODED_CHAR), diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java index dcd5abbf28..8aa59c61ad 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java @@ -7,6 +7,8 @@ */ package org.opendaylight.restconf.nb.rfc8040.utils.parser; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.CharMatcher; import java.util.Iterator; import java.util.Locale; import java.util.Map.Entry; @@ -14,8 +16,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Serializer; +import org.opendaylight.yangtools.concepts.Serializer; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -31,6 +32,10 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; * Serializer for {@link YangInstanceIdentifier} to {@link String} for restconf. */ public final class YangInstanceIdentifierSerializer { + // RFC8040 specifies that reserved characters need to be percent-encoded + @VisibleForTesting + static final CharMatcher PERCENT_ENCODE_CHARS = + CharMatcher.anyOf(ParserConstants.RFC3986_RESERVED_CHARACTERS).precomputed(); private YangInstanceIdentifierSerializer() { throw new UnsupportedOperationException("Util class."); @@ -52,13 +57,12 @@ public final class YangInstanceIdentifierSerializer { final StringBuilder path = new StringBuilder(); QNameModule parentModule = null; - for (int i = 0; i < data.getPathArguments().size(); i++) { + for (final PathArgument arg : data.getPathArguments()) { // get module of the parent if (!variables.getCurrent().isMixin()) { parentModule = variables.getCurrent().getDataSchemaNode().getQName().getModule(); } - final PathArgument arg = data.getPathArguments().get(i); variables.setCurrent(variables.getCurrent().getChild(arg)); RestconfDocumentedException.throwIf(variables.getCurrent() == null, ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT, "Invalid input '%s': schema for argument '%s' (after '%s') not found", @@ -75,8 +79,7 @@ public final class YangInstanceIdentifierSerializer { path.append(RestconfConstants.SLASH); } - path.append(prefixForNamespace(arg.getNodeType(), schemaContext)); - path.append(ParserBuilderConstants.Deserializer.COLON); + path.append(prefixForNamespace(arg.getNodeType(), schemaContext)).append(':'); } else { path.append(RestconfConstants.SLASH); } @@ -95,10 +98,10 @@ public final class YangInstanceIdentifierSerializer { private static void prepareNodeWithValue(final StringBuilder path, final PathArgument arg) { path.append(arg.getNodeType().getLocalName()); - path.append(ParserBuilderConstants.Deserializer.EQUAL); + path.append('='); String value = String.valueOf(((NodeWithValue) arg).getValue()); - if (Serializer.PERCENT_ENCODE_CHARS.matchesAnyOf(value)) { + if (PERCENT_ENCODE_CHARS.matchesAnyOf(value)) { value = parsePercentEncodeChars(value); } path.append(value); @@ -109,17 +112,17 @@ public final class YangInstanceIdentifierSerializer { final Iterator> iterator = ((NodeIdentifierWithPredicates) arg).entrySet().iterator(); if (iterator.hasNext()) { - path.append(ParserBuilderConstants.Deserializer.EQUAL); + path.append('='); } while (iterator.hasNext()) { String valueOf = String.valueOf(iterator.next().getValue()); - if (Serializer.PERCENT_ENCODE_CHARS.matchesAnyOf(valueOf)) { + if (PERCENT_ENCODE_CHARS.matchesAnyOf(valueOf)) { valueOf = parsePercentEncodeChars(valueOf); } path.append(valueOf); if (iterator.hasNext()) { - path.append(ParserBuilderConstants.Deserializer.COMMA); + path.append(','); } } } @@ -133,16 +136,16 @@ public final class YangInstanceIdentifierSerializer { */ private static String parsePercentEncodeChars(final String valueOf) { final StringBuilder sb = new StringBuilder(); - int start = 0; - while (start < valueOf.length()) { - if (Serializer.PERCENT_ENCODE_CHARS.matches(valueOf.charAt(start))) { - final String format = String.format("%x", (int) valueOf.charAt(start)); - final String upperCase = format.toUpperCase(Locale.ROOT); - sb.append(ParserBuilderConstants.Deserializer.PERCENT_ENCODING + upperCase); + + for (int i = 0; i < valueOf.length(); ++i) { + final char ch = valueOf.charAt(i); + + if (PERCENT_ENCODE_CHARS.matches(ch)) { + final String upperCase = String.format("%x", (int) ch).toUpperCase(Locale.ROOT); + sb.append('%').append(upperCase); } else { - sb.append(valueOf.charAt(start)); + sb.append(ch); } - start++; } return sb.toString(); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/builder/ParserBuilderConstants.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/builder/ParserBuilderConstants.java deleted file mode 100644 index 74cc886fe2..0000000000 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/builder/ParserBuilderConstants.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.restconf.nb.rfc8040.utils.parser.builder; - -import com.google.common.base.CharMatcher; -import java.util.Arrays; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierDeserializer; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierSerializer; - -/** - * Util class of constants of {@link YangInstanceIdentifierSerializer} and - * {@link YangInstanceIdentifierDeserializer}. - * - */ -public final class ParserBuilderConstants { - - private ParserBuilderConstants() { - throw new UnsupportedOperationException("Util class"); - } - - /** - * Constants for {@link YangInstanceIdentifierSerializer}. - * - */ - public static final class Serializer { - - private Serializer() { - throw new UnsupportedOperationException("Util class"); - } - - public static final String DISABLED_CHARS = Arrays.toString(new char[] { ':', '/', '?', '#', '[', ']', '@' }) - .concat(Arrays.toString(new char[] { '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' })); - - public static final CharMatcher PERCENT_ENCODE_CHARS = CharMatcher.anyOf(DISABLED_CHARS).precomputed(); - } - - /** - * Constants for {@link YangInstanceIdentifierSerializer}. - * - */ - public static final class Deserializer { - - private Deserializer() { - throw new UnsupportedOperationException("Util class"); - } - - public static final CharMatcher BASE = CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('A', 'Z')) - .precomputed(); - - public static final CharMatcher IDENTIFIER_FIRST_CHAR = BASE.or(CharMatcher.is('_')).precomputed(); - - public static final CharMatcher IDENTIFIER = IDENTIFIER_FIRST_CHAR.or(CharMatcher.inRange('0', '9')) - .or(CharMatcher.anyOf(".-")).precomputed(); - - public static final CharMatcher IDENTIFIER_HEXA = CharMatcher.inRange('a', 'f') - .or(CharMatcher.inRange('A', 'F')).or(CharMatcher.inRange('0', '9')).precomputed(); - - public static final char COLON = ':'; - public static final char EQUAL = '='; - public static final char COMMA = ','; - public static final char HYPHEN = '-'; - public static final char PERCENT_ENCODING = '%'; - - public static final CharMatcher IDENTIFIER_PREDICATE = CharMatcher.noneOf( - Serializer.DISABLED_CHARS).precomputed(); - - public static final String EMPTY_STRING = ""; - - // position of the first encoded char after percent sign in percent encoded string - public static final int FIRST_ENCODED_CHAR = 1; - // position of the last encoded char after percent sign in percent encoded string - public static final int LAST_ENCODED_CHAR = 3; - // percent encoded radix for parsing integers - public static final int PERCENT_ENCODED_RADIX = 16; - } -} \ No newline at end of file diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializerTest.java index cef46ac5b6..3f73f3d67b 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializerTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializerTest.java @@ -20,7 +20,6 @@ import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; @@ -243,12 +242,12 @@ public class YangInstanceIdentifierSerializerTest { for (final char c : genDelims) { assertTrue("Current character is reserved and should be percent encoded", - ParserBuilderConstants.Serializer.PERCENT_ENCODE_CHARS.matches(c)); + YangInstanceIdentifierSerializer.PERCENT_ENCODE_CHARS.matches(c)); } for (final char c : subDelims) { assertTrue("Current character is reserved and should be percent encoded", - ParserBuilderConstants.Serializer.PERCENT_ENCODE_CHARS.matches(c)); + YangInstanceIdentifierSerializer.PERCENT_ENCODE_CHARS.matches(c)); } } -- 2.36.6