当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionUtils.doWithFields方法代码示例

本文整理汇总了Java中org.springframework.util.ReflectionUtils.doWithFields方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.doWithFields方法的具体用法?Java ReflectionUtils.doWithFields怎么用?Java ReflectionUtils.doWithFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.ReflectionUtils的用法示例。


在下文中一共展示了ReflectionUtils.doWithFields方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: injectServicesViaAnnotatedFields

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void injectServicesViaAnnotatedFields(final Object bean, final String beanName) {
	ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {
		public void doWith(Field field) {
			ServiceReference s = AnnotationUtils.getAnnotation(field, ServiceReference.class);
			if (s != null && !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) {
				try {
					if (logger.isDebugEnabled())
						logger.debug("Processing annotation [" + s + "] for [" + field + "] on bean [" + beanName + "]");
					if (!field.isAccessible()) {
						field.setAccessible(true);
					}
					ReflectionUtils.setField(field, bean, getServiceImporter(s, field.getType(), beanName).getObject());
				}
				catch (Exception e) {
					throw new IllegalArgumentException("Error processing service annotation", e);
				}
			}
		}
	});
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:ServiceReferenceInjectionBeanPostProcessor.java

示例2: DirectFieldAccessor

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * Create a new DirectFieldAccessor for the given target object.
 * @param target the target object to access
 */
public DirectFieldAccessor(final Object target) {
	Assert.notNull(target, "Target object must not be null");
	this.target = target;
	ReflectionUtils.doWithFields(this.target.getClass(), new ReflectionUtils.FieldCallback() {
		@Override
		public void doWith(Field field) {
			if (fieldMap.containsKey(field.getName())) {
				// ignore superclass declarations of fields already found in a subclass
			}
			else {
				fieldMap.put(field.getName(), field);
			}
		}
	});
	this.typeConverterDelegate = new TypeConverterDelegate(this, target);
	registerDefaultEditors();
	setExtractOldValueForEditor(true);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:DirectFieldAccessor.java

示例3: getJpaHeaders

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * Return JPA managed properties.
 * 
 * @param <T>
 *            Bean type.
 * @param beanType
 *            the bean type.
 * @return the headers built from given type.
 */
public <T> String[] getJpaHeaders(final Class<T> beanType) {
	// Build descriptor list respecting the declaration order
	final OrderedFieldCallback fieldCallBack = new OrderedFieldCallback();
	ReflectionUtils.doWithFields(beanType, fieldCallBack);
	final List<String> orderedDescriptors = fieldCallBack.descriptorsOrdered;

	// Now filter the properties
	final List<String> descriptorsFiltered = new ArrayList<>();
	final ManagedType<T> managedType = transactionManager.getEntityManagerFactory().getMetamodel().managedType(beanType);
	for (final String propertyDescriptor : orderedDescriptors) {
		for (final Attribute<?, ?> attribute : managedType.getAttributes()) {
			// Match only basic attributes
			if (attribute instanceof SingularAttribute<?, ?> && propertyDescriptor.equals(attribute.getName())) {
				descriptorsFiltered.add(attribute.getName());
				break;
			}
		}
	}

	// Initialize the CSV reader
	return descriptorsFiltered.toArray(new String[descriptorsFiltered.size()]);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:32,代码来源:CsvForJpa.java

示例4: JdbcEntityInformation

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public JdbcEntityInformation(Class<T> domainClass) {

    super(domainClass);
    className = domainClass.getName();

    ReflectionUtils.doWithFields(domainClass, new FieldCallback() {
        public void doWith(Field field) {
            if (field.isAnnotationPresent(ID_ANNOTATION)) {
                JdbcEntityInformation.this.idFields.add(field);
                return;
            }
        }
    });

    if (domainClass.isAnnotationPresent(ID_CLASS_ANNOTATION)) {
        idType = (Class<ID>) domainClass.getAnnotation(ID_CLASS_ANNOTATION).value();
        Assert.notNull(idType, "@IdClass must have a valid class");
        getIdStrategy = new GetIdCompound();
    } else {
        assertUniqueId(
                "There must be one and only one field annotated with @Id unless you annotate the class with @IdClass");
        idType = (Class<ID>) idFields.get(0).getType();
        idFields.get(0).setAccessible(true);
        getIdStrategy = new GetIdSingleKey();
    }
    entityType = calculateEntityType(domainClass, idFields);

}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:30,代码来源:JdbcEntityInformation.java

示例5: postProcessBeforeInitialization

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
  // 扫描所有field,处理扩展的field标注
  ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {
    public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
      processConsumerField(bean, field);
    }
  });

  return bean;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:12,代码来源:RpcReferenceProcessor.java

示例6: mapVarsToFields

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private <T> void mapVarsToFields(Object command, ExternalTask<?> externalTask, Class<T> taskClass, T task) {
    ReflectionUtils.doWithFields(taskClass, field -> {
        if (!externalTask.getFields().containsKey(field.getName())) {
            return;
        }

        Field commandField = externalTask.getFields().get(field.getName());
        JavaUtils.setFieldWithoutCheckedException(
                field
                , task
                , () -> JavaUtils.getFieldWithoutCheckedException(commandField, command)
        );
    });
}
 
开发者ID:EsikAntony,项目名称:camunda-task-dispatcher,代码行数:15,代码来源:ExternalTaskManagerImpl.java

示例7: testToCommand

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test
public void testToCommand() {
    manager.init();

    LockedExternalTaskDto task = EnhancedRandom.random(LockedExternalTaskDto.class);
    JavaUtils.setFieldWithoutCheckedException(
            ReflectionUtils.findField(LockedExternalTaskDto.class, "topicName")
            , task
            , Command.TASK_NAME
    );
    String stringVar = "value";
    String otherVar = "other value";

    task.getVariables().put("stringVar", VariableValueDto.fromTypedValue(new PrimitiveTypeValueImpl.StringValueImpl(stringVar)));
    task.getVariables().put("otherVar", VariableValueDto.fromTypedValue(new PrimitiveTypeValueImpl.StringValueImpl(otherVar)));

    Object object = manager.toCommand(task);
    Assert.assertNotNull(object);
    Assert.assertTrue(object instanceof Command);

    Command command = (Command) object;
    Assert.assertEquals(stringVar, command.getStringVar());
    Assert.assertEquals(otherVar, command.getAnotherStringVar());

    ReflectionUtils.doWithFields(LockedExternalTaskDto.class, field -> {
        if (field.getName().equals("variables")) {
            return;
        }

        Field commandField = ReflectionUtils.findField(Command.class, field.getName());
        Assert.assertNotNull("No field with name: " + field.getName(), commandField);
        Assert.assertEquals(
                JavaUtils.getFieldWithoutCheckedException(field, task)
                , JavaUtils.getFieldWithoutCheckedException(commandField, command)
        );
    });
}
 
开发者ID:EsikAntony,项目名称:camunda-task-dispatcher,代码行数:38,代码来源:ExternalTaskManagerImplTest.java

示例8: testToCompleteTask

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test
public void testToCompleteTask() {
    manager.init();

    Pair<String, CompleteExternalTaskDto> pair = manager.toCompleteTask(null, new Object());
    Assert.assertNull(pair);

    pair = manager.toCompleteTask(Command.TASK_NAME, null);
    Assert.assertNull(pair);

    Command command = EnhancedRandom.random(Command.class);
    pair = manager.toCompleteTask(Command.TASK_NAME, command);

    Assert.assertNotNull(pair);
    Assert.assertNotNull(pair.getKey());
    Assert.assertEquals(command.getId(), pair.getKey());

    Assert.assertNotNull(pair.getValue());
    Assert.assertEquals(command.getWorkerId(), pair.getValue().getWorkerId());

    Assert.assertNotNull(pair.getValue().getVariables());
    Assert.assertFalse(pair.getValue().getVariables().isEmpty());

    final Pair<String, CompleteExternalTaskDto> finalPair = pair;
    ReflectionUtils.doWithFields(Command.class, field -> {
        CamundaVar camundaVar = field.getAnnotation(CamundaVar.class);
        if (camundaVar == null) {
            return;
        }

        Assert.assertTrue(finalPair.getValue().getVariables().containsKey(ExternalTaskManager.getVarName(field, camundaVar)));
    });
}
 
开发者ID:EsikAntony,项目名称:camunda-task-dispatcher,代码行数:34,代码来源:ExternalTaskManagerImplTest.java

示例9: fail

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public void fail(final Object task) {
    List<String> errors = new LinkedList<>();
    ReflectionUtils.doWithFields(task.getClass(), field -> {
        ErrorMessage errorMessage = field.getAnnotation(ErrorMessage.class);
        if (errorMessage != null) {
            errors.add((String) JavaUtils.getFieldWithoutCheckedException(field, task));
        }
    });

    fail(task, Strings.emptyToNull(errors.stream().collect(Collectors.joining("; "))));
}
 
开发者ID:EsikAntony,项目名称:camunda-task-dispatcher,代码行数:13,代码来源:JmsExternalTaskCompleter.java

示例10: parseFields

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public <T> List<FieldDescriptor> parseFields(Class<T> clazz) {
    int[] index = new int[]{1};
    List<FieldDescriptor> descriptors = new ArrayList<>();
    ReflectionUtils.doWithFields(clazz, field -> {
        ReflectionUtils.makeAccessible(field);
        Class<?> type = field.getType();
        ValueTransformer transformer = identifyTransformer(type);
        descriptors.add(new FieldDescriptor(index[0]++, field.getName(), transformer));
    }, field -> {
        int modifiers = field.getModifiers();
        return !Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers);
    });
    return addDefaultDescriptors(descriptors);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:15,代码来源:FieldDescriptorHelper.java

示例11: isHelpRequested

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private boolean isHelpRequested(Object command) {
    AtomicBoolean result = new AtomicBoolean(false);
    ReflectionUtils.doWithFields(AopUtils.getTargetClass(command),
            f -> {
                f.setAccessible(true);
                if (f.getBoolean(command)) {
                    result.set(true);
                }
            },
            f -> f.isAnnotationPresent(Option.class) && f.getAnnotation(Option.class).help());
    return result.get();
}
 
开发者ID:kakawait,项目名称:picocli-spring-boot-starter,代码行数:13,代码来源:PicocliCommandLineRunner.java

示例12: checkFields

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void checkFields(Object bean) {
  ReflectionUtils.doWithFields(bean.getClass(), new ExecutorFieldCallback(bean, omegaContext));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:4,代码来源:CompensableAnnotationProcessor.java


注:本文中的org.springframework.util.ReflectionUtils.doWithFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。