leap.core.BeanFactory.getBeansWithDefinition()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(79)

本文整理了Java中leap.core.BeanFactory.getBeansWithDefinition()方法的一些代码示例,展示了BeanFactory.getBeansWithDefinition()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanFactory.getBeansWithDefinition()方法的具体详情如下:
包路径:leap.core.BeanFactory
类名称:BeanFactory
方法名:getBeansWithDefinition

BeanFactory.getBeansWithDefinition介绍

[英]Returns an immutable Map all the beans's instances and definitions for the given type.

The key of returned Map is the instance of bean.

The value of returned Map is the definition of bean.
[中]返回给定类型的所有bean实例和定义的不可变映射。
返回映射的键是bean的实例。
返回的Map的值是bean的定义。

代码示例

代码示例来源:origin: org.leapframework/leap-core

protected void loadListenerRegistrations(AppContext context){
  for(Entry<EventListenerRegistration,BeanDefinition> entry : context.getBeanFactory().getBeansWithDefinition(EventListenerRegistration.class).entrySet()){
    register(entry.getKey(),entry.getValue());
  }
}

代码示例来源:origin: org.leapframework/leap-core

protected void loadEventRegistrations(AppContext context){
  for(Entry<EventRegistration,BeanDefinition> entry : context.getBeanFactory().getBeansWithDefinition(EventRegistration.class).entrySet()){
    register(entry.getKey(),entry.getValue());
  }
}

代码示例来源:origin: org.leapframework/leap-core

@Override
public <T> Map<T, BeanDefinition> getBeansWithDefinition(Class<? super T> type) throws BeanException {
  Map<T, BeanDefinition> beans = null != externalFactory ? externalFactory.getBeansWithDefinition(type) : null;
  
  if(null == beans){
    return beanContainer.getBeansWithDefinition(type);
  }else{
    Map<T, BeanDefinition> map = new LinkedHashMap<T, BeanDefinition>(beans);
    
    
    Map<T, BeanDefinition> internalBeans = beanContainer.getBeansWithDefinition(type);
    
    for(Entry<T,BeanDefinition> namedBean : internalBeans.entrySet()){
      if(!map.containsKey(namedBean.getKey())){
        map.put(namedBean.getKey(), namedBean.getValue());
      }
    }
    return map;
  }
}

代码示例来源:origin: org.leapframework/leap-core

protected void loadVariableFromBeans(BeanFactory beanFactory){
  Map<Variable,BeanDefinition> beans = beanFactory.getBeansWithDefinition(Variable.class);
  beans.putAll(beanFactory.getBeansWithDefinition(VariableWithContext.class));
  
  for(Entry<Variable,BeanDefinition> entry : beans.entrySet()){
    BeanDefinition bd = entry.getValue();
    
    String name = bd.getName();
    if(!Strings.isEmpty(name)){
      Variable variable = entry.getKey();
      Scope    scope    = null;
      
      if(variable instanceof ScopedVariable){
        scope = ((ScopedVariable) variable).getScope();
      }
      
      if(null == scope){
        scope = defaultScope;
      }
      
      variables.put(name.toLowerCase(), new VariableDefinition(bd.getSource(), name, scope, variable));
    }
  }
}

代码示例来源:origin: org.leapframework/leap-core

protected void loadVariableFromProviders(BeanFactory beanFactory){
  for(Entry<VariableProvider, BeanDefinition> providerEntry : beanFactory.getBeansWithDefinition(VariableProvider.class).entrySet()){
    
    VariableProvider provider = providerEntry.getKey();
    Object           source   = providerEntry.getValue().getSource();
    
    List<VariableDefinition> providedVariables = provider.getVariables();
    
    for(VariableDefinition providerVd : providedVariables){
      String key = providerVd.getName().toLowerCase();
      VariableDefinition vd = variables.get(key);
      
      if(null != vd){
        throw new VariableConfigException("Found duplicated variable '" + vd.getName() + "', check source [" + vd.getScope() + "," + source + "]");
      }
      
      variables.put(key,providerVd);
    }
  }
}

代码示例来源:origin: org.leapframework/leap-orm

beanFactory.getBeansWithDefinition(OrmContext.class).forEach((oc, bd) -> {
  registry.registerContext(oc, bd.isPrimary());

相关文章