use of com.eden.orchid.api.options.annotations.ImpliedKey in project Orchid by JavaEden.
the class ModularTypeOptionExtractor method getOption.
@Override
public ModularType getOption(Field field, Object sourceObject, String key) {
final String typeKey;
final String valueKey;
if (field.isAnnotationPresent(ImpliedKey.class)) {
ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
typeKey = impliedKey.typeKey();
valueKey = impliedKey.valueKey();
} else {
typeKey = null;
valueKey = null;
}
Map<String, Object> data = mapConverter.convert(field.getType(), sourceObject, typeKey).second;
ModularType t = null;
Object actualType = data.get(typeKey);
if (actualType != null) {
t = createModularType(field, actualType.toString(), data);
if (t == null) {
Clog.e("Could not find modular type [{}] for {} {} in class {}, falling back to default [{}]", actualType, field.getType().getSimpleName(), field.getName(), field.getDeclaringClass().getSimpleName(), getDefaultType(field));
}
}
actualType = data.get(null);
if (actualType != null) {
t = createModularType(field, actualType.toString(), data);
if (t == null) {
Clog.e("Could not find modular type [{}] for {} {} in class {}, falling back to default [{}]", actualType, field.getType().getSimpleName(), field.getName(), field.getDeclaringClass().getSimpleName(), getDefaultType(field));
}
}
return t;
}
use of com.eden.orchid.api.options.annotations.ImpliedKey in project Orchid by JavaEden.
the class ModularTypeOptionExtractor method describeDefaultValue.
@Override
public String describeDefaultValue(Field field) {
final String typeKey;
final String valueKey;
if (field.isAnnotationPresent(ImpliedKey.class)) {
ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
typeKey = impliedKey.typeKey();
valueKey = impliedKey.valueKey();
} else {
typeKey = null;
valueKey = null;
}
return "Default " + field.getType().getSimpleName() + " of type '" + typeKey + "'";
}
use of com.eden.orchid.api.options.annotations.ImpliedKey in project Orchid by JavaEden.
the class ModularListOptionExtractor method getOption.
@Override
public ModularList getOption(Field field, Object sourceObject, String key) {
OrchidContext context = contextProvider.get();
final String typeKey;
final String valueKey;
if (field.isAnnotationPresent(ImpliedKey.class)) {
ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
typeKey = impliedKey.typeKey();
valueKey = impliedKey.valueKey();
} else {
typeKey = null;
valueKey = null;
}
Iterable iterable = iterableConverter.convert(field.getType(), sourceObject, typeKey, valueKey).second;
List<Map<String, Object>> jsonArray = new ArrayList<>();
for (Object o : iterable) {
Map<String, Object> map = (Map<String, Object>) mapConverter.convert(field.getType(), o).second;
jsonArray.add(map);
}
if (jsonArray.size() > 0) {
ModularList modularList = (ModularList) contextProvider.get().resolve(field.getType());
modularList.initialize(context, jsonArray);
return modularList;
}
return null;
}
use of com.eden.orchid.api.options.annotations.ImpliedKey in project Orchid by JavaEden.
the class MapOptionExtractor method getOption.
@Override
public Map getOption(Field field, Object sourceObject, String key) {
final String typeKey;
if (field.isAnnotationPresent(ImpliedKey.class)) {
ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
typeKey = impliedKey.typeKey();
} else {
typeKey = null;
}
return mapConverter.convert(field.getType(), sourceObject, typeKey).second;
}
Aggregations