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);
}
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;
}
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));
}
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);
}
Aggregations