Search in sources :

Example 1 with XSDDiagnostic

use of org.eclipse.xsd.XSDDiagnostic in project tmdm-studio-se by Talend.

the class DataModelMainPage method validateDiagnoses.

private String validateDiagnoses(String[] msg_omit) {
    xsdSchema.clearDiagnostics();
    xsdSchema.getAllDiagnostics().clear();
    xsdSchema.validate();
    EList<XSDDiagnostic> diagnoses = xsdSchema.getAllDiagnostics();
    // $NON-NLS-1$
    String error = "";
    Set<String> errors = new HashSet<String>();
    for (int i = 0; i < diagnoses.size(); i++) {
        XSDDiagnostic dia = diagnoses.get(i);
        XSDDiagnosticSeverity servity = dia.getSeverity();
        if (servity == XSDDiagnosticSeverity.ERROR_LITERAL || servity == XSDDiagnosticSeverity.FATAL_LITERAL) {
            boolean omit = false;
            for (String msg : msg_omit) {
                if (dia.getMessage().indexOf(msg) != -1) {
                    omit = true;
                    break;
                }
            }
            if (!omit && !errors.contains(dia.getMessage())) {
                // $NON-NLS-1$
                error += dia.getMessage() + "\n";
                errors.add(dia.getMessage());
            }
        }
    }
    return error;
}
Also used : XSDDiagnostic(org.eclipse.xsd.XSDDiagnostic) XSDDiagnosticSeverity(org.eclipse.xsd.XSDDiagnosticSeverity) HashSet(java.util.HashSet)

Example 2 with XSDDiagnostic

use of org.eclipse.xsd.XSDDiagnostic in project tmdm-studio-se by Talend.

the class XSDEditor method validateDiagnoses.

/**
 * DOC talend-mdm Comment method "validateDiagnoses".
 *
 * @param xsdSchema
 * @return
 */
private String validateDiagnoses(XSDSchema xsdSchema) {
    xsdSchema.clearDiagnostics();
    xsdSchema.getAllDiagnostics().clear();
    xsdSchema.validate();
    EList<XSDDiagnostic> diagnoses = xsdSchema.getAllDiagnostics();
    // $NON-NLS-1$
    String error = "";
    Set<String> errors = new HashSet<String>();
    for (int i = 0; i < diagnoses.size(); i++) {
        XSDDiagnostic dia = diagnoses.get(i);
        XSDDiagnosticSeverity servity = dia.getSeverity();
        if (servity == XSDDiagnosticSeverity.ERROR_LITERAL || servity == XSDDiagnosticSeverity.FATAL_LITERAL) {
            boolean omit = false;
            for (String msg : MSG_OMIT) {
                if (dia.getMessage().indexOf(msg) != -1) {
                    omit = true;
                    break;
                }
            }
            if (!omit && !errors.contains(dia.getMessage())) {
                // $NON-NLS-1$
                error += dia.getMessage() + "\n";
                errors.add(dia.getMessage());
            }
        }
    }
    return error;
}
Also used : XSDDiagnostic(org.eclipse.xsd.XSDDiagnostic) XSDDiagnosticSeverity(org.eclipse.xsd.XSDDiagnosticSeverity) HashSet(java.util.HashSet)

Example 3 with XSDDiagnostic

use of org.eclipse.xsd.XSDDiagnostic in project tmdm-common by Talend.

the class MetadataRepository method load.

public void load(InputStream inputStream, ValidationHandler handler) {
    if (inputStream == null) {
        throw new IllegalArgumentException("Input stream can not be null.");
    }
    // Validates data model using shared studio / server classes
    // Load user defined data model now
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
    XSDParser parse = new XSDParser(options);
    parse.parse(inputStream);
    XSDSchema schema = parse.getSchema();
    if (schema == null) {
        throw new IllegalStateException("No schema parsed from input (make sure stream contains a data model).");
    }
    schema.validate();
    EList<XSDDiagnostic> diagnostics = schema.getDiagnostics();
    for (XSDDiagnostic diagnostic : diagnostics) {
        XSDDiagnosticSeverity severity = diagnostic.getSeverity();
        if (XSDDiagnosticSeverity.ERROR_LITERAL.equals(severity)) {
            handler.error((TypeMetadata) null, "XSD validation error: " + diagnostic.getMessage(), null, -1, -1, ValidationError.XML_SCHEMA);
        } else if (XSDDiagnosticSeverity.WARNING_LITERAL.equals(severity)) {
            handler.error((TypeMetadata) null, "XSD validation warning: " + diagnostic.getMessage(), null, -1, -1, ValidationError.XML_SCHEMA);
        }
    }
    XmlSchemaWalker.walk(schema, this);
    // TMDM-4876 Additional processing for entity inheritance
    resolveAdditionalSuperTypes(this);
    // "Freeze" all types (ensure all soft references now point to actual types in the repository).
    nonInstantiableTypes.put(getUserNamespace(), freezeTypes(nonInstantiableTypes.get(getUserNamespace())));
    // "Freeze" all reusable type usages in the data model.
    freezeUsages();
    entityTypes.put(getUserNamespace(), freezeTypes(entityTypes.get(getUserNamespace())));
    // Validate types
    for (TypeMetadata type : getUserComplexTypes()) {
        if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(type.getNamespace())) {
            type.validate(handler);
        }
    }
    for (TypeMetadata type : getNonInstantiableTypes()) {
        if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(type.getNamespace())) {
            type.validate(handler);
        }
    }
    // Perform data model-scoped validation (e.g. cycles).
    ValidationFactory.getRule(this).perform(handler);
    handler.end();
    if (handler.getErrorCount() != 0) {
        LOGGER.error("Could not parse data model (" + handler.getErrorCount() + " error(s) found).");
    }
}
Also used : XSDDiagnostic(org.eclipse.xsd.XSDDiagnostic) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) XSDParser(org.eclipse.xsd.util.XSDParser) XSDDiagnosticSeverity(org.eclipse.xsd.XSDDiagnosticSeverity) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDDiagnostic (org.eclipse.xsd.XSDDiagnostic)3 XSDDiagnosticSeverity (org.eclipse.xsd.XSDDiagnosticSeverity)3 HashSet (java.util.HashSet)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 XSDParser (org.eclipse.xsd.util.XSDParser)1