+
+ /**
+ * Based on identifier read from source and collections of relevant prefixes and statement definitions mappings
+ * provided for actual phase, method resolves and returns valid QName for declared statement to be written.
+ * This applies to any declared statement, including unknown statements.
+ *
+ * @param prefixes collection of all relevant prefix mappings supplied for actual parsing phase
+ * @param stmtDef collection of all relevant statement definition mappings provided for actual parsing phase
+ * @param keywordText statement keyword text to parse from source
+ * @return valid QName for declared statement to be written, or null
+ */
+ private static QName getValidStatementDefinition(final PrefixToModule prefixes,
+ final QNameToStatementDefinition stmtDef, final String keywordText) {
+ final int firstColon = keywordText.indexOf(':');
+ if (firstColon == -1) {
+ final StatementDefinition statementDefinition = stmtDef.get(
+ new QName(YangConstants.RFC6020_YIN_NAMESPACE, keywordText));
+ return statementDefinition != null ? statementDefinition.getStatementName() : null;
+ }
+
+ final int secondColon = keywordText.indexOf(':', firstColon + 1);
+ if (secondColon != -1) {
+ // Malformed string
+ return null;
+ }
+ if (prefixes == null) {
+ // No prefixes to look up from
+ return null;
+ }
+
+ final String prefix = keywordText.substring(0, firstColon);
+ final QNameModule qNameModule = prefixes.get(prefix);
+ if (qNameModule == null) {
+ // Failed to look the namespace
+ return null;
+ }
+
+ final String localName = keywordText.substring(firstColon + 1);
+ final StatementDefinition foundStmtDef;
+ if (prefixes.isPreLinkageMap()) {
+ foundStmtDef = stmtDef.getByNamespaceAndLocalName(qNameModule.getNamespace(), localName);
+ } else {
+ foundStmtDef = stmtDef.get(QName.create(qNameModule, localName));
+ }
+
+ return foundStmtDef != null ? foundStmtDef.getStatementName() : null;
+ }