Package org.apache.myfaces.orchestra.conversation

Examples of org.apache.myfaces.orchestra.conversation.Conversation


        if (log.isDebugEnabled())
        {
            log.debug("registerDestructionCallback for [" + name + "]");
        }

        Conversation conversation = getConversationForBean(name);
        if (conversation == null)
        {
            // This should never happen because this should only be called after the bean
            // instance has been created via scope.getBean, which always creates the
            // conversation for the bean.
            throw new IllegalStateException("No conversation for bean [" + name + "]");
        }
        if (runnable == null)
        {
            throw new IllegalStateException("No runnable object for bean [" + name + "]");
        }

        // Add an object to the conversation as a bean so that when the conversation is removed
        // its valueUnbound method will be called. However we never need to retrieve this object
        // from the context by name, so use a totally unique name as the bean key.
        conversation.setAttribute(
            runnable.getClass().getName() + "@" + System.identityHashCode(runnable),
            new ConversationBindingListener()
            {
                public void valueBound(ConversationBindingEvent event)
                {
View Full Code Here


        realBean.setData("real");
        assertEquals("real", scopedProxy.getData());

        // After invalidating the conversation and recreating the bean, the scopedProxy no longer refers
        // to the same object.
        Conversation conv = ConversationManager.getInstance().getConversation(CONVERSATION_NAME);
        conv.invalidate();
        assertEquals(null, scopedProxy.getData()); // this is a new object with reset data property
        SimpleBean newConvProxy = (SimpleBean) _SpringUtils.getTargetObject(scopedProxy);
        assertNotSame(convProxy, newConvProxy);

        // Writing via the proxy no longer touches the original realBean
View Full Code Here

            }
            return null;
        }

        AbstractSpringOrchestraScope scopeForThisBean = (AbstractSpringOrchestraScope) scopeObj;
        Conversation conversation = scopeForThisBean.getConversationForBean(beanName);
           
        if (conversation == null)
        {
            // In general, getConversationForBean is allowed to return null. However in this case
            // that is really not expected. Calling getBean for a bean in a scope only ever calls
View Full Code Here

        // The CurrentConversationAdvice object is expected to have already been executed,
        // so the "current conversation" is now the one associated with the bean being
        // invoked. But the persistence context currently configured is still unchanged,
        // so here we set up the context associated with this conversation (creating
        // it if this is the first call to this conversation).
        Conversation conversation = Conversation.getCurrentInstance();
        if (conversation != null)
        {
            PersistenceContextCloser persistenceContextCloser = (PersistenceContextCloser)
                conversation.getAttribute(PERSISTENCE_CONTEXT_CONV_ATTRIBUTE);
            if (persistenceContextCloser != null)
            {
                // This is not the first call to this conversation (the closer exists). So
                // retrieve the existing PersistenceContext for this conversation from the
                // closer object.
                persistenceContext = persistenceContextCloser.getPersistenceContext();
            }

            if (persistenceContext == null)
            {
                // This must be the first time any bean in this conversation has been
                // invoked. Therefore create a PersistenceContext. Also create a
                // PersistenceContextCloser and cache it in the conversation.
                persistenceContext = persistenceContextFactory.create();

                conversation.setAttribute(
                    PERSISTENCE_CONTEXT_CONV_ATTRIBUTE,
                    new PersistenceContextCloser(persistenceContext));
            }
        }
View Full Code Here

    /**
     * Implementation of ConversationFactory interface.
     */
    public Conversation createConversation(ConversationContext context, String name)
    {
        Conversation conversation = new Conversation(context, name, this);
        conversation.setBinder(new SpringConversationBinder(this, conversation));

        // invoke child scope classes so they can add any aspects they desire.
        initAspects(conversation);

        return conversation;
View Full Code Here

        boolean isDebug = log.isDebugEnabled();
        Iterator iterConversations = conversationManager.iterateConversations();
        while (iterConversations.hasNext())
        {
            Conversation conversation = (Conversation) iterConversations.next();
           
            // This conversation has "access" scope if it has an attached Aspect
            // of type ConversationAccessLifetimeAspect. All other conversations
            // are not access-scoped and should be ignored here.
            ConversationAccessLifetimeAspect aspect =
                (ConversationAccessLifetimeAspect)
                    conversation.getAspect(ConversationAccessLifetimeAspect.class);

            if (aspect != null)
            {
                if (aspect.isAccessed())
                {
                    if (isDebug)
                    {
                        log.debug(
                            "Not clearing accessed conversation " + conversation.getName()
                            + " after rendering view " + viewId);
                    }
                }
                else
                {
                    if (isDebug)
                    {
                        log.debug(
                            "Clearing access-scoped conversation " + conversation.getName()
                            + " after rendering view " + viewId);
                    }
                    conversation.invalidate();
                }
            }
        }
    }
View Full Code Here

     */
    public static void endAndRestartConversation(FacesContext context,
            String conversationName, Boolean restart, MethodBinding restartAction)
    {
        ConversationManager conversationManager = ConversationManager.getInstance();
        Conversation conversation = conversationManager.getConversation(conversationName);
        if (conversation != null)
        {
            conversation.invalidate();
        }

        if (restart != null && restart.booleanValue())
        {
            FrameworkAdapter.getCurrentInstance().getBean(conversationName);
View Full Code Here

        if (log.isDebugEnabled())
        {
            log.debug("getRealBean called for bean " + beanName);
        }
        ConversationManager manager = ConversationManager.getInstance();
        Conversation conversation;

        // check if we have a conversation
        synchronized(manager)
        {
            conversation = manager.getConversation(conversationName);
            if (conversation == null)
            {
                // Start the conversation. This eventually results in a
                // callback to the createConversation method on this class.
                conversation = manager.startConversation(conversationName, this);
            }
            else
            {
                // sanity check: verify that two beans with the different scopes
                // do not declare the same conversationName.
                assertSameScope(beanName, conversation);
            }
        }

        // get the conversation
        notifyAccessConversation(conversation);
        synchronized(conversation)
        {
            if (!conversation.hasAttribute(beanName))
            {
                Object value;

                // Set the magic property that forces all proxies of this bean to be CGLIB proxies.
                // It doesn't matter if we do this multiple times..
                BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(beanName);
                beanDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);

                try
                {
                    // Create the new bean. Note that this will run the
                    // OrchestraAdvisorBeanPostProcessor processor, which
                    // will cause the returned object to actually be a proxy
                    // with the CurrentConversationAdvice (at least) attached to it.
                    value = objectFactory.getObject();
                }
                catch(org.springframework.aop.framework.AopConfigException e)
                {
                    throw new IllegalStateException(
                        "Unable to create Orchestra proxy"
                            + " for bean " + beanName, e);
                }

                conversation.setAttribute(beanName, value);

                if (value instanceof ConversationAware)
                {
                    ((ConversationAware) value).setConversation(conversation);
                }
            }
        }

        // get the bean
        return conversation.getAttribute(beanName);
    }
View Full Code Here

     */
    protected Conversation getConversationForBean(String beanDefName)
    {
        ConversationManager manager = ConversationManager.getInstance();
        String conversationName = getConversationNameForBean(beanDefName);
        Conversation conversation = manager.getConversation(conversationName);
        return conversation;
    }
View Full Code Here

        if (log.isDebugEnabled())
        {
            log.debug("registerDestructionCallback for [" + name + "]");
        }

        Conversation conversation = getConversationForBean(name);
        if (conversation == null)
        {
            // This should never happen because this should only be called after the bean
            // instance has been created via scope.getBean, which always creates the
            // conversation for the bean.
            throw new IllegalStateException("No conversation for bean [" + name + "]");
        }
        if (runnable == null)
        {
            throw new IllegalStateException("No runnable object for bean [" + name + "]");
        }

        // Add an object to the conversation as a bean so that when the conversation is removed
        // its valueUnbound method will be called. However we never need to retrieve this object
        // from the context by name, so use a totally unique name as the bean key.
        conversation.setAttribute(
            runnable.getClass().getName() + "@" + System.identityHashCode(runnable),
            new ConversationBindingListener()
            {
                public void valueBound(ConversationBindingEvent event)
                {
View Full Code Here

TOP

Related Classes of org.apache.myfaces.orchestra.conversation.Conversation

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.