Codota Logo
BeanManager.getContext
Code IndexAdd Codota to your IDE (free)

How to use
getContext
method
in
javax.enterprise.inject.spi.BeanManager

Best Java code snippets using javax.enterprise.inject.spi.BeanManager.getContext (Showing top 20 results out of 369)

  • Common ways to obtain BeanManager
private void myMethod () {
BeanManager b =
  • Codota IconCDI.current().getBeanManager()
  • Codota IconBeanManagerProvider.getInstance().getBeanManager()
  • Codota IconWeldContainer container;container.getBeanManager()
  • Smart code suggestions by Codota
}
origin: camunda/camunda-bpm-platform

protected Class< ? extends ScopedAssociation> getBroadestActiveContext() {
 for (Class< ? extends ScopedAssociation> scopeType : getAvailableScopedAssociationClasses()) {
  Annotation scopeAnnotation = scopeType.getAnnotations().length > 0 ? scopeType.getAnnotations()[0] : null;
  if (scopeAnnotation == null || !beanManager.isScope(scopeAnnotation.annotationType())) {
   throw new ProcessEngineException("ScopedAssociation must carry exactly one annotation and it must be a @Scope annotation");
  }
  try {
   beanManager.getContext(scopeAnnotation.annotationType());
   return scopeType;
  } catch (ContextNotActiveException e) {
   log.finest("Context " + scopeAnnotation.annotationType() + " not active.");
  }
 }
 throw new ProcessEngineException("Could not determine an active context to associate the current process instance / task instance with.");
}
origin: stackoverflow.com

@Inject BeanManager beanManager;  //inject bean manager into the class
 void someMethod() {
   Set<Bean<E>> possibleBeans = beanManager.getBeans("aBeanName");
   Bean<E> bean = (Bean<E>) beanManager.resolve(possibleBeans);        
   E instance = beanManager.getContext(bean.getScope()).get(bean, beanManager.createCreationalContext(bean));
 }
origin: org.omnifaces/omnifaces

/**
 * @see Beans#isActive(Class)
 */
public static <S extends Annotation> boolean isActive(BeanManager beanManager, Class<S> scope) {
  try {
    return beanManager.getContext(scope).isActive();
  }
  catch (Exception ignore) {
    logger.log(FINEST, "Ignoring thrown exception; given scope is very unlikely active anyway.", ignore);
    return false;
  }
}
origin: omnifaces/omnifaces

/**
 * @see Beans#isActive(Class)
 */
public static <S extends Annotation> boolean isActive(BeanManager beanManager, Class<S> scope) {
  try {
    return beanManager.getContext(scope).isActive();
  }
  catch (Exception ignore) {
    logger.log(FINEST, "Ignoring thrown exception; given scope is very unlikely active anyway.", ignore);
    return false;
  }
}
origin: org.jboss.jsr299.tck/jsr299-tck-impl

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
 if (!jsr299Manager.getContext(ApplicationScoped.class).isActive())
 {
   throw new ServletException("Application context is not active");
 }
 else
 {
   chain.doFilter(request, response);
 }
}
origin: org.jboss.jsr299.tck/jsr299-tck-impl

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
 if (!jsr299Manager.getContext(SessionScoped.class).isActive())
 {
   throw new ServletException("Session is not active");
 }
 else
 {
   super.service(req, resp);
 }
}
origin: org.jboss.jsr299.tck/jsr299-tck-impl

@PostConstruct
public void construct()
{
 try
 {
   dependentContextActiveDuringPostConstruct = beanManager.getContext(Dependent.class).isActive();
 }
 catch (ContextNotActiveException e) 
 {
   dependentContextActiveDuringPostConstruct = false;
 }
}
origin: org.jboss.cdi.tck/cdi-tck-impl

public void testConversationContextIsActive() {
  try {
    result = beanManager.getContext(ConversationScoped.class).isActive();
  } catch (ContextNotActiveException expected) {
    result = false;
  }
}
origin: thorntail/thorntail

@Override
public void activate(Archive archive, String asName, boolean implicit) {
  try {
    beanManager.getContext(delegate.getScope());
    LOGGER.info("Command context already active");
  } catch (ContextNotActiveException e) {
    // Only activate the context if not already active
    delegate.activate(archive, asName, implicit);
    isActivator = true;
  }
}
origin: org.glassfish/javax.faces

/**
 * Returns true if given scope is active in current context.
 */
public static <S extends Annotation> boolean isScopeActive(Class<S> scope) {
  BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());
  try {
    Context context = beanManager.getContext(scope);
    return context.isActive();
  } catch (ContextNotActiveException ignore) {
    return false;
  }
}
origin: org.glassfish/jakarta.faces

/**
 * Returns true if given scope is active in current context.
 */
public static <S extends Annotation> boolean isScopeActive(Class<S> scope) {
  BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());
  try {
    Context context = beanManager.getContext(scope);
    return context.isActive();
  } catch (ContextNotActiveException ignore) {
    return false;
  }
}
origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertion(section = AFTER_BEAN_DISCOVERY, id = "f")
public void testAddContext() {
  Context context = getCurrentManager().getContext(SuperScoped.class);
  assertNotNull(context);
  assertTrue(context.isActive());
  assertTrue(context instanceof SuperContext);
}
origin: org.wildfly.swarm/container

@Override
public void activate(Archive archive, String asName, boolean implicit) {
  try {
    beanManager.getContext(delegate.getScope());
    LOGGER.info("Command context already active");
  } catch (ContextNotActiveException e) {
    // Only activate the context if not already active
    delegate.activate(archive, asName, implicit);
    isActivator = true;
  }
}
origin: io.thorntail/container

@Override
public void activate(Archive archive, String asName, boolean implicit) {
  try {
    beanManager.getContext(delegate.getScope());
    LOGGER.info("Command context already active");
  } catch (ContextNotActiveException e) {
    // Only activate the context if not already active
    delegate.activate(archive, asName, implicit);
    isActivator = true;
  }
}
origin: com.sun.jersey/jersey-servlet

public static CDIExtension getCdiExtensionInstance(BeanManager beanManager) {
  Bean<?> bean = getBean(beanManager, CDIExtension.class);
  if  (bean == null) {
    return null;
  }
  return ( CDIExtension ) beanManager.getContext( ApplicationScoped.class ).get( bean );
}
origin: br.gov.frameworkdemoiselle/demoiselle-jsf

@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
  if (event instanceof PreDestroyViewMapEvent) {
    final Context context = Beans.getBeanManager().getContext(ViewScoped.class);
    if (context instanceof FacesViewContextImpl) {
      ((FacesViewContextImpl) context).clearView();
    }
  }
}
origin: com.sun.jersey/jersey-bundle

public static CDIExtension getCdiExtensionInstance(BeanManager beanManager) {
  Bean<?> bean = getBean(beanManager, CDIExtension.class);
  if  (bean == null) {
    return null;
  }
  return ( CDIExtension ) beanManager.getContext( ApplicationScoped.class ).get( bean );
}
origin: org.apache.myfaces.core/myfaces-impl

public static <T> T getInstance(BeanManager beanManager, Bean<T> bean, boolean create)
{
  Context context = beanManager.getContext(bean.getScope());
  if (create)
  {
    return context.get(bean, beanManager.createCreationalContext(bean));
  }
  else
  {
    return context.get(bean);
  }
}

origin: org.jboss.jsr299.tck/jsr299-tck-impl

@Test(groups = { "contexts" }, expectedExceptions = { ContextNotActiveException.class })
@SpecAssertion(section = "6.2", id = "m")
public void testInvokingGetOnInactiveContextFails()
{
 Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
 assert sessionContext.isActive();
 setContextInactive(sessionContext);
 Contextual<MySessionBean> mySessionBean = getBeans(MySessionBean.class).iterator().next();
 sessionContext.get(mySessionBean);
}
origin: org.jboss.cdi.tck/cdi-tck-impl

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = CONTEXT, id = "t")
public void testNothingHappensIfNoInstanceToDestroy(ApplicationScopedComponent application) {
  Bean<?> bean = getUniqueBean(ApplicationScopedComponent.class);
  AlterableContext context = (AlterableContext) getCurrentManager().getContext(bean.getScope());
  AbstractComponent.reset();
  application.setValue("value");
  context.destroy(bean);
  assertTrue(AbstractComponent.isDestroyed());
  context.destroy(bean); // make sure subsequent calls do not raise exception
  context.destroy(bean);
}
javax.enterprise.inject.spiBeanManagergetContext

Javadoc

Obtains an active javax.enterprise.context.spi.Context for the given javax.enterprise.context .

Popular methods of BeanManager

  • createCreationalContext
    Obtain an instance of a javax.enterprise.context.spi.CreationalContext for the given javax.enterpris
  • getBeans
    Return the set of beans which have the given required type and qualifiers and are available for inje
  • getReference
    Obtains a contextual reference for a certain Bean and a certain bean type of the bean.
  • resolve
    Apply the ambiguous dependency resolution rules to a set of Bean. Note that when called during invoc
  • createAnnotatedType
    Obtain an AnnotatedType that may be used to read the annotations of the given class or interface.
  • createInjectionTarget
    Obtains an InjectionTarget for the given AnnotatedType. The container ignores the annotations and t
  • fireEvent
    Fire an event and notify observers. This method is deprecated from CDI 2.0 and #getEvent()) should b
  • isNormalScope
    Test the given annotation type to determine if it is a javax.enterprise.context.
  • isQualifier
    Test the given annotation type to determine if it is a javax.inject.Qualifier.
  • isStereotype
    Test the given annotation type to determine if it is a javax.enterprise.inject.Stereotype.
  • getInjectableReference
    Obtains an injectable reference for a certain InjectionPoint.
  • getELResolver
    Returns a javax.el.ELResolver that resolves beans by EL name.
  • getInjectableReference,
  • getELResolver,
  • isScope,
  • getPassivationCapableBean,
  • getInjectionTargetFactory,
  • getStereotypeDefinition,
  • wrapExpressionFactory,
  • getExtension,
  • isInterceptorBinding

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSystemService (Context)
  • getSharedPreferences (Context)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Kernel (java.awt.image)
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • IsNull (org.hamcrest.core)
    Is the value null?
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now