use of org.lastaflute.di.helper.beans.BeanDesc in project lastaflute by lastaflute.
the class LaClassificationUtil method nativeFindByCode.
// ===================================================================================
// Native Method
// =============
// -----------------------------------------------------
// cls.of(code)
// ------------
protected static OptionalThing<Classification> nativeFindByCode(Class<?> cdefType, Object code) {
assertArgumentNotNull("cdefType", cdefType);
assertArgumentNotNull("code", code);
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(cdefType);
final String methodName = "of";
final Method method;
try {
method = beanDesc.getMethod(methodName, new Class<?>[] { Object.class });
} catch (BeanMethodNotFoundException e) {
String msg = "Failed to get the method " + methodName + "() of the classification type: " + cdefType;
throw new ClassificationFindByCodeMethodNotFoundException(msg, e);
}
@SuppressWarnings("unchecked") final OptionalThing<Classification> opt = (OptionalThing<Classification>) DfReflectionUtil.invokeStatic(method, new Object[] { code });
return opt;
}
use of org.lastaflute.di.helper.beans.BeanDesc in project lastaflute by lastaflute.
the class LaClassificationUtil method nativeCodeOf.
// -----------------------------------------------------
// Code-of
// -------
public static Object nativeCodeOf(Class<?> cdefType, Object code) {
// old method
assertArgumentNotNull("cdefType", cdefType);
assertArgumentNotNull("code", code);
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(cdefType);
final String methodName = "codeOf";
final Method method;
try {
method = beanDesc.getMethod(methodName, new Class<?>[] { Object.class });
} catch (BeanMethodNotFoundException e) {
String msg = "Failed to get the method " + methodName + "() of the classification type: " + cdefType;
throw new ClassificationCodeOfMethodNotFoundException(msg, e);
}
return DfReflectionUtil.invokeStatic(method, new Object[] { code });
}
use of org.lastaflute.di.helper.beans.BeanDesc in project lastaflute by lastaflute.
the class Lato method resolveBeanExpression.
protected static String resolveBeanExpression(Object obj, Map<Object, String> alreadyAppearedSet) {
if (obj == null) {
throw new IllegalArgumentException("The argument 'obj' should not be null.");
}
final Class<? extends Object> targetType = obj.getClass();
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(targetType);
final int propertySize = beanDesc.getPropertyDescSize();
final StringBuilder sb = new StringBuilder();
sb.append("{");
for (int i = 0; i < propertySize; i++) {
final PropertyDesc pd = beanDesc.getPropertyDesc(i);
final String propertyName = pd.getPropertyName();
final Object propertyValue = pd.getValue(obj);
final String exp = deriveExpression(propertyValue, alreadyAppearedSet, () -> {
return resolveObjectString(propertyValue, alreadyAppearedSet);
});
sb.append(i > 0 ? ", " : "").append(propertyName).append("=").append(exp);
}
sb.append("}");
return sb.toString();
}
use of org.lastaflute.di.helper.beans.BeanDesc in project lastaflute by lastaflute.
the class LaClassificationUtil method nativeMetaOf.
// -----------------------------------------------------
// Meta of
// -------
public static Object nativeMetaOf(Class<?> defmetaType, String classificationName) {
// old method
assertArgumentNotNull("defmetaType", defmetaType);
assertArgumentNotNull("classificationName", classificationName);
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(defmetaType);
final String methodName = "meta";
final Method method;
try {
method = beanDesc.getMethod(methodName, new Class<?>[] { String.class });
} catch (BeanMethodNotFoundException e) {
String msg = "Failed to get the method " + methodName + "() of the def-meta type: " + defmetaType;
throw new ClassificationMetaOfMethodNotFoundException(msg, e);
}
return DfReflectionUtil.invokeStatic(method, new Object[] { classificationName });
}
use of org.lastaflute.di.helper.beans.BeanDesc in project lastaflute by lastaflute.
the class LaClassificationUtil method nativeFindMeta.
// -----------------------------------------------------
// meta.find(name)
// ---------------
protected static OptionalThing<ClassificationMeta> nativeFindMeta(Class<?> defmetaType, String classificationName) {
// old method
assertArgumentNotNull("defmetaType", defmetaType);
assertArgumentNotNull("classificationName", classificationName);
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(defmetaType);
final String methodName = "find";
final Method method;
try {
method = beanDesc.getMethod(methodName, new Class<?>[] { String.class });
} catch (BeanMethodNotFoundException e) {
String msg = "Failed to get the method " + methodName + "() of the def-meta type: " + defmetaType;
throw new ClassificationMetaFindMethodNotFoundException(msg, e);
}
@SuppressWarnings("unchecked") OptionalThing<ClassificationMeta> opt = (OptionalThing<ClassificationMeta>) DfReflectionUtil.invokeStatic(method, new Object[] { classificationName });
return opt;
}
Aggregations