Package javax.enterprise.context.spi

Examples of javax.enterprise.context.spi.Context


     */
    public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> creationalContext)
    {
        Asserts.assertNotNull(bean, "bean parameter can not be null");

        Context context = null;
        Object instance = null;

        if (bean instanceof SerializableBean)
        {
            bean = ((SerializableBean)bean).getBean();
        }
       
        //Check type if bean type is given
        if(beanType != null)
        {
            if(!ResolutionUtil.checkBeanTypeAssignableToGivenType(bean.getTypes(), beanType, bean instanceof NewBean))
            {
                throw new IllegalArgumentException("Given bean type : " + beanType + " is not applicable for the bean instance : " + bean);
            }
           
        }
       
        if(!(creationalContext instanceof CreationalContextImpl))
        {
            creationalContext = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext, bean);
        }       
       
               
        //Scope is normal
        if (webBeansContext.getWebBeansUtil().isScopeTypeNormal(bean.getScope()))
        {
            instance = getEjbOrJmsProxyReference(bean, beanType,creationalContext);
           
            if(instance != null)
            {
                return instance;
            }
           
            instance = cacheProxies.get(bean);

            if (instance == null)
            {
                //Create Managed Bean Proxy
                instance = webBeansContext.getJavassistProxyFactory().createNormalScopedBeanProxy((AbstractOwbBean<?>)bean,creationalContext);

                //Cached instance
                cacheProxies.put(bean, instance);
            }

        }
        //Create Pseudo-Scope Bean Instance
        else
        {
            //Get bean context
            context = getContext(bean.getScope());
           
            //Get instance for ejb or jms
            instance = getEjbOrJmsProxyReference(bean, beanType, creationalContext);
           
            if(instance != null)
            {
                return instance;
            }
           
            //Get dependent from DependentContex that create contextual instance
            instance = context.get((Bean<Object>)bean, (CreationalContext<Object>)creationalContext);
        }
       
        return instance;
    }
View Full Code Here


        PersonalDataBean pdb = getInstance(PersonalDataBean.class);
        pdb.business();
       
        // first we need to actually create a few instances

        Context sessionContext = webBeansContext.getContextFactory().getStandardContext(SessionScoped.class);
        Assert.assertNotNull(sessionContext);
        byte[] ba = serializeObject(sessionContext);
        Assert.assertNotNull(ba);
        Context sessContext2 = (Context) deSerializeObject(ba);
        Assert.assertNotNull(sessContext2);
    }
View Full Code Here

        if (logger.isLoggable(Level.FINE))
        {
            logger.log(Level.FINE, ">lazyStartSessionContext");
        }

        Context webContext = null;
        Context context = getCurrentContext(RequestScoped.class);
        if (context instanceof ServletRequestContext)
        {
            ServletRequestContext requestContext = (ServletRequestContext) context;
            HttpServletRequest servletRequest = requestContext.getServletRequest();
            if (null != servletRequest)
View Full Code Here

      if (scope.equals(Unknown.class) || scope.equals(Singleton.class) || scope.equals(Dependent.class)
         || scope.equals(ApplicationScoped.class))
      {
         return create();
      }
      final Context ctx = manager.getContext(scope);
      if (ctx == null)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace("The scope {} is unknown, thus we will create the component {} out of a scope context.",
View Full Code Here

        final BeanContext beanContext = newContext.getBeanContext();

        final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
        final ContextsService contextsService = webBeansContext.getContextsService();

        final Context requestContext = contextsService.getCurrentContext(RequestScoped.class);

        if (requestContext == null) {
            contextsService.startContext(RequestScoped.class, null);
            newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
        }
View Full Code Here

    private BeanManager beanManager;

    @Test
    public void test() throws Exception {

        final Context appContext = beanManager.getContext(ApplicationScoped.class);



        final Green green = createAndMutate(appContext, Green.class);
View Full Code Here

        }

        @Override
        public Object call() throws Exception {

            Context ctx = contextService.getCurrentContext(scopeType);

            if (ctx == null) {
                contextService.startContext(scopeType, null);
            } else if (!ctx.isActive()) {
                contextService.activateContext(scopeType);
            }

            try {
                return callable.call();
View Full Code Here

  /**
   * Convenience for Resin.
   */
  public <T> T findReference(Bean<T> bean)
  {
    Context context = getContext(bean.getScope());
   
    if (context != null)
      return context.get(bean);
    else
      return null;
  }
View Full Code Here

    if (bean instanceof AbstractBean<?>)
      ownerManager = ((AbstractBean<?>) bean).getBeanManager();
    else
      ownerManager = this;

    Context context = ownerManager.getContextImpl(scopeType);

    /*
    if (context == null)
      return null;
      */
 
View Full Code Here

    if (bean instanceof AbstractBean<?>)
      ownerManager = ((AbstractBean<?>) bean).getBeanManager();
    else
      ownerManager = this;

    Context context = ownerManager.getContextImpl(scopeType);

    if (context == null)
      throw new InjectionException(L.l("Bean has an unknown scope '{0}' for bean {1}",
                                       scopeType, bean));
View Full Code Here

TOP

Related Classes of javax.enterprise.context.spi.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.