Search in sources :

Example 1 with Schema

use of nl.nn.adapterframework.validation.Schema in project iaf by ibissource.

the class XmlValidator method getSchemas.

@Override
public List<Schema> getSchemas(IPipeLineSession session) throws PipeRunException {
    List<Schema> xsds = new ArrayList<Schema>();
    String schemaLocation = getSchemasId(session);
    if (schemaSessionKey != null) {
        final URL url = ClassUtils.getResourceURL(classLoader, schemaLocation);
        if (url == null) {
            throw new PipeRunException(this, getLogPrefix(session) + "could not find schema at [" + schemaLocation + "]");
        }
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setNoNamespaceSchemaLocation(schemaLocation);
        try {
            xsd.init();
        } catch (ConfigurationException e) {
            throw new PipeRunException(this, "Could not init xsd", e);
        }
        xsds.add(xsd);
        return xsds;
    }
    return null;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Schema(nl.nn.adapterframework.validation.Schema) ArrayList(java.util.ArrayList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) XSD(nl.nn.adapterframework.validation.XSD) URL(java.net.URL)

Example 2 with Schema

use of nl.nn.adapterframework.validation.Schema in project iaf by ibissource.

the class XmlValidator method getSchemas.

public List<Schema> getSchemas(boolean checkRootValidations) throws ConfigurationException {
    Set<XSD> xsds = getXsds();
    if (StringUtils.isEmpty(getNoNamespaceSchemaLocation())) {
        xsds = SchemaUtils.getXsdsRecursive(xsds);
        if (checkRootValidations) {
            checkInputRootValidations(xsds);
            checkOutputRootValidations(xsds);
        }
        try {
            Map<String, Set<XSD>> xsdsGroupedByNamespace = SchemaUtils.getXsdsGroupedByNamespace(xsds, false);
            xsds = SchemaUtils.mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(classLoader, xsdsGroupedByNamespace, null);
        } catch (Exception e) {
            throw new ConfigurationException(getLogPrefix(null) + "could not merge schema's", e);
        }
    } else {
        // Support redefine for noNamespaceSchemaLocation for backwards
        // compatibility. It's deprecated in the latest specification:
        // http://www.w3.org/TR/xmlschema11-1/#modify-schema
        // It's difficult to support redefine in
        // mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes so
        // we only use getXsdsRecursive here for root validation. Xerces
        // will need to resolve the imports, includes an redefines itself.
        // See comment in method XercesXmlValidator.stringToXMLInputSource()
        // too. The latest specification also specifies override:
        // http://www.w3.org/TR/xmlschema11-1/#override-schema
        // But this functionality doesn't seem to be (properly) supported by
        // Xerces (yet). WSDL generation was the main reason to introduce
        // mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes, in case of
        // noNamespaceSchemaLocation the WSDL generator doesn't use
        // XmlValidator.getXsds(). See comment in Wsdl.getXsds() too.
        Set<XSD> xsds_temp = SchemaUtils.getXsdsRecursive(xsds, false);
        if (checkRootValidations) {
            checkInputRootValidations(xsds_temp);
            checkOutputRootValidations(xsds_temp);
        }
    }
    List<Schema> schemas = new ArrayList<Schema>();
    SchemaUtils.sortByDependencies(xsds, schemas);
    return schemas;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Schema(nl.nn.adapterframework.validation.Schema) XSD(nl.nn.adapterframework.validation.XSD) ArrayList(java.util.ArrayList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException)

Aggregations

ArrayList (java.util.ArrayList)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 PipeRunException (nl.nn.adapterframework.core.PipeRunException)2 Schema (nl.nn.adapterframework.validation.Schema)2 XSD (nl.nn.adapterframework.validation.XSD)2 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PipeStartException (nl.nn.adapterframework.core.PipeStartException)1 XmlValidatorException (nl.nn.adapterframework.validation.XmlValidatorException)1