Search in sources :

Example 1 with AbstractValidator

use of org.apache.cxf.tools.validator.AbstractValidator in project cxf by apache.

the class WSDL11Validator method isValid.

public boolean isValid() throws ToolException {
    // boolean isValid = true;
    String schemaDir = getSchemaDir();
    SchemaValidator schemaValidator = null;
    String[] schemas = (String[]) env.get(ToolConstants.CFG_SCHEMA_URL);
    // Tool will use the following sequence to find the schema files
    // 1.ToolConstants.CFG_SCHEMA_DIR from ToolContext
    // 2.ToolConstants.CXF_SCHEMA_DIR from System property
    // 3.If 1 and 2 is null , then load these schema files from jar file
    String wsdl = (String) env.get(ToolConstants.CFG_WSDLURL);
    Document doc = getWSDLDoc(wsdl);
    if (doc == null) {
        return true;
    }
    if (this.def == null) {
        try {
            this.def = getBus().getExtension(WSDLManager.class).getDefinition(wsdl);
        } catch (WSDLException e) {
            throw new ToolException(e);
        }
    }
    WSDLRefValidator wsdlRefValidator = new WSDLRefValidator(this.def, doc, getBus());
    wsdlRefValidator.setSuppressWarnings(env.optionSet(ToolConstants.CFG_SUPPRESS_WARNINGS));
    validators.add(wsdlRefValidator);
    if (env.fullValidateWSDL()) {
        validators.add(new UniqueBodyPartsValidator(this.def));
        validators.add(new WSIBPValidator(this.def));
        validators.add(new MIMEBindingValidator(this.def));
    }
    boolean notValid = false;
    for (AbstractValidator validator : validators) {
        if (!validator.isValid()) {
            notValid = true;
            addErrorMessage(validator.getErrorMessage());
        }
    }
    if (notValid) {
        throw new ToolException(this.getErrorMessage());
    }
    // By default just use WsdlRefValidator
    if (!env.fullValidateWSDL()) {
        return true;
    }
    if (!StringUtils.isEmpty(schemaDir)) {
        schemaValidator = new SchemaValidator(schemaDir, wsdl, schemas);
    } else {
        try {
            schemaValidator = new SchemaValidator(getDefaultSchemas(), wsdl, schemas);
        } catch (IOException e) {
            throw new ToolException("Schemas can not be loaded before validating wsdl", e);
        }
    }
    if (!schemaValidator.isValid()) {
        this.addErrorMessage(schemaValidator.getErrorMessage());
        throw new ToolException(this.getErrorMessage());
    }
    return true;
}
Also used : WSDLException(javax.wsdl.WSDLException) AbstractValidator(org.apache.cxf.tools.validator.AbstractValidator) IOException(java.io.IOException) Document(org.w3c.dom.Document) ToolException(org.apache.cxf.tools.common.ToolException)

Aggregations

IOException (java.io.IOException)1 WSDLException (javax.wsdl.WSDLException)1 ToolException (org.apache.cxf.tools.common.ToolException)1 AbstractValidator (org.apache.cxf.tools.validator.AbstractValidator)1 Document (org.w3c.dom.Document)1