Search in sources :

Example 1 with DynamicNamespacePrefixMapper

use of com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper in project midpoint by Evolveum.

the class PrismInternalTestUtil method constructPrismContext.

public static PrismContextImpl constructPrismContext(File extraSchema) throws SchemaException, FileNotFoundException {
    SchemaRegistryImpl schemaRegistry = new SchemaRegistryImpl();
    schemaRegistry.setCatalogResourceName(TEST_CATALOG_RESOURCE_NAME);
    DynamicNamespacePrefixMapper prefixMapper = new GlobalDynamicNamespacePrefixMapper();
    // Set default namespace?
    schemaRegistry.setNamespacePrefixMapper(prefixMapper);
    schemaRegistry.registerPrismDefaultSchemaResource("xml/ns/test/foo-1.xsd", "foo", ObjectFactory.class.getPackage());
    schemaRegistry.registerPrismSchemaResource("xml/ns/test/foo-types-1.xsd", "foot", null);
    schemaRegistry.registerPrismSchemaResource("xml/ns/public/types-3.xsd", "t", com.evolveum.prism.xml.ns._public.types_3.ObjectFactory.class.getPackage());
    schemaRegistry.registerPrismSchemaResource("xml/ns/public/query-3.xsd", "q", com.evolveum.prism.xml.ns._public.query_3.ObjectFactory.class.getPackage());
    schemaRegistry.registerPrismSchemasFromDirectory(SCHEMA_DIR);
    if (extraSchema != null) {
        schemaRegistry.registerPrismSchemaFile(extraSchema);
    }
    prefixMapper.registerPrefix(XMLConstants.W3C_XML_SCHEMA_NS_URI, DOMUtil.NS_W3C_XML_SCHEMA_PREFIX, false);
    prefixMapper.registerPrefix(PrismConstants.NS_ANNOTATION, PrismConstants.PREFIX_NS_ANNOTATION, false);
    prefixMapper.registerPrefix(PrismInternalTestUtil.NS_WEAPONS, PrismInternalTestUtil.NS_WEAPONS_PREFIX, false);
    return PrismContextImpl.create(schemaRegistry);
}
Also used : ObjectFactory(com.evolveum.midpoint.prism.foo.ObjectFactory) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) DynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper)

Example 2 with DynamicNamespacePrefixMapper

use of com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper in project midpoint by Evolveum.

the class JaxbTestUtil method createMarshaller.

private Marshaller createMarshaller(Map<String, Object> jaxbProperties) throws JAXBException {
    Marshaller marshaller = context.createMarshaller();
    // set default properties
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    DynamicNamespacePrefixMapper namespacePrefixMapper = ((SchemaRegistryImpl) getSchemaRegistry()).getNamespacePrefixMapper().clone();
    namespacePrefixMapper.setAlwaysExplicit(true);
    marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", namespacePrefixMapper);
    // set custom properties
    if (jaxbProperties != null) {
        for (Entry<String, Object> property : jaxbProperties.entrySet()) {
            marshaller.setProperty(property.getKey(), property.getValue());
        }
    }
    return marshaller;
}
Also used : Marshaller(javax.xml.bind.Marshaller) PrismObject(com.evolveum.midpoint.prism.PrismObject) DynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper)

Example 3 with DynamicNamespacePrefixMapper

use of com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper in project midpoint by Evolveum.

the class TestPrismContext method testPrefixMapper.

@Test
public void testPrefixMapper() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testPrefixMapper ]===");
    // WHEN
    PrismContextImpl prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    DynamicNamespacePrefixMapper prefixMapper = schemaRegistry.getNamespacePrefixMapper();
    System.out.println("Prefix mapper:");
    System.out.println(DebugUtil.dump(prefixMapper));
    assertEquals("Wrong foo prefix", "", prefixMapper.getPrefix(NS_FOO));
    assertEquals("Wrong xsd prefix", DOMUtil.NS_W3C_XML_SCHEMA_PREFIX, prefixMapper.getPrefix(XMLConstants.W3C_XML_SCHEMA_NS_URI));
}
Also used : SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) DynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper) Test(org.testng.annotations.Test)

Example 4 with DynamicNamespacePrefixMapper

use of com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper in project midpoint by Evolveum.

the class TestSchemaSanity method testPrefixMappings.

@Test
public void testPrefixMappings() {
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    DynamicNamespacePrefixMapper prefixMapper = schemaRegistry.getNamespacePrefixMapper();
    assertNotNull("No prefix mapper in context", prefixMapper);
    System.out.println("Prefix mapper:");
    System.out.println(prefixMapper.debugDump());
    // WHEN, THEN
    assertMapping(prefixMapper, PrismConstants.NS_ANNOTATION, PrismConstants.PREFIX_NS_ANNOTATION);
    assertMapping(prefixMapper, SchemaConstantsGenerated.NS_COMMON, "");
    assertMapping(prefixMapper, MidPointConstants.NS_RA, MidPointConstants.PREFIX_NS_RA);
    assertMapping(prefixMapper, SchemaTestConstants.NS_ICFC, "icfc");
    assertMapping(prefixMapper, SchemaTestConstants.NS_ICFS, "icfs");
    QName cBarQName = new QName(SchemaConstantsGenerated.NS_COMMON, "bar");
    QName cBarQNameWithPrefix = prefixMapper.setQNamePrefix(cBarQName);
    assertQName("common namespace implicit", SchemaConstantsGenerated.NS_COMMON, "bar", "", cBarQNameWithPrefix);
    QName cBarQNameWithPrefixExplixit = prefixMapper.setQNamePrefixExplicit(cBarQName);
    assertQName("common namespace implicit", SchemaConstantsGenerated.NS_COMMON, "bar", "c", cBarQNameWithPrefixExplixit);
}
Also used : QName(javax.xml.namespace.QName) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) DynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper) Test(org.testng.annotations.Test)

Aggregations

DynamicNamespacePrefixMapper (com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper)4 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)2 Test (org.testng.annotations.Test)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectFactory (com.evolveum.midpoint.prism.foo.ObjectFactory)1 SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)1 GlobalDynamicNamespacePrefixMapper (com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1