- final String xPathPartTrimmed = getIdAndPrefixAsStr(xPathArgument).trim();
- final Iterator<String> it = COLON_SPLITTER.split(xPathPartTrimmed).iterator();
-
- // Empty string
- if (!it.hasNext()) {
- return null;
- }
-
- final String prefix = it.next().trim();
- if (prefix.isEmpty()) {
- return null;
- }
-
- // it is not "prefix:value"
- if (!it.hasNext()) {
- return null;
- }
-
- final String identifier = it.next().trim();
- if (identifier.isEmpty()) {
- return null;
- }
-
- URI namespace = null;
- String namespaceStr = null;
- try {
- namespaceStr = element.lookupNamespaceURI(prefix);
- namespace = new URI(namespaceStr);
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("It wasn't possible to convert " + namespaceStr + " to URI object.");
- } catch (NullPointerException e) {
- throw new IllegalArgumentException("It wasn't possible to get namespace for prefix " + prefix);
- }
-
- final Module module = schemaContext.findModuleByNamespaceAndRevision(namespace, null);
- Preconditions.checkNotNull(module, "Unknown module: %s, cannot parse identity %s", namespace, xPathArgument);
- return QName.create(module.getQNameModule(), identifier);
- }
-
- private static String trimIfEndIs(final String str, final char end) {
- final int l = str.length() - 1;
- if (str.charAt(l) != end) {
- return null;
- }
-
- return str.substring(1, l);