Package javax.enterprise.context.spi

Examples of javax.enterprise.context.spi.Context


    {
        Asserts.assertNotNull(scopeType, "scopeType paramter can not be null");

        List<Context> contexts = new ArrayList<Context>();
       
        Context standardContext = null;

        standardContext = ContextFactory.getStandardContext(scopeType);

        if(standardContext != null)
        {
            if(standardContext.isActive())
            {
                contexts.add(standardContext);  
            }
        }
       
View Full Code Here


     * {@inheritDoc}
     */
    @Override
    public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> creationalContext)
    {
        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 = CreationalContextFactory.getInstance().wrappedCreationalContext(creationalContext, bean);
        }       
       
       
        //Get bean context
        context = getContext(bean.getScope());
       
        //Scope is normal
        if (WebBeansUtil.isScopeTypeNormal(bean.getScope()))
        {
            instance = getEjbOrJmsProxyReference(bean, beanType,creationalContext);
           
            if(instance != null)
            {
                return instance;
            }           
            //Create Managed Bean Proxy
            instance = JavassistProxyFactory.createNormalScopedBeanProxy((AbstractOwbBean<?>)bean,creationalContext);
           
            //push this proxy instance into creational context
            CreationalContextImpl<Object> temp = (CreationalContextImpl<Object>)creationalContext;
            temp.setProxyInstance(instance);
        }
        //Create Pseudo-Scope Bean Instance
        else
        {
            instance = getEjbOrJmsProxyReference(bean, beanType, creationalContext);
           
            if(instance != null)
            {
                return instance;
            }
           
           
            instance = context.get((Bean<Object>)bean, (CreationalContext<Object>)creationalContext);    
            instance = JavassistProxyFactory.createDependentScopedBeanProxy((AbstractOwbBean<Object>)bean, instance, (CreationalContext<Object>)creationalContext);
        }
       
        return instance;
    }
View Full Code Here

    public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Exception
    {
        BeanManagerImpl beanManager = BeanManagerImpl.getManager();

        //Context of the bean
        Context webbeansContext = beanManager.getContext(bean.getScope());

        //Get bean instance from context
        Object webbeansInstance = webbeansContext.get((Contextual<Object>)this.bean, (CreationalContext<Object>) creationalContext);

        return super.invoke(webbeansInstance, method, proceed, arguments, (CreationalContextImpl<?>) creationalContext);
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    private void configureTarget(OwbBean<?> bean)
    {
        Context webbeansContext = BeanManagerImpl.getManager().getContext(bean.getScope());
       
        this.target = webbeansContext.get((Contextual<Object>)bean, (CreationalContext<Object>)this.creationalContext);       
       
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")   
    protected  T createInstance(CreationalContext<T> creationalContext)
    {
        Context context = BeanManagerImpl.getManager().getContext(getScope());
        Object actualInstance = context.get((Bean<Object>)this.wrappedBean, (CreationalContext<Object>)creationalContext);
        T proxy = (T)JavassistProxyFactory.createDependentScopedBeanProxy(this.wrappedBean, actualInstance, creationalContext);
       
        return proxy;       
    }
View Full Code Here

            }
            else
            {
                BeanManagerImpl manager = BeanManagerImpl.getManager();
                specializedComponent = (AbstractOwbBean<Object>)WebBeansUtil.getMostSpecializedBean(manager, baseComponent);       
                Context context = manager.getContext(specializedComponent.getScope());
               
                creationalContext = manager.createCreationalContext(specializedComponent);
               
                // on Reception.IF_EXISTS: ignore this bean if a the contextual instance doesn't already exist
                if (ifExist && context.get(specializedComponent) == null)
                {
                    return;
                }
               
                // on Reception.ALWAYS we must get a contextual reference if we didn't find the contextual instance
View Full Code Here

  public boolean activate() {
    if (!this.active){
      BeanManager beanManager = Beans.getBeanManager();
      if (beanManager!=null){
        try{
          Context ctx = beanManager.getContext(this.getScope());
          if (ctx!=null){
            getLogger().debug( getBundle().getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) );
          }
        }
        catch(ContextNotActiveException ce){
          this.active = true;
          getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) );
View Full Code Here

    public void sessionDestroyed(final HttpSessionEvent event) {
        ensureRequestScope();
    }

    private void ensureRequestScope() {
        final Context reqCtx = webBeansContext.getContextsService().getCurrentContext(RequestScoped.class);
        if (reqCtx == null || !webBeansContext.getContextsService().getCurrentContext(RequestScoped.class).isActive()) {
            requestInitialized(null);
            EndWebBeansListener.FAKE_REQUEST.set(true);
        }
    }
View Full Code Here

        if (logger.isDebugEnabled()) {
            logger.debug(">lazyStartSessionContext");
        }

        final Context webContext = null;
        final Context context = getCurrentContext(RequestScoped.class);
        if (context instanceof ServletRequestContext) {
            final ServletRequestContext requestContext = (ServletRequestContext) context;
            final HttpServletRequest servletRequest = requestContext.getServletRequest();
            if (null != servletRequest) { // this could be null if there is no active request context
                try {
View Full Code Here

                    instance = normalScopeProxyFactory.createProxyInstance(proxyClass, provider);
                }

                cacheProxies.put(inBean, instance);
            } else {
                final Context context = webBeansContext.getBeanManagerImpl().getContext(scopeClass);
                instance = context.get(bean, cc);
            }
            bean.setOwbProxy(instance);
            return instance;
        }
    }
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.