@Override protected QName createQName(final String prefix, final String localName) { final String namespace = element.lookupNamespaceURI(prefix); Preconditions.checkArgument(namespace != null, "Failed to lookup prefix %s", prefix); final URI ns = URI.create(namespace); final Module module = schema.findModuleByNamespaceAndRevision(ns, null); Preconditions.checkArgument(module != null, "Namespace %s is not owned by a module", ns); return QName.create(module.getQNameModule(), localName); }
/** * Write a child JSON node identifier, optionally prefixing it with the module name corresponding * to its namespace. * * @param schema Schema context * @param writer Output writer * @param qname Namespace/name tuple * @throws IOException when the writer reports it */ final void writeChildJsonIdentifier( final SchemaContext schema, final JsonWriter writer, final QName qname) throws IOException { final StringBuilder sb = new StringBuilder(); // Prepend module name if namespaces do not match final URI ns = qname.getNamespace(); if (!ns.equals(getNamespace())) { final Module module = schema.findModuleByNamespaceAndRevision(ns, null); Preconditions.checkArgument(module != null, "Could not find module for namespace {}", ns); sb.append(module.getName()); sb.append(':'); } sb.append(qname.getLocalName()); writer.name(sb.toString()); }
@Override protected String prefixForNamespace(final URI namespace) { final Module module = context.findModuleByNamespaceAndRevision(namespace, null); return module == null ? null : module.getName(); }