• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FieldCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parseResouce

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
private void parseResouce(){
ReflectionUtils.doWithFields(clz, new FieldCallback(){
    @Override
    public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
	if(field.getAnnotation(Id.class) != null){
	    idField = field;
	    return;
	}
	Index index = null;
	if(null != (index = field.getAnnotation(Index.class))){
	    if(index.unique()){
		uniqueIndexFields.add(field);
	    }else{
		nonUniqueIndexFields.add(field);
	    }
	}
	Autowired auto = field.getAnnotation(Autowired.class);
	if(null != auto && auto.required()){
	    autowiredFields.add(field);
	}
    }
});
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:24,代码来源:ResourceDefinition.java


示例2: parseByObject

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
/**
 * 解析对象为Model
 * 自定义filter
 * @param obj
 * @param parseSuper 是否解析父类
 * @return
 */
public static List<Model> parseByObject(Object obj,boolean parseSuper,FieldFilter ff){
	List<Model> list = new ArrayList<>();
	if (obj==null) {
		return list;
	}
	//解析Field
	FieldCallback fc = new FieldCallback() {
		@Override
		public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
			if (ff != null && !ff.matches(field)) {
				return;
			}
			Model m = parseByField(obj, field);
			if (m!=null) {
				list.add(m);
			}
		}
	};
	if (parseSuper) {
		ReflectionUtil.doWithFields(obj.getClass(),fc);
	}else{
		ReflectionUtil.doWithLocalFields(obj.getClass(),fc);
	}
	return list;
}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:33,代码来源:MyBatisUtil.java


示例3: determineDeleteInBatchSupported

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
private boolean determineDeleteInBatchSupported(final Class<?> genericType) {
    final MutableBoolean deleteInBatchSupported = new MutableBoolean(true);
    Reflections.doWithFields(genericType, new FieldCallback() {
        @Override
        public void doWith(final Field field) {
            if (!deleteInBatchSupported.getValue()) {
                return;
            } else if (Reflections.getAnnotation(field, ElementCollection.class) != null) {
                //element collections are mapped as separate tables, thus the values would cause a foreign key constraint violation
                deleteInBatchSupported.setValue(false);
            } else if (Reflections.getAnnotation(field, Embedded.class) != null) {
                //check embedded types for the same constraints
                if (!determineDeleteInBatchSupported(field.getType())) {
                    deleteInBatchSupported.setValue(false);
                }
            }
        }
    });
    return deleteInBatchSupported.getValue();
}
 
开发者ID:subes,项目名称:invesdwin-context-persistence,代码行数:21,代码来源:ACustomIdDao.java


示例4: postProcessAfterInitialization

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName)
		throws BeansException {

	// 处理DbCacheService属性
	ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
		public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
			processDbCacheService(bean, beanName, field);
		}
	});

	// 处理EntityLoadEventListener接口
	processEntityLoadEventListener(bean);

	// 处理IndexChangeListener接口
	processIndexChangeListener(bean);

	return super.postProcessAfterInitialization(bean, beanName);
}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:20,代码来源:DbCacheInjectProcessor.java


示例5: DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
public DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl(final Class<T> domainType) {
	super(domainType);
	this.hashAndRangeKeyMethodExtractor = new DynamoDBHashAndRangeKeyMethodExtractorImpl<T>(getJavaType());
	ReflectionUtils.doWithMethods(domainType, new MethodCallback() {
		public void doWith(Method method) {
			if (method.getAnnotation(DynamoDBHashKey.class) != null) {
				String setterMethodName = toSetterMethodNameFromAccessorMethod(method);
				if (setterMethodName != null) {
					hashKeySetterMethod = ReflectionUtils.findMethod(domainType, setterMethodName, method.getReturnType());
				}
			}
		}
	});
	ReflectionUtils.doWithFields(domainType, new FieldCallback() {
		public void doWith(Field field) {
			if (field.getAnnotation(DynamoDBHashKey.class) != null) {
				
				hashKeyField = ReflectionUtils.findField(domainType, field.getName());
				
			}
		}
	});
	Assert.isTrue(hashKeySetterMethod != null || hashKeyField != null, "Unable to find hash key field or setter method on " + domainType + "!");
	Assert.isTrue(hashKeySetterMethod == null || hashKeyField == null, "Found both hash key field and setter method on " + domainType + "!");

}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:27,代码来源:DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java


示例6: JdbcEntityInformation

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的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


示例7: postProcessPropertyValues

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
@Override
public PropertyValues postProcessPropertyValues(PropertyValues pvs,
		PropertyDescriptor[] pds, final Object bean, String beanName)
				throws BeansException {
	ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {

		@Override
		public void doWith(Field field)
				throws IllegalArgumentException, IllegalAccessException {
			postProcessField(bean, field);
		}

	});
	return pvs;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:MockitoPostProcessor.java


示例8: parse

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
public void parse(Class<?> source) {
	parseElement(source);
	ReflectionUtils.doWithFields(source, new FieldCallback() {

		@Override
		public void doWith(Field field)
				throws IllegalArgumentException, IllegalAccessException {
			parseElement(field);
		}

	});
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:DefinitionsParser.java


示例9: initFields

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
public void initFields(final Object testInstance,
		final ObjectFactory<M> marshaller) {
	Assert.notNull(testInstance, "TestInstance must not be null");
	Assert.notNull(marshaller, "Marshaller must not be null");
	ReflectionUtils.doWithFields(testInstance.getClass(), new FieldCallback() {

		@Override
		public void doWith(Field field)
				throws IllegalArgumentException, IllegalAccessException {
			doWithField(field, testInstance, marshaller);
		}

	});
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:AbstractJsonMarshalTester.java


示例10: dumpObjectFieldsSizeEstimate

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
public static String dumpObjectFieldsSizeEstimate(final Serializable o) {
	final StringBuilder sb = new StringBuilder();
	sb.append(o).append(": ").append(estimateObjectSize(o)).append("\n");
	ReflectionUtils.doWithFields(o.getClass(), new FieldCallback() {
		@Override
		public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
			int mods = field.getModifiers();
			if (Modifier.isStatic(mods) && Modifier.isFinal(mods)) {
				return;
			}
			if (Modifier.isTransient(mods)) {
				return;
			}
			field.setAccessible(true);
			sb.append("\n");
			DebugUtil.indentDebugDump(sb, 1);
			sb.append(field.getName());
			if (Modifier.isStatic(mods)) {
				sb.append(" (static)");
			}
			sb.append(": ");
			Object value = field.get(o);
			if (value == null) {
				sb.append("null");
			} else if (value instanceof Serializable) {
				sb.append(estimateObjectSize((Serializable)value));
			} else {
				sb.append("non-serializable ("+value.getClass()+")");
			}
		}
	});
	return sb.toString();
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:34,代码来源:DebugUtil.java


示例11: map

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
/**
 * 
 * @param source
 * @param targetClass
 * @param depth
 * @param dtoToEntity
 * @return
 */
protected Object map(final Object source, final Class<?> targetClass,
        final int depth, final boolean dtoToEntity) {

    if (source == null) {
        return null;
    }
    try {
        final Object toRet = targetClass.newInstance();
        ReflectionUtils.doWithFields(source.getClass(),
                new FieldCallback() {

                    @Override
                    public void doWith(Field field)
                            throws IllegalAccessException {

                        mapField(source, targetClass, depth, dtoToEntity,
                                toRet, field);
                    }

                }, ReflectionUtils.COPYABLE_FIELDS);
        return toRet;
    } catch (Exception e) {
        throw new KarakuRuntimeException(
                String.format("Can't copy from %s to %s",
                        source.getClass(), targetClass), e);
    }
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:36,代码来源:ReflectionConverter.java


示例12: ResourceDefinition

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
/** 构造方法 */
public ResourceDefinition(Class<?> clz, FormatDefinition format) {
	this.clz = clz;
	this.format = format.getType();

	this.location = format.getLocation();
	ReflectionUtility.doWithDeclaredFields(clz, new FieldCallback() {
		@Override
		public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
			InjectDefinition definition = new InjectDefinition(field);
			injects.add(definition);
		}
	}, INJECT_FILTER);
}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:15,代码来源:ResourceDefinition.java


示例13: getIndexRangeKeyPropertyNames

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
@Override
public Set<String> getIndexRangeKeyPropertyNames() {
	final Set<String> propertyNames = new HashSet<String>();
	ReflectionUtils.doWithMethods(getJavaType(), new MethodCallback() {
		public void doWith(Method method) {
			if (method.getAnnotation(DynamoDBIndexRangeKey.class) != null) {
				if ((method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && method
						.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim().length() > 0)
						|| (method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && method
								.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames().length > 0)) {
					propertyNames.add(getPropertyNameForAccessorMethod(method));
				}
			}
		}
	});
	ReflectionUtils.doWithFields(getJavaType(), new FieldCallback() {
		public void doWith(Field field) {
			if (field.getAnnotation(DynamoDBIndexRangeKey.class) != null) {
				if ((field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && field
						.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim().length() > 0)
						|| (field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && field
								.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames().length > 0)) {
					propertyNames.add(getPropertyNameForField(field));
				}
			}
		}
	});
	return propertyNames;
}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:30,代码来源:DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java


示例14: FieldAndGetterReflectionEntityInformation

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
/**
 * Creates a new {@link FieldAndGetterReflectionEntityInformation} inspecting the
 * given domain class for a getter carrying the given annotation.
 * 
 * @param domainClass
 *            must not be {@literal null}.
 * @param annotation
 *            must not be {@literal null}.
 */
public FieldAndGetterReflectionEntityInformation(Class<T> domainClass, final Class<? extends Annotation> annotation) {

	super(domainClass);
	Assert.notNull(annotation);

	ReflectionUtils.doWithMethods(domainClass, new MethodCallback() {
		public void doWith(Method method) {
			if (method.getAnnotation(annotation) != null) {
				FieldAndGetterReflectionEntityInformation.this.method = method;
				return;
			}
		}
	});
	
	if (method == null)
	{
		ReflectionUtils.doWithFields(domainClass, new FieldCallback() {
			public void doWith(Field field) {
				if (field.getAnnotation(annotation) != null) {
					FieldAndGetterReflectionEntityInformation.this.field = field;
					return;
				}
			}
		});
	}

	Assert.isTrue(this.method != null || this.field != null, String.format("No field or method annotated with %s found!", annotation.toString()));
	Assert.isTrue(this.method == null || this.field == null, String.format("Both field and method annotated with %s found!", annotation.toString()));

	if (method != null)
	{
		ReflectionUtils.makeAccessible(method);
	}
}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:44,代码来源:FieldAndGetterReflectionEntityInformation.java


示例15: findAnnotatedElements

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
/**
 * Find annotated elements on types
 * @param ann annotation to search
 * @param clazz class to search on.
 * @return List with annotated elements
 */
public static List<AnnotatedElement> findAnnotatedElements(final Class<? extends Annotation> annotationType, Class<?> clazz) {
	final ArrayList<AnnotatedElement> elements = new ArrayList<AnnotatedElement>();
	// Lookup fields
	ReflectionUtils.doWithFields(clazz, new FieldCallback() {
		
		@Override
		public void doWith(Field field) throws IllegalArgumentException,
				IllegalAccessException {
			if (field.getAnnotation(annotationType) != null) {
				elements.add(field);
			}
			
		}
	});
	// Lookup methods
	ReflectionUtils.doWithMethods(clazz, new MethodCallback() {
		
		@Override
		public void doWith(Method method) throws IllegalArgumentException,
				IllegalAccessException {
			
			if (org.springframework.core.annotation.AnnotationUtils.getAnnotation(method, annotationType) != null)
				elements.add(method);
		}
	});
	
	return elements;
}
 
开发者ID:chelu,项目名称:jdal,代码行数:35,代码来源:AnnotatedElementAccessor.java


示例16: initializeKnownElements

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
@PostConstruct
protected void initializeKnownElements() {

    final Builder<String, List<WebElement>> builder = ImmutableMap.builder();

    ReflectionUtils.doWithFields(getClass(),
                                 new FieldCallback() {
                                     @Override
                                     @SuppressWarnings("unchecked")
                                     public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
                                         final String name = lowerCase(join(splitByCharacterTypeCamelCase(field.getName()), ' '));

                                         field.setAccessible(true);
                                         final Object value = ReflectionUtils.getField(field, GenericPage.this);

                                         if (value instanceof List) {
                                             builder.put(name, (List<WebElement>) value);
                                         }
                                         else if (value instanceof WebElement) {
                                             builder.put(name, Collections.singletonList((WebElement) value));
                                         }
                                     }
                                 },
                                 new AnnotationFieldFilter(FindBy.class));

    knownElements = builder.build();
}
 
开发者ID:martinlau,项目名称:unidle-old,代码行数:28,代码来源:GenericPage.java


示例17: createCacheConfig

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
private CacheConfig createCacheConfig(final Class<?> clz) {

		CacheConfig cacheConfig = CacheConfig.valueOf(clz);
		final Map<String, ValueGetter<?>> indexes = new HashMap<String, ValueGetter<?>>();

		// 解析注解
		ReflectionUtils.doWithFields(clz, new FieldCallback() {
			public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
				// 忽略静态属性和临时属性
				if (Modifier.isTransient(field.getModifiers())
						|| Modifier.isStatic(field.getModifiers())
						|| field.isAnnotationPresent(javax.persistence.Transient.class)) {
					return;
				}

				// 处理索引注解
				if (field.isAnnotationPresent(org.hibernate.annotations.Index.class) ||
						field.isAnnotationPresent(dbcache.anno.Index.class)) {

					org.hibernate.annotations.Index indexAno =
							field.getAnnotation(org.hibernate.annotations.Index.class);

					String indexName;
					if (indexAno != null) {
						indexName = indexAno.name();
					} else {
						dbcache.anno.Index indexAno1 = field.getAnnotation(dbcache.anno.Index.class);
						indexName = indexAno1.name();
					}

					try {
						indexes.put(indexName, AsmAccessHelper.createFieldGetter(field.getName(), clz, field));
					} catch (Exception e) {
						logger.error("获取实体配置出错:生成索引失败(" +
								clz.getName() + "." + field.getName() + ").");
						e.printStackTrace();
					}
				}

			}
		});

		cacheConfig.setIndexes(indexes);
		cacheConfig.setFieldCount(clz.getDeclaredFields().length);
		return cacheConfig;
	}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:47,代码来源:DbConfigFactoryImpl.java


示例18: intercept

import org.springframework.util.ReflectionUtils.FieldCallback; //导入依赖的package包/类
/**
 * Intercepta un bean especifico.
 * 
 * <p>
 * Intercepta todos los campos de un objeto, buscando aquellos que tengan
 * algún interceptor definido.
 * </p>
 * <p>
 * Reglas:
 * <ol>
 * <li>Si el item es un atributo normal, invocar a su respectivo
 * interceptor.
 * </p>
 * <li>Si es una colección, y tiene tiene la anotación {@link OneToMany}, y
 * su {@link CascadeType} es {@link CascadeType#ALL}, entonces se propaga la
 * intercepción a los miembros de la colección. </p>
 * 
 * @param op
 *            Operación actual.
 * @param bean
 *            objeto que esta siendo interceptado.
 */
public void intercept(@Nonnull final Operation op, final Object bean) {

	ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {

		@Override
		public void doWith(Field field) throws IllegalAccessException {

			InterceptorHandler.this.intercept(op, notNull(field), bean);
		}
	});
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:34,代码来源:InterceptorHandler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Pref类代码示例发布时间:2022-05-21
下一篇:
Java IllegalArgumentException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap