use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class AbstractViewRepository method loadView.
protected void loadView(Element rootElem, Element viewElem, View view, boolean systemProperties, Set<ViewInfo> visited) {
final MetaClass metaClass = metadata.getClassNN(view.getEntityClass());
final String viewName = view.getName();
Set<String> propertyNames = new HashSet<>();
for (Element propElem : (List<Element>) viewElem.elements("property")) {
String propertyName = propElem.attributeValue("name");
if (propertyNames.contains(propertyName)) {
throw new DevelopmentException(String.format("View %s/%s definition error: view declared property %s twice", metaClass.getName(), viewName, propertyName));
}
propertyNames.add(propertyName);
MetaProperty metaProperty = metaClass.getProperty(propertyName);
if (metaProperty == null) {
throw new DevelopmentException(String.format("View %s/%s definition error: property %s doesn't exists", metaClass.getName(), viewName, propertyName));
}
View refView = null;
String refViewName = propElem.attributeValue("view");
MetaClass refMetaClass;
Range range = metaProperty.getRange();
if (range == null) {
throw new RuntimeException("cannot find range for meta property: " + metaProperty);
}
final List<Element> propertyElements = Dom4j.elements(propElem, "property");
boolean inlineView = !propertyElements.isEmpty();
if (!range.isClass() && (refViewName != null || inlineView)) {
throw new DevelopmentException(String.format("View %s/%s definition error: property %s is not an entity", metaClass.getName(), viewName, propertyName));
}
if (refViewName != null) {
refMetaClass = getMetaClass(propElem, range);
refView = retrieveView(refMetaClass, refViewName, visited);
if (refView == null) {
for (Element e : Dom4j.elements(rootElem, "view")) {
if (refMetaClass.equals(getMetaClass(e.attributeValue("entity"), e.attributeValue("class"))) && refViewName.equals(e.attributeValue("name"))) {
refView = deployView(rootElem, e, visited);
break;
}
}
if (refView == null) {
MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalMetaClass(refMetaClass);
if (originalMetaClass != null) {
refView = retrieveView(originalMetaClass, refViewName, visited);
}
}
if (refView == null) {
throw new DevelopmentException(String.format("View %s/%s definition error: unable to find/deploy referenced view %s/%s", metaClass.getName(), viewName, range.asClass().getName(), refViewName));
}
}
}
if (inlineView) {
// try to import anonymous views
Class rangeClass = range.asClass().getJavaClass();
if (refView != null) {
// system properties are already in the source view
refView = new View(refView, rangeClass, "", false);
} else {
ViewProperty existingProperty = view.getProperty(propertyName);
if (existingProperty != null && existingProperty.getView() != null) {
refView = new View(existingProperty.getView(), rangeClass, "", systemProperties);
} else {
refView = new View(rangeClass, systemProperties);
}
}
loadView(rootElem, propElem, refView, systemProperties, visited);
}
FetchMode fetchMode = FetchMode.AUTO;
String fetch = propElem.attributeValue("fetch");
if (fetch != null)
fetchMode = FetchMode.valueOf(fetch);
view.addProperty(propertyName, refView, fetchMode);
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class MetadataLoader method postProcessClass.
protected void postProcessClass(MetaClass metaClass) {
for (MetaProperty property : metaClass.getOwnProperties()) {
postProcessProperty(metaClass, property);
}
Collection<MetaClass> missingDescendants = new HashSet<>(1);
findMissingDescendants(metaClass, missingDescendants);
if (!missingDescendants.isEmpty()) {
CollectionUtils.addAll(metaClass.getDescendants(), missingDescendants.iterator());
MetaClass ancestorMetaClass = metaClass.getAncestor();
while (ancestorMetaClass != null) {
CollectionUtils.addAll(ancestorMetaClass.getDescendants(), missingDescendants.iterator());
ancestorMetaClass = ancestorMetaClass.getAncestor();
}
}
MetaClass ancestorMetaClass = metaClass.getAncestor();
while (ancestorMetaClass != null) {
((MetaClassImpl) metaClass).addAncestor(ancestorMetaClass);
ancestorMetaClass = ancestorMetaClass.getAncestor();
}
}
use of com.haulmont.chile.core.model.MetaProperty 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;
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class PrintUtils method printClass.
public static String printClass(MetaClass metaClass) {
StringBuilder builder = new StringBuilder();
builder.append(metaClass.getName()).append("\n");
for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
builder.append(shift(metaProperty.getName() + ": " + metaProperty.getRange()));
}
return builder.toString();
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DynamicAttributesMetaClass method getPropertyPath.
@Override
public MetaPropertyPath getPropertyPath(String propertyPath) {
MetaProperty currentProperty;
currentProperty = this.getProperty(propertyPath);
if (currentProperty == null)
return null;
return new MetaPropertyPath(this, currentProperty);
}
Aggregations