Search in sources :

Example 1 with XmlAnnotations

use of com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations in project cuba by cuba-platform.

the class MetadataLoader method loadMetadata.

/**
 * Loads metadata session.
 */
public void loadMetadata() {
    List<MetadataBuildSupport.XmlFile> metadataXmlList = metadataBuildSupport.init();
    initRootPackages(metadataXmlList);
    initDatatypes(metadataBuildSupport.getDatatypeElements(metadataXmlList));
    MetaModelLoader modelLoader = createModelLoader(session);
    Map<String, List<EntityClassInfo>> entityPackages = metadataBuildSupport.getEntityPackages(metadataXmlList);
    for (Map.Entry<String, List<EntityClassInfo>> entry : entityPackages.entrySet()) {
        modelLoader.loadModel(entry.getKey(), entry.getValue());
    }
    for (MetaClass metaClass : session.getClasses()) {
        postProcessClass(metaClass);
        initMetaAnnotations(metaClass);
    }
    initStoreMetaAnnotations(entityPackages);
    initExtensionMetaAnnotations();
    List<XmlAnnotations> xmlAnnotations = metadataBuildSupport.getEntityAnnotations(metadataXmlList);
    for (MetaClass metaClass : session.getClasses()) {
        addMetaAnnotationsFromXml(xmlAnnotations, metaClass);
    }
    replaceExtendedMetaClasses();
}
Also used : XmlAnnotations(com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 2 with XmlAnnotations

use of com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations in project cuba by cuba-platform.

the class MetadataLoader method addMetaAnnotationsFromXml.

/**
 * Initialize entity annotations from definition in <code>metadata.xml</code>.
 * <p>Can be overridden in application projects to handle application-specific annotations.</p>
 *
 * @param xmlAnnotations map of class name to annotations map
 * @param metaClass      MetaClass instance to assign annotations
 */
protected void addMetaAnnotationsFromXml(List<XmlAnnotations> xmlAnnotations, MetaClass metaClass) {
    for (XmlAnnotations xmlAnnotation : xmlAnnotations) {
        MetaClass metaClassFromXml = session.getClassNN(ReflectionHelper.getClass(xmlAnnotation.entityClass));
        Class extendedClass = extendedEntities.getExtendedClass(metaClassFromXml);
        MetaClass effectiveMetaClass = extendedClass != null ? session.getClassNN(extendedClass) : metaClassFromXml;
        if (effectiveMetaClass.equals(metaClass)) {
            for (Map.Entry<String, XmlAnnotation> entry : xmlAnnotation.annotations.entrySet()) {
                assignMetaAnnotationValueFromXml(entry.getKey(), entry.getValue(), metaClass.getAnnotations());
            }
            for (XmlAnnotations attributeAnnotation : xmlAnnotation.attributeAnnotations) {
                MetaProperty property = metaClass.getPropertyNN(attributeAnnotation.entityClass);
                for (Map.Entry<String, XmlAnnotation> entry : attributeAnnotation.annotations.entrySet()) {
                    assignMetaAnnotationValueFromXml(entry.getKey(), entry.getValue(), property.getAnnotations());
                }
            }
            break;
        }
    }
}
Also used : XmlAnnotations(com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) XmlAnnotation(com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotation) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)2 XmlAnnotations (com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 XmlAnnotation (com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotation)1