use of io.jmix.core.metamodel.model.impl.ClassRange in project jmix by jmix-framework.
the class KeyValueMetaPropertyBuilder method build.
public KeyValueMetaProperty build(MetaClass metaClass, String name, Class javaClass) {
MetaProperty.Type type;
Range range;
Session metadataSession = metadata.getSession();
if (Entity.class.isAssignableFrom(javaClass)) {
range = new ClassRange(metadataSession.findClass(javaClass));
type = MetaProperty.Type.ASSOCIATION;
} else if (EnumClass.class.isAssignableFrom(javaClass)) {
@SuppressWarnings("unchecked") EnumerationImpl enumeration = new EnumerationImpl(javaClass);
range = new EnumerationRange(enumeration);
type = MetaProperty.Type.ENUM;
} else {
@SuppressWarnings("unchecked") Datatype datatype = datatypeRegistry.get(javaClass);
range = new DatatypeRange(datatype);
type = MetaProperty.Type.DATATYPE;
}
return new KeyValueMetaProperty(metaClass, name, javaClass, range, type);
}
use of io.jmix.core.metamodel.model.impl.ClassRange in project jmix by jmix-framework.
the class ExtendedEntities method replaceExtendedMetaClasses.
protected void replaceExtendedMetaClasses() {
Session session = metadata.getSession();
List<Pair<MetaClass, MetaClass>> replaceMap = new ArrayList<>();
for (MetaClass metaClass : session.getClasses()) {
MetaClass effectiveMetaClass = session.getClass(getEffectiveClass(metaClass));
if (effectiveMetaClass != metaClass) {
replaceMap.add(new Pair<>(metaClass, effectiveMetaClass));
}
for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
MetaPropertyImpl propertyImpl = (MetaPropertyImpl) metaProperty;
// replace domain
Class effectiveDomainClass = getEffectiveClass(metaProperty.getDomain());
MetaClass effectiveDomainMeta = session.getClass(effectiveDomainClass);
if (metaProperty.getDomain() != effectiveDomainMeta) {
propertyImpl.setDomain(effectiveDomainMeta);
}
if (metaProperty.getRange().isClass()) {
// replace range class
ClassRange range = (ClassRange) metaProperty.getRange();
Class effectiveRangeClass = getEffectiveClass(range.asClass());
MetaClass effectiveRangeMeta = session.getClass(effectiveRangeClass);
if (effectiveRangeMeta != range.asClass()) {
ClassRange newRange = new ClassRange(effectiveRangeMeta);
newRange.setCardinality(range.getCardinality());
newRange.setOrdered(range.isOrdered());
((MetaPropertyImpl) metaProperty).setRange(newRange);
}
}
}
}
for (Pair<MetaClass, MetaClass> replace : replaceMap) {
MetaClass replacedMetaClass = replace.getFirst();
registerReplacedMetaClass(replacedMetaClass);
MetaClassImpl effectiveMetaClass = (MetaClassImpl) replace.getSecond();
((SessionImpl) session).registerClass(replacedMetaClass.getName(), replacedMetaClass.getJavaClass(), effectiveMetaClass);
}
}
Aggregations