XmlSchemaImport handleImport()

in src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java [503:547]


    XmlSchemaImport handleImport(XmlSchema schema, Element importEl, Element schemaEl) {

        XmlSchemaImport schemaImport = new XmlSchemaImport(schema);

        Element annotationEl = XDOMUtil.getFirstChildElementNS(importEl, XmlSchema.SCHEMA_NS, "annotation");

        if (annotationEl != null) {
            XmlSchemaAnnotation importAnnotation = handleAnnotation(annotationEl);
            schemaImport.setAnnotation(importAnnotation);
        }

        schemaImport.namespace = importEl.getAttribute("namespace");
        final String uri = schemaImport.namespace;
        schemaImport.schemaLocation = importEl.getAttribute("schemaLocation");

        TargetNamespaceValidator validator = new TargetNamespaceValidator() {
            public void validate(XmlSchema pSchema) {
                final boolean valid;
                if (isEmpty(uri)) {
                    valid = isEmpty(pSchema.getSyntacticalTargetNamespace());
                } else {
                    valid = pSchema.getSyntacticalTargetNamespace().equals(uri);
                }
                if (!valid) {
                    throw new XmlSchemaException("An imported schema was announced to have the namespace "
                                                 + uri + ", but has the namespace "
                                                 + pSchema.getSyntacticalTargetNamespace());
                }
            }

            private boolean isEmpty(String pValue) {
                return pValue == null || Constants.NULL_NS_URI.equals(pValue);
            }
        };
        if (schemaImport.schemaLocation != null && !schemaImport.schemaLocation.equals("")) {
            if (schema.getSourceURI() != null) {
                schemaImport.schema =
                    resolveXmlSchema(uri, schemaImport.schemaLocation, schema.getSourceURI(), validator);
            } else {
                schemaImport.schema =
                    resolveXmlSchema(schemaImport.namespace, schemaImport.schemaLocation, validator);
            }
        }
        return schemaImport;
    }