EntityHelper.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:jspresso-ce 作者:
/**
 * Gets entity sub contracts.
 *
 * @param entityContract
 *     the entity contract
 * @return the entity sub contracts
 */
@SuppressWarnings("unchecked")
public static Collection<Class<IEntity>> getEntitySubContracts(Class<IEntity> entityContract) {
  Collection<Class<IEntity>> entitySubContracts = new HashSet<>();
  ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false) {
    @Override
    protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
      // Allow to return superclasses
      return beanDefinition.getMetadata().isIndependent();
    }
  };
  provider.addIncludeFilter(new AssignableTypeFilter(entityContract));
  Set<BeanDefinition> components = provider.findCandidateComponents(entityContract.getPackage().getName().replace('.',
      '/'));
  for (BeanDefinition component : components) {
    try {
      Class<IEntity> entitySubContract = (Class<IEntity>) Class.forName(component.getBeanClassName());
      if (entitySubContract != entityContract) {
        entitySubContracts.add(entitySubContract);
      }
    } catch (ClassNotFoundException e) {
      // Ignore
    }
  }
  return entitySubContracts;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号