Package org.apache.myfaces.orchestra.conversation

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


     * end and restart a conversation
     */
    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

            }
            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

    public Object invoke(MethodInvocation methodInvocation) throws Throwable
    {
        PersistenceContext persistenceContext = null;

        Conversation conversation = Conversation.getCurrentInstance();
        if (conversation != null)
        {
            PersistenceContextCloser persistenceContextCloser = (PersistenceContextCloser) conversation.getAttribute(PERSISTENCE_CONTEXT_CONV_ATTRIBUTE);
            if (persistenceContextCloser != null)
            {
                persistenceContext = persistenceContextCloser.getPersistenceContext();
            }

            if (persistenceContext == null)
            {
                persistenceContext = persistenceContextFactory.create();

                conversation.setAttribute(PERSISTENCE_CONTEXT_CONV_ATTRIBUTE, new PersistenceContextCloser(persistenceContext));
            }
        }

        if (persistenceContext != null)
        {
View Full Code Here

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

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

        return conversation;
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

        real.setData("real");
        assertEquals("real", proxy.getData());

        // After invalidating the conversation and recreating the bean, the proxy and
        // real are no longer the same object.
        Conversation conv = ConversationManager.getInstance().getConversation(CONVERSATION_NAME);
        conv.invalidate();
        proxy.setData("proxy");
        assertEquals("real", real.getData());
        real.setData("real");
        assertEquals("proxy", proxy.getData());
    }
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

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.