Search in sources :

Example 1 with StringBeanIdentifier

use of org.jboss.weld.bean.StringBeanIdentifier in project core by weld.

the class BeanIdentifierIndexTest method testGetIndex.

@Test
public void testGetIndex() {
    BeanIdentifierIndex index = new BeanIdentifierIndex();
    index.build(Collections.<Bean<?>>emptySet());
    try {
        index.getIndex(null);
    } catch (IllegalArgumentException e) {
    // Expected
    }
    assertNull(index.getIndex(new StringBeanIdentifier("foo")));
}
Also used : StringBeanIdentifier(org.jboss.weld.bean.StringBeanIdentifier) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) Test(org.junit.Test)

Example 2 with StringBeanIdentifier

use of org.jboss.weld.bean.StringBeanIdentifier in project core by weld.

the class ContextualStoreImpl method putIfAbsent.

/**
 * Add a contextual (if not already present) to the store, and return it's
 * id. If the contextual is passivation capable, it's id will be used,
 * otherwise an id will be generated
 *
 * @param contextual the contextual to add
 * @return the current id for the contextual
 */
@SuppressFBWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED", justification = "Using non-standard semantics of putIfAbsent")
public BeanIdentifier putIfAbsent(Contextual<?> contextual) {
    if (contextual instanceof CommonBean<?>) {
        // this is a Bean<?> created by Weld
        CommonBean<?> bean = (CommonBean<?>) contextual;
        passivationCapableContextuals.putIfAbsent(bean.getIdentifier(), contextual);
        return bean.getIdentifier();
    }
    if (contextual instanceof PassivationCapable) {
        // this is an extension-provided passivation capable bean
        PassivationCapable passivationCapable = (PassivationCapable) contextual;
        String id = passivationCapable.getId();
        BeanIdentifier identifier = new StringBeanIdentifier(id);
        passivationCapableContextuals.putIfAbsent(identifier, contextual);
        return identifier;
    } else {
        BeanIdentifier id = contextuals.get(contextual);
        if (id != null) {
            return id;
        } else {
            synchronized (contextual) {
                id = contextuals.get(contextual);
                if (id == null) {
                    id = new StringBeanIdentifier(new StringBuilder().append(GENERATED_ID_PREFIX).append(idGenerator.incrementAndGet()).toString());
                    contextuals.put(contextual, id);
                    contextualsInverse.put(id, contextual);
                }
                return id;
            }
        }
    }
}
Also used : PassivationCapable(javax.enterprise.inject.spi.PassivationCapable) StringBeanIdentifier(org.jboss.weld.bean.StringBeanIdentifier) BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier) CommonBean(org.jboss.weld.bean.CommonBean) StringBeanIdentifier(org.jboss.weld.bean.StringBeanIdentifier) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

StringBeanIdentifier (org.jboss.weld.bean.StringBeanIdentifier)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 PassivationCapable (javax.enterprise.inject.spi.PassivationCapable)1 CommonBean (org.jboss.weld.bean.CommonBean)1 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)1 BeanIdentifier (org.jboss.weld.serialization.spi.BeanIdentifier)1 Test (org.junit.Test)1