Search in sources :

Example 11 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class ResourceManager method createSchemaUpdateDelta.

private ContainerDelta<XmlSchemaType> createSchemaUpdateDelta(PrismObject<ResourceType> resource, ResourceSchema resourceSchema) throws SchemaException {
    Document xsdDoc = null;
    try {
        // Convert to XSD
        LOGGER.trace("Serializing XSD resource schema for {} to DOM", resource);
        xsdDoc = resourceSchema.serializeToXsd();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Serialized XSD resource schema for {}:\n{}", resource, DOMUtil.serializeDOMToString(xsdDoc));
        }
    } catch (SchemaException e) {
        throw new SchemaException("Error processing resource schema for " + resource + ": " + e.getMessage(), e);
    }
    Element xsdElement = DOMUtil.getFirstChildElement(xsdDoc);
    if (xsdElement == null) {
        throw new SchemaException("No schema was generated for " + resource);
    }
    CachingMetadataType cachingMetadata = MiscSchemaUtil.generateCachingMetadata();
    // Store generated schema into repository (modify the original
    // Resource)
    LOGGER.info("Storing generated schema in resource {}", resource);
    ContainerDelta<XmlSchemaType> schemaContainerDelta = ContainerDelta.createDelta(ResourceType.F_SCHEMA, ResourceType.class, prismContext);
    PrismContainerValue<XmlSchemaType> cval = new PrismContainerValue<XmlSchemaType>(prismContext);
    schemaContainerDelta.setValueToReplace(cval);
    PrismProperty<CachingMetadataType> cachingMetadataProperty = cval.createProperty(XmlSchemaType.F_CACHING_METADATA);
    cachingMetadataProperty.setRealValue(cachingMetadata);
    List<QName> objectClasses = ResourceTypeUtil.getSchemaGenerationConstraints(resource);
    if (objectClasses != null) {
        PrismProperty<SchemaGenerationConstraintsType> generationConstraints = cval.createProperty(XmlSchemaType.F_GENERATION_CONSTRAINTS);
        SchemaGenerationConstraintsType constraints = new SchemaGenerationConstraintsType();
        constraints.getGenerateObjectClass().addAll(objectClasses);
        generationConstraints.setRealValue(constraints);
    }
    PrismProperty<SchemaDefinitionType> definitionProperty = cval.createProperty(XmlSchemaType.F_DEFINITION);
    ObjectTypeUtil.setXsdSchemaDefinition(definitionProperty, xsdElement);
    return schemaContainerDelta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) SchemaGenerationConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)

Example 12 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class ObjectTypeUtil method findXsdElement.

public static Element findXsdElement(PrismContainerValue<XmlSchemaType> xmlSchemaContainerValue) {
    PrismProperty<SchemaDefinitionType> definitionProperty = xmlSchemaContainerValue.findProperty(XmlSchemaType.F_DEFINITION);
    if (definitionProperty == null) {
        return null;
    }
    SchemaDefinitionType schemaDefinition = definitionProperty.getValue().getValue();
    if (schemaDefinition == null) {
        return null;
    }
    return schemaDefinition.getSchema();
//        List<Element> schemaElements = DOMUtil.listChildElements(definitionElement);
//        for (Element e : schemaElements) {
//            if (QNameUtil.compareQName(DOMUtil.XSD_SCHEMA_ELEMENT, e)) {
//            	DOMUtil.fixNamespaceDeclarations(e);
//                return e;
//            }
//        }
//        return null;
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)

Aggregations

SchemaDefinitionType (com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)11 Element (org.w3c.dom.Element)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 QName (javax.xml.namespace.QName)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)2 JAXBElement (javax.xml.bind.JAXBElement)2 Test (org.testng.annotations.Test)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)1 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)1 ExtensionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 SchemaGenerationConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType)1 SchemaHandlingType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType)1 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)1 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)1