if (value.length() == 1) {
// This is completely blank (just a ':') ...
return BLANK_NAME;
}
// Otherwise, it's invalid with a blank prefix and non-blank local name
throw new ValueFormatException(value, getPropertyType(),
GraphI18n.errorConvertingType.text(String.class.getSimpleName(),
Name.class.getSimpleName(), value));
}
if (firstChar == '{') {
// This might be fully-qualified ...
int closingBraceIndex = value.indexOf('}', 1);
if (closingBraceIndex == 1) {
// It's an empty pair of braces, so treat it as the blank namespace ...
if (value.length() == 2) {
// There's nothing else ...
return BLANK_NAME;
}
String namespaceUri = this.namespaceRegistryHolder.getNamespaceRegistry().getNamespaceForPrefix("");
String localName = decoder.decode(value.substring(2));
return new BasicName(namespaceUri, localName);
}
if (closingBraceIndex > 1) {
// Closing brace found with chars between ...
String namespaceUri = value.substring(1, closingBraceIndex);
int nextIndexAfterClosingBrace = closingBraceIndex + 1;
String localName = nextIndexAfterClosingBrace < value.length() ? value.substring(nextIndexAfterClosingBrace) : "";
// Decode the parts ...
return create(namespaceUri, localName, decoder);
}
} else {
// This is not fully-qualified, so see whether the value fits the prefixed name pattern ...
int colonIndex = value.indexOf(':');
if (colonIndex < 1) {
// There is no namespace prefix ...
String namespaceUri = this.namespaceRegistryHolder.getNamespaceRegistry().getNamespaceForPrefix("");
String localName = decoder.decode(value);
return new BasicName(namespaceUri, localName);
}
// There is a namespace ...
String prefix = value.substring(0, colonIndex);
prefix = decoder.decode(prefix);
// Look for a namespace match ...
String namespaceUri = this.namespaceRegistryHolder.getNamespaceRegistry().getNamespaceForPrefix(prefix);
// Fail if no namespace is found ...
if (namespaceUri == null) {
throw new NamespaceException(GraphI18n.noNamespaceRegisteredForPrefix.text(prefix));
}
int nextIndexAfterColon = colonIndex + 1;
String localName = nextIndexAfterColon < value.length() ? value.substring(nextIndexAfterColon) : "";
localName = decoder.decode(localName);
return new BasicName(namespaceUri, localName);
}
} catch (NamespaceException err) {
throw new ValueFormatException(value, getPropertyType(),
GraphI18n.errorConvertingType.text(String.class.getSimpleName(),
Name.class.getSimpleName(), value), err);
}
throw new ValueFormatException(value, getPropertyType(), GraphI18n.errorConvertingType.text(String.class.getSimpleName(),
Name.class.getSimpleName(),
value));
}