本文整理汇总了Java中org.lastaflute.di.helper.beans.factory.BeanDescFactory类的典型用法代码示例。如果您正苦于以下问题:Java BeanDescFactory类的具体用法?Java BeanDescFactory怎么用?Java BeanDescFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanDescFactory类属于org.lastaflute.di.helper.beans.factory包,在下文中一共展示了BeanDescFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareSimpleProperty
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected Object prepareSimpleProperty(Object bean, String name) {
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());
if (!beanDesc.hasPropertyDesc(name)) {
return null;
}
final PropertyDesc pd = beanDesc.getPropertyDesc(name);
if (!pd.isReadable()) {
return null;
}
Object value = pd.getValue(bean);
if (value == null) {
final Class<?> propertyType = pd.getPropertyType();
if (!LdiModifierUtil.isAbstract(propertyType)) {
value = LdiClassUtil.newInstance(propertyType);
if (pd.isWritable()) {
pd.setValue(bean, value);
}
} else if (Map.class.isAssignableFrom(propertyType)) {
value = new HashMap<String, Object>();
if (pd.isWritable()) {
pd.setValue(bean, value);
}
}
}
return value;
}
示例2: setSimpleProperty
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected void setSimpleProperty(VirtualForm virtualForm, Object bean, String name, Object value, StringBuilder pathSb,
FormMappingOption option, Object parentBean, String parentName) {
if (bean instanceof Map) {
@SuppressWarnings("unchecked")
final Map<String, Object> map = (Map<String, Object>) bean;
setMapProperty(map, name, value, option, parentBean, parentName);
return;
}
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());
if (!beanDesc.hasPropertyDesc(name)) {
handleUndefinedParameter(bean, name, value, option, beanDesc);
return;
}
final PropertyDesc pd = beanDesc.getPropertyDesc(name);
if (!pd.isWritable()) {
handleUndefinedParameter(bean, name, value, option, beanDesc);
return;
}
try {
mappingToProperty(virtualForm, bean, name, value, pathSb, option, pd);
} catch (RuntimeException e) {
handleMappingFailureException(beanDesc, name, value, pathSb, pd, e);
}
}
示例3: detectLonelyAnnotatedField
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected void detectLonelyAnnotatedField(Field field, Class<?> beanType, Map<String, Class<?>> genericMap, Deque<String> pathDeque,
Set<Class<?>> checkedTypeSet) {
final boolean hasNestedBeanAnnotation = hasNestedBeanAnnotation(field);
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(beanType);
for (int i = 0; i < beanDesc.getFieldSize(); i++) {
final Field nestedField = beanDesc.getField(i);
if (!hasNestedBeanAnnotation) {
for (Annotation anno : nestedField.getAnnotations()) {
if (isValidatorAnnotation(anno.annotationType())) {
throwLonelyValidatorAnnotationException(field, nestedField); // only first level
}
}
}
doCheckLonelyValidatorAnnotation(nestedField, deriveFieldType(nestedField, genericMap)); // recursive call
}
}
示例4: doCheckJsonBeanValidator
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected void doCheckJsonBeanValidator(Class<?> jsonBeanType, Map<String, Class<?>> genericMap) {
final Deque<String> pathDeque = new LinkedList<String>(); // recycled
final Set<Class<?>> mismatchedCheckedTypeSet = DfCollectionUtil.newHashSet(jsonBeanType);
final Set<Class<?>> lonelyCheckedTypeSet = DfCollectionUtil.newHashSet(jsonBeanType);
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(jsonBeanType);
final int pdSide = beanDesc.getPropertyDescSize();
for (int i = 0; i < pdSide; i++) {
final PropertyDesc pd = beanDesc.getPropertyDesc(i);
final Field field = pd.getField();
if (field != null) {
pathDeque.clear(); // to recycle
checkJsonBeanMismatchedValidatorAnnotation(jsonBeanType, pd, field, pathDeque, mismatchedCheckedTypeSet, genericMap);
pathDeque.clear(); // to recycle
checkJsonBeanLonelyValidatorAnnotation(jsonBeanType, pd, field, pathDeque, lonelyCheckedTypeSet, genericMap);
}
}
}
示例5: nativeFindByCode
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
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;
}
示例6: nativeFindMeta
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
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;
}
示例7: resolveBeanExpression
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
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();
}
示例8: appendInterType
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
public void appendInterType(ComponentDef componentDef) {
Class<?> componentClass = componentDef.getComponentClass();
if (componentClass == null) {
return;
}
BeanDesc beanDesc = BeanDescFactory.getBeanDesc(componentClass);
if (!beanDesc.hasField(INTER_TYPE)) {
return;
}
String interTypeStr = (String) beanDesc.getFieldValue(INTER_TYPE, null);
String[] array = LdiStringUtil.split(interTypeStr, ", ");
for (int i = 0; i < array.length; i += 2) {
String interTypeName = array[i].trim();
appendInterType(componentDef, interTypeName);
}
}
示例9: evaluate
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
@Override
public Object evaluate(Map<String, ? extends Object> context, LaContainer container, Class<?> conversionType) {
final MethodInterceptor interceptor = MethodInterceptor.class.cast(container.getComponent(getInterceptorName(annotation)));
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(interceptor.getClass());
for (final Method method : annotation.annotationType().getMethods()) {
if (method.isBridge() || method.isSynthetic()) {
continue;
}
final String propertyName = method.getName();
if ("pointcut".equals(propertyName) || !beanDesc.hasPropertyDesc(propertyName)) {
continue;
}
final PropertyDesc propertyDesc = beanDesc.getPropertyDesc(propertyName);
if (!propertyDesc.isWritable()) {
continue;
}
propertyDesc.setValue(interceptor, LdiMethodUtil.invoke(method, annotation, null));
}
return interceptor;
}
示例10: invoke
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
public Object invoke(MethodInvocation invocation) throws Throwable {
if (targetName == null) {
throw new EmptyRuntimeException("targetName");
}
final Method method = invocation.getMethod();
if (!LdiMethodUtil.isAbstract(method)) {
return invocation.proceed();
}
String methodName = method.getName();
if (methodNameMap.containsKey(methodName)) {
methodName = (String) methodNameMap.get(methodName);
}
final Object target = container.getComponent(targetName);
if (beanDesc == null) {
beanDesc = BeanDescFactory.getBeanDesc(target.getClass());
}
if (!beanDesc.hasMethod(methodName)) {
throw new BeanMethodNotFoundException(getTargetClass(invocation), methodName, invocation.getArguments());
}
return beanDesc.invoke(target, methodName, invocation.getArguments());
}
示例11: isMapValueStringArray
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected boolean isMapValueStringArray(Object parentBean, String parentName) {
if (parentBean == null) {
return false;
}
final PropertyDesc pd = BeanDescFactory.getBeanDesc(parentBean.getClass()).getPropertyDesc(parentName);
final Class<?> valueClassOfMap = pd.getValueClassOfMap();
return valueClassOfMap != null && valueClassOfMap.isArray() && String[].class.isAssignableFrom(valueClassOfMap);
}
示例12: prepareJsonParameterDebugChallengeList
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected List<JsonDebugChallenge> prepareJsonParameterDebugChallengeList(Map<String, Object> retryMap, Class<?> beanType, String json,
Integer elementIndex) {
if (retryMap.isEmpty()) {
return Collections.emptyList();
}
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(beanType);
final int fieldSize = beanDesc.getFieldSize();
final List<JsonDebugChallenge> challengeList = new ArrayList<JsonDebugChallenge>(fieldSize);
for (int i = 0; i < fieldSize; i++) {
final Field field = beanDesc.getField(i);
final JsonDebugChallenge challenge = createJsonDebugChallenge(retryMap, field.getName(), field.getType(), elementIndex);
challengeList.add(challenge);
}
return Collections.unmodifiableList(challengeList);
}
示例13: setIndexedProperty
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected void setIndexedProperty(Object bean, String name, int[] indexes, Object value, FormMappingOption option) { // e.g. sea[0]
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());
if (!beanDesc.hasPropertyDesc(name)) {
return;
}
final PropertyDesc pd = beanDesc.getPropertyDesc(name);
if (!pd.isWritable()) {
return;
}
if (value.getClass().isArray() && Array.getLength(value) > 0) {
value = Array.get(value, 0);
}
final Class<?> propertyType = pd.getPropertyType();
if (propertyType.isArray()) {
Object array = pd.getValue(bean);
final Class<?> elementType = getArrayElementType(propertyType, indexes.length);
if (array == null) {
int[] newIndexes = new int[indexes.length];
newIndexes[0] = indexes[0] + 1;
array = Array.newInstance(elementType, newIndexes);
}
array = expand(array, indexes, elementType);
pd.setValue(bean, array);
setArrayValue(array, indexes, value);
} else { // e.g. List, ImmutableList, MutableList
// process of your collections should be first because MutableList is java.util.List
final Optional<FormYourCollectionResource> yourCollection = findListableYourCollection(pd, option);
if (yourCollection.isPresent()) { // e.g. ImmutableList, MutableList
doSetIndexedPropertyListable(bean, name, indexes, value, beanDesc, pd, option, newList -> {
@SuppressWarnings("unchecked")
final List<Object> filtered = (List<Object>) yourCollection.get().getYourCollectionCreator().apply(newList);
return filtered;
});
} else if (List.class.isAssignableFrom(propertyType)) {
doSetIndexedPropertyListable(bean, name, indexes, value, beanDesc, pd, option, Function.identity());
} else {
throwIndexedPropertyNotListArrayException(beanDesc, pd);
}
}
}
示例14: prepareIndexedProperty
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected Object prepareIndexedProperty(Object bean, String name, int[] indexes, FormMappingOption option) {
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());
if (!beanDesc.hasPropertyDesc(name)) {
return null;
}
final PropertyDesc pd = beanDesc.getPropertyDesc(name);
if (!pd.isReadable()) {
return null;
}
final Class<?> propertyType = pd.getPropertyType();
if (propertyType.isArray()) {
Object array = pd.getValue(bean);
final Class<?> elementType = getArrayElementType(propertyType, indexes.length);
if (array == null) {
int[] newIndexes = new int[indexes.length];
newIndexes[0] = indexes[0] + 1;
array = Array.newInstance(elementType, newIndexes);
}
array = expand(array, indexes, elementType);
pd.setValue(bean, array);
return getArrayValue(array, indexes, elementType);
} else { // e.g. List, ImmutableList, MutableList
// process of your collections should be first because MutableList is java.util.List
final Optional<FormYourCollectionResource> yourCollection = findListableYourCollection(pd, option);
if (yourCollection.isPresent()) { // e.g. ImmutableList, MutableList
return doPrepareIndexedPropertyListable(bean, name, indexes, beanDesc, pd, option, newList -> {
@SuppressWarnings("unchecked")
final List<Object> filtered = (List<Object>) yourCollection.get().getYourCollectionCreator().apply(newList);
return filtered;
});
} else if (List.class.isAssignableFrom(propertyType)) { // e.g. List (can be ArrayList)
return doPrepareIndexedPropertyListable(bean, name, indexes, beanDesc, pd, option, Function.identity());
} else { // cannot treat it
throwIndexedPropertyNotListArrayException(beanDesc, pd);
return null; // unreachable
}
}
}
示例15: setupProperties
import org.lastaflute.di.helper.beans.factory.BeanDescFactory; //导入依赖的package包/类
protected Map<String, ActionFormProperty> setupProperties(Class<?> formType) {
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(formType);
final int propertyDescSize = beanDesc.getPropertyDescSize();
final Map<String, ActionFormProperty> map = new HashMap<String, ActionFormProperty>(propertyDescSize);
for (int i = 0; i < propertyDescSize; i++) {
final PropertyDesc pd = beanDesc.getPropertyDesc(i);
if (pd.isReadable()) {
final ActionFormProperty property = newActionFormProperty(pd);
addProperty(map, property);
}
}
return map;
}