use of io.jmix.core.metamodel.datatype.impl.EnumerationImpl in project jmix by jmix-framework.
the class MetaModelLoader method loadRange.
@SuppressWarnings("unchecked")
protected MetadataObjectInfo<Range> loadRange(Session session, MetaProperty metaProperty, Class<?> type, Map<String, Object> map) {
Datatype datatype = (Datatype) map.get("datatype");
if (datatype != null) {
// A datatype is assigned explicitly
return new MetadataObjectInfo<>(new DatatypeRange(datatype));
}
datatype = getAdaptiveDatatype(metaProperty, type);
if (datatype == null) {
datatype = datatypes.find(type);
}
if (datatype != null) {
MetaClass metaClass = metaProperty.getDomain();
Class<?> javaClass = metaClass.getJavaClass();
try {
String name = "get" + StringUtils.capitalize(metaProperty.getName());
Method method = javaClass.getMethod(name);
Class<Enum> returnType = (Class<Enum>) method.getReturnType();
if (returnType.isEnum()) {
return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl<>(returnType)));
}
} catch (NoSuchMethodException e) {
// ignore
}
return new MetadataObjectInfo<>(new DatatypeRange(datatype));
} else if (type.isEnum()) {
return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl(type)));
} else {
return new MetadataObjectInfo<>(null, Collections.singletonList(new RangeInitTask(session, metaProperty, type, map)));
}
}
use of io.jmix.core.metamodel.datatype.impl.EnumerationImpl 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);
}
Aggregations