XmlSchema resolveXmlSchema()

in src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java [676:723]


    XmlSchema resolveXmlSchema(String targetNamespace, String schemaLocation, String baseUri,
                               TargetNamespaceValidator validator) {

        if (getCachedSchema(targetNamespace, schemaLocation, baseUri) != null) {
            return getCachedSchema(targetNamespace, schemaLocation, baseUri);
        }

        // use the entity resolver provided if the schema location is present
        // null
        if (schemaLocation != null && !"".equals(schemaLocation)) {
            InputSource source =
                collection.getSchemaResolver().resolveEntity(targetNamespace, schemaLocation, baseUri);

            // the entity resolver was unable to resolve this!!
            if (source == null) {
                // try resolving it with the target namespace only with the
                // known namespace map
                return collection.getKnownSchema(targetNamespace);
            }
            final String systemId = source.getSystemId() == null ? schemaLocation : source.getSystemId();
            // Push repaired system id back into source where read sees it.
            // It is perhaps a bad thing to patch the source, but this fixes
            // a problem.
            source.setSystemId(systemId);
            final SchemaKey key = new XmlSchemaCollection.SchemaKey(targetNamespace, systemId);
            XmlSchema schema = collection.getSchema(key);
            if (schema != null) {
                return schema;
            }
            if (collection.check(key)) {
                collection.push(key);
                try {
                    XmlSchema readSchema = collection.read(source, validator);
                    putCachedSchema(targetNamespace, schemaLocation, baseUri, readSchema);
                    return readSchema;
                } finally {
                    collection.pop();
                }
            }
        } else {
            XmlSchema schema = collection.getKnownSchema(targetNamespace);
            if (schema != null) {
                return schema;
            }
        }

        return null;
    }