javax.enterprise.inject.spi.Bean.getName()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(123)

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

Bean.getName介绍

[英]Returns name of a bean.
[中]返回bean的名称。

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public <T> T get(Contextual<T> contextual) {
 Bean<T> bean = (Bean<T>) contextual;
 String variableName = bean.getName();
 BusinessProcess businessProcess = getBusinessProcess();
 Object variable = businessProcess.getVariable(variableName);
 if (variable != null) {
  if (logger.isLoggable(Level.FINE)) {
   if(businessProcess.isAssociated()) {        
    logger.fine("Getting instance of bean '" + variableName + "' from Execution[" + businessProcess.getExecutionId() + "].");
   } else {
    logger.fine("Getting instance of bean '" + variableName + "' from transient bean store");
   }
  }
  return (T) variable;
 } else {
  return null;
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> arg1) {
 Bean<T> bean = (Bean<T>) contextual;
 String variableName = bean.getName();
 BusinessProcess businessProcess = getBusinessProcess();
 Object variable = businessProcess.getVariable(variableName);
 if (variable != null) {
  if (logger.isLoggable(Level.FINE)) {
   if(businessProcess.isAssociated()) {        
    logger.fine("Getting instance of bean '" + variableName + "' from Execution[" + businessProcess.getExecutionId() + "].");
   } else {
    logger.fine("Getting instance of bean '" + variableName + "' from transient bean store");
   }
  }
  return (T) variable;
 } else {
  if (logger.isLoggable(Level.FINE)) {
   if(businessProcess.isAssociated()) {        
    logger.fine("Creating instance of bean '" + variableName + "' in business process context representing Execution["
        + businessProcess.getExecutionId() + "].");
   } else {
    logger.fine("Creating instance of bean '" + variableName + "' in transient bean store");
   }
  }
  T beanInstance = bean.create(arg1);
  businessProcess.setVariable(variableName, beanInstance);
  return beanInstance;
 }
}

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl

@Override
public String getName()
{
  return bean.getName();
}

代码示例来源:origin: org.graniteds/granite-client-java-advanced

@Override
public List<String> allNames() {
  Set<Bean<?>> beans = beanManager.getBeans(Object.class);
  List<String> names = new ArrayList<String>();
  for (Bean<?> bean : beans) {
    if (bean.getName() != null)
      names.add(bean.getName());
  }
  return names;
}

代码示例来源:origin: weld/core

public Set<Bean<?>> apply(String from) {
  Set<Bean<?>> matchedBeans = new HashSet<Bean<?>>();
  for (Bean<?> bean : allBeans) {
    if ((bean.getName() == null && from == null) || (bean.getName() != null && bean.getName().equals(from))) {
      matchedBeans.add(bean);
    }
  }
  return Beans.removeDisabledBeans(matchedBeans, beanManager);
}

代码示例来源:origin: weld/core

public Set<Bean<?>> apply(String from) {
  Set<Bean<?>> matchedBeans = new HashSet<Bean<?>>();
  for (Bean<?> bean : allBeans) {
    if ((bean.getName() == null && from == null) || (bean.getName() != null && bean.getName().equals(from))) {
      matchedBeans.add(bean);
    }
  }
  return Beans.removeDisabledBeans(matchedBeans, beanManager);
}

代码示例来源:origin: org.jboss.weld.se/weld-se

public Set<Bean<?>> apply(String from) {
  Set<Bean<?>> matchedBeans = new HashSet<Bean<?>>();
  for (Bean<?> bean : allBeans) {
    if ((bean.getName() == null && from == null) || (bean.getName() != null && bean.getName().equals(from))) {
      matchedBeans.add(bean);
    }
  }
  return Beans.removeDisabledBeans(matchedBeans, beanManager);
}

代码示例来源:origin: net.oneandone/ejb-cdi-unit

@Override
public <T> T get(Contextual<T> cntxtl, CreationalContext<T> cc) {
  Bean<T> bean = (Bean<T>) cntxtl;
  if (viewMap.containsKey(bean.getName())) {
    return (T) viewMap.get(bean.getName());
  } else {
    T t = bean.create(cc);
    viewMap.put(bean.getName(), t);
    return t;
  }
}

代码示例来源:origin: org.pustefixframework/pustefix-cdi

private String createBeanName(Bean<?> bean, BeanDefinition beanDefinition, BeanDefinitionRegistry registry) {
  String beanName = bean.getName();
  if (beanName == null) {
    beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, registry);
  }
  return beanName;
}

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl

/**
 * Add a @Dependent scoped bean for later use in the <b>same</b> EL.
 * See spec section 6.4.3. <i>Dependent pseudo-scope and Unified EL</i>.
 * @param bean
 * @param dependent
 * @param creationalContext
 */
public void addDependent(Bean<?> bean, Object dependent, CreationalContext<?> creationalContext)
{
  dependentObjects.put(bean, new CreationalStore(dependent, creationalContext));
  beanNameToDependentBeanMapping.put(bean.getName(), bean);
}

代码示例来源:origin: org.apache.camel/camel-cdi

@Override
public <T> Map<String, T> findByTypeWithName(Class<T> type) {
  notNull(type, "type");
  logger.trace("Looking up named beans of type [{}]", type);
  return manager.getBeans(type, ANY).stream()
    .filter(bean -> bean.getName() != null)
    .collect(toMap(Bean::getName, bean -> getReference(manager, type, bean)));
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test(groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = DIRECT_AND_INDIRECT_SPECIALIZATION_EE, id = "k") })
public void testSpecializingBeanHasNameOfSpecializedBean() {
  String expectedName = "farmer";
  Set<Bean<?>> beans = getCurrentManager().getBeans(expectedName);
  assertEquals(beans.size(), 1);
  Bean<?> farmerBean = beans.iterator().next();
  assertEquals(farmerBean.getName(), expectedName);
  assertEquals(farmerBean.getBeanClass(), LazyFarmer.class);
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertion(section = BUILTIN_EVENT, id = "e")
public void testImplicitEventHasNoName() {
  assert getUniqueBean(STUDENT_REGISTERED_EVENT_LITERAL).getName() == null;
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertions({ @SpecAssertion(section = DIRECT_AND_INDIRECT_SPECIALIZATION, id = "k"), @SpecAssertion(section = SPECIALIZE_MANAGED_BEAN, id = "ab") })
public void testSpecializingBeanHasNameOfSpecializedBean() {
  String expectedName = "farmer";
  Set<Bean<?>> beans = getCurrentManager().getBeans(expectedName);
  assertEquals(beans.size(), 1);
  Bean<?> farmerBean = beans.iterator().next();
  assertEquals(farmerBean.getName(), expectedName);
  assertEquals(farmerBean.getBeanClass(), LazyFarmer.class);
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertions({ @SpecAssertion(section = DECLARING_MANAGED_BEAN, id = "bd"), @SpecAssertion(section = BEAN, id = "ba") })
public void testMultipleStereotypes() {
  Bean<ComplicatedTuna> tunaBean = getBeans(ComplicatedTuna.class).iterator().next();
  assertEquals(tunaBean.getScope(), RequestScoped.class);
  assertEquals(tunaBean.getName(), "complicatedTuna");
}

代码示例来源:origin: org.apache.camel/camel-cdi

/**
 * Generates a unique signature for {@link Bean}.
 */
static String createBeanId(Bean<?> bean) {
  return Stream.of(bean.getName(),
    bean.getScope().getName(),
    createAnnotationCollectionId(bean.getQualifiers()),
    createTypeCollectionId(bean.getTypes()))
    .filter(Objects::nonNull)
    .collect(joining(","));
}

代码示例来源:origin: org.jboss.weld.se/weld-se

public void validateBeanNames(BeanManagerImpl beanManager) {
  SetMultimap<String, Bean<?>> namedAccessibleBeans = SetMultimap.newSetMultimap();
  for (Bean<?> bean : beanManager.getAccessibleBeans()) {
    if (bean.getName() != null) {
      namedAccessibleBeans.put(bean.getName(), bean);
    }
  }
  List<String> accessibleNamespaces = beanManager.getAccessibleNamespaces();
  for (String name : namedAccessibleBeans.keySet()) {
    validateBeanName(name, namedAccessibleBeans, accessibleNamespaces, beanManager);
  }
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertions({ @SpecAssertion(section = DEFAULT_NAME, id = "fc") })
public void testDefaultNamed() {
  Bean<Tarantula> tarantulaBean = getUniqueBean(Tarantula.class, PET_LITERAL);
  assertEquals(tarantulaBean.getName(), "producedPetTarantula");
  // Any, Pet, Named
  assertTrue(annotationSetMatches(tarantulaBean.getQualifiers(), Any.Literal.INSTANCE, PET_LITERAL, NamedLiteral.of(
      "producedPetTarantula")));
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertions({ @SpecAssertion(section = STEREOTYPES, id = "a"), @SpecAssertion(section = NAMED_STEREOTYPE, id = "aa"),
    @SpecAssertion(section = NAMED_STEREOTYPE, id = "ab"), @SpecAssertion(section = DEFAULT_NAME, id = "e") })
public void testStereotypeDeclaringNamed() {
  Bean<FallowDeer> fallowBean = getUniqueBean(FallowDeer.class);
  assertEquals(fallowBean.getName(), "fallowDeer");
  assertTrue(annotationSetMatches(fallowBean.getQualifiers(), Any.Literal.INSTANCE, Default.Literal.INSTANCE));
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertion(section = NEW, id = "t")
public void testNewBeanHasNoStereotypes() {
  Bean<Fox> foxBean = getBeans(Fox.class).iterator().next();
  assert foxBean.getScope().equals(RequestScoped.class);
  assert foxBean.getName().equals("fox");
  Fox newFox1 = getContextualReference(FoxRun.class).getNewFox();
  Fox newFox2 = getContextualReference(FoxRun.class).getNewFox();
  newFox1.setDen(new Den("TheElms"));
  assert newFox2.getDen().getName() != "TheElms";
}

相关文章