QName { public static QName parseQName(final @NotNull NamespaceMapping mapping, final @NotNull Type type, final @NotNull String qName) { if (qName.startsWith("{") && qName.contains("}")) { final int lastBrace = qName.indexOf("}"); final String uri = qName.substring(1, lastBrace); final String localName = qName.substring(lastBrace + 1); return new QName(type, result1(mapping::getPrefix).apply(uri).toOptional().orElse(null), localName, uri); } else if (qName.contains(":")) { final String[] parts = qName.split(":", 2); final String prefix = parts[0]; final String localName = parts[1]; return new QName(type, prefix, localName, result1(mapping::getURI).apply(prefix).toOptional().orElse(null)); } throw new UnqualifiedNameException(qName); } QName(final @NotNull Type type,
                 final @Nullable String prefix,
                 final @NotNull String localName,
                 final @Nullable String uri); static QName parseQName(final @NotNull NamespaceMapping mapping,
                                   final @NotNull Type type,
                                   final @NotNull String qName); static QName adaptName(final @NotNull NamespaceMapping mapping,
                                  final @NotNull Type type,
                                  final @NotNull Name name); Type getType(); String getPrefix(); String getLocalName(); String getUri(); @Override String toString(); String toExpandedForm(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test(expected = QName.UnqualifiedNameException.class) public void testParseQName_unqualified() { QName.parseQName(JsonCnd.BUILTIN_MAPPINGS, QName.Type.NODETYPE, "aType"); }
@Test public void testParseQName() { final QName ntPrefixName = QName.parseQName(JsonCnd.BUILTIN_MAPPINGS, QName.Type.NODETYPE, "nt:aType"); assertEquals("type is ", QName.Type.NODETYPE, ntPrefixName.getType()); assertEquals("prefix is ", "nt", ntPrefixName.getPrefix()); assertEquals("localName is ", "aType", ntPrefixName.getLocalName()); assertEquals("uri is ", NamespaceRegistry.NAMESPACE_NT, ntPrefixName.getUri()); assertEquals("toString is ", "nt:aType", ntPrefixName.toString()); assertEquals("expanded is ", "{" + NamespaceRegistry.NAMESPACE_NT + "}aType", ntPrefixName.toExpandedForm()); final QName ntUriName = QName.parseQName(JsonCnd.BUILTIN_MAPPINGS, QName.Type.NODETYPE, "{http: assertEquals("type is ", QName.Type.NODETYPE, ntUriName.getType()); assertNull("prefix is null", ntUriName.getPrefix()); assertEquals("localName is ", "anotherType", ntUriName.getLocalName()); assertEquals("uri is ", "http: assertEquals("toString is ", "{http: assertEquals("expanded is ", "{http: }