Search in sources :

Example 31 with PrismSchema

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";
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema)

Example 32 with PrismSchema

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);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema)

Example 33 with PrismSchema

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;
}
Also used : QName(javax.xml.namespace.QName) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema)

Example 34 with PrismSchema

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);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 35 with PrismSchema

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);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Aggregations

PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)44 Test (org.testng.annotations.Test)20 QName (javax.xml.namespace.QName)10 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)8 Element (org.w3c.dom.Element)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)6 Task (com.evolveum.midpoint.task.api.Task)6 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 Document (org.w3c.dom.Document)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PrismSchemaImpl (com.evolveum.midpoint.prism.schema.PrismSchemaImpl)3 SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)3