Search in sources :

Example 1 with XmlAnnotation

use of com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotation 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)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 XmlAnnotation (com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotation)1 XmlAnnotations (com.haulmont.cuba.core.sys.MetadataBuildSupport.XmlAnnotations)1