Search in sources :

Example 1 with BeanDesc

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;
}
Also used : BeanMethodNotFoundException(org.lastaflute.di.helper.beans.exception.BeanMethodNotFoundException) OptionalThing(org.dbflute.optional.OptionalThing) BeanDesc(org.lastaflute.di.helper.beans.BeanDesc) Classification(org.dbflute.jdbc.Classification) Method(java.lang.reflect.Method)

Example 2 with BeanDesc

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 });
}
Also used : BeanMethodNotFoundException(org.lastaflute.di.helper.beans.exception.BeanMethodNotFoundException) BeanDesc(org.lastaflute.di.helper.beans.BeanDesc) Method(java.lang.reflect.Method)

Example 3 with BeanDesc

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();
}
Also used : BeanDesc(org.lastaflute.di.helper.beans.BeanDesc) PropertyDesc(org.lastaflute.di.helper.beans.PropertyDesc)

Example 4 with BeanDesc

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 });
}
Also used : BeanMethodNotFoundException(org.lastaflute.di.helper.beans.exception.BeanMethodNotFoundException) BeanDesc(org.lastaflute.di.helper.beans.BeanDesc) Method(java.lang.reflect.Method)

Example 5 with BeanDesc

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;
}
Also used : BeanMethodNotFoundException(org.lastaflute.di.helper.beans.exception.BeanMethodNotFoundException) ClassificationMeta(org.dbflute.jdbc.ClassificationMeta) OptionalThing(org.dbflute.optional.OptionalThing) BeanDesc(org.lastaflute.di.helper.beans.BeanDesc) Method(java.lang.reflect.Method)

Aggregations

BeanDesc (org.lastaflute.di.helper.beans.BeanDesc)5 Method (java.lang.reflect.Method)4 BeanMethodNotFoundException (org.lastaflute.di.helper.beans.exception.BeanMethodNotFoundException)4 OptionalThing (org.dbflute.optional.OptionalThing)2 Classification (org.dbflute.jdbc.Classification)1 ClassificationMeta (org.dbflute.jdbc.ClassificationMeta)1 PropertyDesc (org.lastaflute.di.helper.beans.PropertyDesc)1