private QName getRefQName()

in xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java [799:832]


    private QName getRefQName(String pName, NamespaceContext pContext) {
        final int offset = pName.indexOf(':');
        String uri;
        final String localName;
        final String prefix;
        if (offset == -1) {
            uri = pContext.getNamespaceURI(Constants.DEFAULT_NS_PREFIX);
            if (Constants.NULL_NS_URI.equals(uri)) {
                if (currentSchema.getTargetNamespace() == null
                    && !currentSchema.getLogicalTargetNamespace().isEmpty()) {
                    // If object is unqualified in a schema without a target namespace then it could
                    // be that this schema is included in another one. The including namespace
                    // should then be used for this reference
                    return new QName(currentSchema.getLogicalTargetNamespace(), pName);
                }
                return new QName(Constants.NULL_NS_URI, pName);
            }
            localName = pName;
            prefix = Constants.DEFAULT_NS_PREFIX;
        } else {
            prefix = pName.substring(0, offset);
            uri = pContext.getNamespaceURI(prefix);
            if (uri == null || Constants.NULL_NS_URI.equals(uri) && currentSchema.getParent() != null
                && currentSchema.getParent().getNamespaceContext() != null) {
                uri = currentSchema.getParent().getNamespaceContext().getNamespaceURI(prefix);
            }

            if (uri == null || Constants.NULL_NS_URI.equals(uri)) {
                throw new IllegalStateException("The prefix " + prefix + " is not bound.");
            }
            localName = pName.substring(offset + 1);
        }
        return new QName(uri, localName, prefix);
    }