- private static Module moduleForPrefix(final String prefix, final SchemaContext schemaContext) {
- return schemaContext.findModules(prefix).stream().findFirst().orElse(null);
- }
-
- private static void validArg(final MainVarsWrapper variables) {
- // every identifier except of the first MUST start with slash
- if (variables.getOffset() != MainVarsWrapper.STARTING_OFFSET) {
- variables.checkValid(RestconfConstants.SLASH == variables.currentChar(), "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 (!variables.allCharsConsumed() && RestconfConstants.SLASH == variables.currentChar()) {
- variables.skipCurrentChar();
- }
-
- // check if slash is not also the last char in identifier
- variables.checkValid(!variables.allCharsConsumed(), "Identifier cannot end with '/'.");
- }
- }
-
- private static Optional<ActionDefinition> findActionDefinition(final SchemaNode dataSchemaNode,
- final String nodeName) {
- requireNonNull(dataSchemaNode, "DataSchema Node must not be null.");
- if (dataSchemaNode instanceof ActionNodeContainer) {
- return ((ActionNodeContainer) dataSchemaNode).getActions().stream()
- .filter(actionDef -> actionDef.getQName().getLocalName().equals(nodeName)).findFirst();
- }
- return Optional.empty();
- }
-
- private static final class MainVarsWrapper {
- private static final int STARTING_OFFSET = 0;
-
- private final SchemaContext schemaContext;
- private final String data;
-
- private DataSchemaContextNode<?> current;
- private int offset;
-
- MainVarsWrapper(final String data, final DataSchemaContextNode<?> current, final int offset,
- final SchemaContext schemaContext) {
- this.data = data;
- this.current = current;
- this.offset = offset;
- this.schemaContext = schemaContext;
- }
-
- boolean allCharsConsumed() {
- return offset == data.length();
- }
-
- void checkValid(final boolean condition, final String errorMsg) {
- checkArgument(condition, "Could not parse Instance Identifier '%s'. Offset: %s : Reason: %s", data, offset,
- errorMsg);
- }
-
- char currentChar() {
- return data.charAt(offset);
- }
-
- void skipCurrentChar() {
- offset++;
- }
-
- public String getData() {
- return data;
- }
-
- public DataSchemaContextNode<?> getCurrent() {
- return current;
- }
-
- public void setCurrent(final DataSchemaContextNode<?> current) {
- this.current = current;
- }
-
- public int getOffset() {
- return offset;
- }
-
- public SchemaContext getSchemaContext() {
- return schemaContext;
- }