+
+ /**
+ * Validation of name.
+ *
+ * @param moduleName iterator
+ * @return {@link String}
+ */
+ @VisibleForTesting
+ static String validateAndGetModulName(final Iterator<String> moduleName) {
+ RestconfDocumentedException.throwIf(!moduleName.hasNext(), "Module name must be supplied.", ErrorType.PROTOCOL,
+ ErrorTag.INVALID_VALUE);
+ final String name = moduleName.next();
+
+ RestconfDocumentedException.throwIf(
+ 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(
+ !ParserConstants.YANG_IDENTIFIER_PART.matchesAllOf(name.substring(1)),
+ "Supplied name has not expected identifier format.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
+
+ return name;
+ }
+
+ private static EffectiveModelContext coerceModelContext(final DOMMountPoint mountPoint) {
+ final EffectiveModelContext context = modelContext(mountPoint);
+ checkState(context != null, "Mount point %s does not have a model context", mountPoint);
+ return context;
+ }
+
+ private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) {
+ return mountPoint.getService(DOMSchemaService.class)
+ .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext()))
+ .orElse(null);
+ }