use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class PathGenerator method typeDefinitionUrl.
public String typeDefinitionUrl(QName typeName, String prefixToBase, PrismContext prismContext) {
String namespaceURI = typeName.getNamespaceURI();
PrismSchema schema = prismContext.getSchemaRegistry().findSchemaByNamespace(namespaceURI);
if (schema == null) {
return null;
}
return prefixToBase + "/" + getSchemaDirName(schema) + "/type/" + typeName.getLocalPart() + ".html";
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class PrismContainerDefinitionImpl method createContainerDefinition.
public PrismContainerDefinition createContainerDefinition(QName name, QName typeName, int minOccurs, int maxOccurs) {
PrismSchema typeSchema = prismContext.getSchemaRegistry().findSchemaByNamespace(typeName.getNamespaceURI());
if (typeSchema == null) {
throw new IllegalArgumentException("Schema for namespace " + typeName.getNamespaceURI() + " is not known in the prism context");
}
ComplexTypeDefinition typeDefinition = typeSchema.findComplexTypeDefinition(typeName);
if (typeDefinition == null) {
throw new IllegalArgumentException("Type " + typeName + " is not known in the schema");
}
return createContainerDefinition(name, typeDefinition, minOccurs, maxOccurs);
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class PrismUnmarshaller method parseContainerValueFromMap.
private <C extends Containerable> PrismContainerValue<C> parseContainerValueFromMap(@NotNull MapXNode map, @NotNull PrismContainerDefinition<C> containerDef, @NotNull ParsingContext pc) throws SchemaException {
Long id = getContainerId(map);
ComplexTypeDefinition complexTypeDefinition = containerDef.getComplexTypeDefinition();
PrismContainerValue<C> cval;
if (containerDef instanceof PrismObjectDefinition) {
cval = ((PrismObjectDefinition) containerDef).createValue();
} else {
// override container definition, if explicit type is specified
if (map.getTypeQName() != null) {
ComplexTypeDefinition specificDef = getSchemaRegistry().findComplexTypeDefinitionByType(map.getTypeQName());
if (specificDef != null) {
complexTypeDefinition = specificDef;
} else {
pc.warnOrThrow(LOGGER, "Unknown type " + map.getTypeQName() + " in " + map);
}
}
cval = new PrismContainerValue<>(null, null, null, id, complexTypeDefinition, prismContext);
}
for (Entry<QName, XNode> entry : map.entrySet()) {
QName itemName = entry.getKey();
if (itemName == null) {
throw new IllegalArgumentException("Null item name while parsing " + map.debugDump());
}
if (QNameUtil.match(itemName, XNode.KEY_CONTAINER_ID)) {
continue;
}
if (containerDef instanceof PrismObjectDefinition && (QNameUtil.match(itemName, XNode.KEY_OID) || QNameUtil.match(itemName, XNode.KEY_VERSION))) {
continue;
}
ItemDefinition itemDef = locateItemDefinition(itemName, complexTypeDefinition, entry.getValue());
if (itemDef == null) {
if (complexTypeDefinition == null || complexTypeDefinition.isXsdAnyMarker() || complexTypeDefinition.isRuntimeSchema()) {
PrismSchema itemSchema = getSchemaRegistry().findSchemaByNamespace(itemName.getNamespaceURI());
if (itemSchema != null) {
// If we already have schema for this namespace then a missing element is
// an error. We positively know that it is not in the schema.
pc.warnOrThrow(LOGGER, "Item " + itemName + " has no definition (schema present, in container " + containerDef + ")" + "while parsing " + map.debugDump());
continue;
} else {
// No definition for item, but the schema is runtime. the definition may come later.
// Null is OK here. The item will be parsed as "raw"
}
} else {
// complex type definition is static
pc.warnOrThrow(LOGGER, "Item " + itemName + " has no definition (in container value " + complexTypeDefinition + ")" + "while parsing " + map.debugDump());
// don't even attempt to parse it
continue;
}
}
Item<?, ?> item;
if (entry.getValue() == null) {
if (itemDef != null) {
// TODO or skip the creation altogether?
item = itemDef.instantiate();
} else {
item = null;
}
} else {
item = parseItemInternal(entry.getValue(), itemName, itemDef, pc);
}
// names and representations and these cannot be processed as one map or list
if (item != null) {
cval.merge(item);
}
}
return cval;
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class TestPrismSchemaConstruction method schemaRoundtrip.
private void schemaRoundtrip(PrismContext ctx) throws SchemaException, SAXException, IOException {
PrismSchema schema = constructSchema(ctx);
assertSchema(schema);
// WHEN
Document xsdDocument = schema.serializeToXsd();
// THEN
Element xsdElement = DOMUtil.getFirstChildElement(xsdDocument);
System.out.println("Serialized schema");
System.out.println(DOMUtil.serializeDOMToString(xsdElement));
assertPrefix("xsd", xsdElement);
Element displayNameElement = DOMUtil.findElementRecursive(xsdElement, PrismConstants.A_DISPLAY_NAME);
assertPrefix(PrismConstants.PREFIX_NS_ANNOTATION, displayNameElement);
// re-parse
PrismSchema reparsedSchema = PrismSchemaImpl.parse(xsdElement, true, "serialized schema", ctx);
System.out.println("Re-parsed schema");
System.out.println(reparsedSchema.debugDump());
assertSchema(reparsedSchema);
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class TestPrismContext method testSchemaToDom.
@Test
public void testSchemaToDom() throws SchemaException, SAXException, IOException {
System.out.println("===[ testSchemaToDom ]===");
// GIVEN
PrismContext prismContext = constructInitializedPrismContext();
PrismSchema fooSchema = prismContext.getSchemaRegistry().findSchemaByNamespace(NS_FOO);
// WHEN
Document fooXsd = fooSchema.serializeToXsd();
// THEN
assertNotNull("No foo XSD DOM", fooXsd);
}
Aggregations