Search in sources :

Example 6 with SchemaRegistryImpl

use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl in project midpoint by Evolveum.

the class SchemaDocMojo method createSchemaRegistry.

@NotNull
private SchemaRegistryImpl createSchemaRegistry() throws SchemaException {
    SchemaRegistryImpl schemaRegistry = new SchemaRegistryImpl();
    schemaRegistry.setNamespacePrefixMapper(new GlobalDynamicNamespacePrefixMapper());
    return schemaRegistry;
}
Also used : SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with SchemaRegistryImpl

use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl in project midpoint by Evolveum.

the class MidPointPrismContextFactory method createSchemaRegistry.

@NotNull
private SchemaRegistryImpl createSchemaRegistry() throws SchemaException, FileNotFoundException {
    SchemaRegistryImpl schemaRegistry = new SchemaRegistryImpl();
    schemaRegistry.setDefaultNamespace(SchemaConstantsGenerated.NS_COMMON);
    schemaRegistry.setNamespacePrefixMapper(new GlobalDynamicNamespacePrefixMapper());
    registerBuiltinSchemas(schemaRegistry);
    registerExtensionSchemas(schemaRegistry);
    return schemaRegistry;
}
Also used : SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with SchemaRegistryImpl

use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl in project midpoint by Evolveum.

the class MidPointPrismContextFactory method createEmptyPrismContext.

public PrismContext createEmptyPrismContext() throws SchemaException, FileNotFoundException {
    SchemaRegistryImpl schemaRegistry = createSchemaRegistry();
    PrismContextImpl context = PrismContextImpl.createEmptyContext(schemaRegistry);
    context.setDefinitionFactory(createDefinitionFactory());
    context.setDefaultRelation(SchemaConstants.ORG_DEFAULT);
    return context;
}
Also used : PrismContextImpl(com.evolveum.midpoint.prism.PrismContextImpl) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)

Example 9 with SchemaRegistryImpl

use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl in project midpoint by Evolveum.

the class SchemaDocMojo method createInitializedPrismContext.

private PrismContext createInitializedPrismContext() throws MojoFailureException {
    try {
        SchemaRegistryImpl schemaRegistry = createSchemaRegistry();
        for (File schemaFile : schemaFiles) {
            getLog().info("SchemaDoc: registering schema file: " + schemaFile);
            if (!schemaFile.exists()) {
                throw new MojoFailureException("Schema file " + schemaFile + " does not exist");
            }
            schemaRegistry.registerPrismSchemaFile(schemaFile);
        }
        if (catalogFiles != null && catalogFiles.length > 0) {
            for (File catalogFile : catalogFiles) {
                getLog().info("SchemaDoc: using catalog file: " + catalogFile);
                if (!catalogFile.exists()) {
                    throw new IOException("Catalog file '" + catalogFile + "' does not exist.");
                }
            }
            schemaRegistry.setCatalogFiles(catalogFiles);
        }
        PrismContextImpl context = PrismContextImpl.create(schemaRegistry);
        context.setDefinitionFactory(new SchemaDefinitionFactory());
        context.initialize();
        return context;
    } catch (SchemaException e) {
        handleFailure(e);
        // never reached
        return null;
    } catch (FileNotFoundException e) {
        handleFailure(e);
        // never reached
        return null;
    } catch (SAXException e) {
        handleFailure(e);
        // never reached
        return null;
    } catch (IOException e) {
        handleFailure(e);
        // never reached
        return null;
    }
}
Also used : SchemaDefinitionFactory(com.evolveum.midpoint.prism.schema.SchemaDefinitionFactory) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) PrismContextImpl(com.evolveum.midpoint.prism.PrismContextImpl) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) SAXException(org.xml.sax.SAXException)

Example 10 with SchemaRegistryImpl

use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl in project midpoint by Evolveum.

the class TestExtraSchema method testExtraSchema.

/**
	 * Test is extra schema can be loaded to the schema registry and whether the file compliant to that
	 * schema can be validated.
	 */
@Test
public void testExtraSchema() throws SAXException, IOException, SchemaException {
    System.out.println("===[ testExtraSchema ]===");
    Document dataDoc = DOMUtil.parseFile(new File(COMMON_DIR_PATH, "root-foo.xml"));
    PrismContext context = constructPrismContext();
    SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
    Document extraSchemaDoc = DOMUtil.parseFile(new File(EXTRA_SCHEMA_DIR, "root.xsd"));
    reg.registerSchema(extraSchemaDoc, "file root.xsd");
    reg.initialize();
    Schema javaxSchema = reg.getJavaxSchema();
    assertNotNull(javaxSchema);
    Validator validator = javaxSchema.newValidator();
    DOMResult validationResult = new DOMResult();
    validator.validate(new DOMSource(dataDoc), validationResult);
//		System.out.println("Validation result:");
//		System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) Schema(javax.xml.validation.Schema) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Document(org.w3c.dom.Document) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) File(java.io.File) Validator(javax.xml.validation.Validator) Test(org.testng.annotations.Test)

Aggregations

SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)12 Test (org.testng.annotations.Test)6 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)5 PrismContextImpl (com.evolveum.midpoint.prism.PrismContextImpl)3 GlobalDynamicNamespacePrefixMapper (com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper)3 UserType (com.evolveum.midpoint.prism.foo.UserType)2 DOMResult (javax.xml.transform.dom.DOMResult)2 DOMSource (javax.xml.transform.dom.DOMSource)2 Schema (javax.xml.validation.Schema)2 Validator (javax.xml.validation.Validator)2 NotNull (org.jetbrains.annotations.NotNull)2 Document (org.w3c.dom.Document)2 ObjectFactory (com.evolveum.midpoint.prism.foo.ObjectFactory)1 SchemaDefinitionFactory (com.evolveum.midpoint.prism.schema.SchemaDefinitionFactory)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 DynamicNamespacePrefixMapper (com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper)1 InternalMonitor (com.evolveum.midpoint.schema.internals.InternalMonitor)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 File (java.io.File)1 QName (javax.xml.namespace.QName)1