* @param str String to check
* @return True if the string usable as a local name, false otherwise
*/
- public static final boolean isValidLocalName(final @Nullable String str) {
+ static final boolean isValidLocalName(final @Nullable String str) {
return str != null && !str.isEmpty() && checkContent(str);
}
return new UnqualifiedQName(checkLocalName(localName));
}
+ /**
+ * Create a new unqualified QName.
+ *
+ * @param localName The local name of this unqualified QName
+ * @return An UnqualifiedQName instance, or null if localName is not valid
+ */
+ @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "Non-grok of @Nullable")
+ public static @Nullable UnqualifiedQName tryCreate(final String localName) {
+ return isValidLocalName(localName) ? new UnqualifiedQName(localName) : null;
+ }
+
/**
* Read an UnqualifiedQName from a DataInput. The format is expected to match the output format of
* {@link #writeTo(DataOutput)}.
import com.google.common.collect.ImmutableList;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.AbstractQName;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
final int colon = value.indexOf(':');
if (colon == -1) {
- if (AbstractQName.isValidLocalName(value)) {
- return QName.unsafeOf(StmtContextUtils.getRootModuleQName(stmt), value).intern();
- }
- return null;
+ final UnqualifiedQName qname = UnqualifiedQName.tryCreate(value);
+ return qname == null ? null : qname.bindTo(StmtContextUtils.getRootModuleQName(stmt)).intern();
}
final QNameModule qnameModule = StmtContextUtils.getModuleQNameByPrefix(stmt, value.substring(0, colon));