You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/04/30 09:04:01 UTC
svn commit: r398289 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/conversation/
core/src/main/tld/ core/src/main/tld/entities/
examples/src/main/webapp/WEB-INF/
Author: imario
Date: Sun Apr 30 00:03:59 2006
New Revision: 398289
URL: http://svn.apache.org/viewcvs?rev=398289&view=rev
Log:
conversation: start with persistence stuff
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml (with props)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/StartConversationTag.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java Sun Apr 30 00:03:59 2006
@@ -29,13 +29,17 @@
public class Conversation
{
private final String name;
+ private final boolean persistence;
+
+ private PersistenceManager persistenceManager;
// private final Map beans = new TreeMap(new ValueBindingKey());
private final Map beans = new TreeMap();
- protected Conversation(String name)
+ protected Conversation(String name, boolean persistence)
{
this.name = name;
+ this.persistence = persistence;
}
/**
@@ -72,7 +76,7 @@
* <li>free all beans</li>
* </ul>
*/
- public void endConversation()
+ public void endConversation(boolean regularEnd)
{
Iterator iterBeans = beans.values().iterator();
while (iterBeans.hasNext())
@@ -84,6 +88,18 @@
}
}
beans.clear();
+
+ if (isPersistence())
+ {
+ if (regularEnd)
+ {
+ getPersistenceManager().commit();
+ }
+ else
+ {
+ getPersistenceManager().rollback();
+ }
+ }
}
/**
@@ -104,5 +120,23 @@
public Object getBean(String name)
{
return beans.get(name);
+ }
+
+ /**
+ * returns true if this conversation hold the persistence manager (aka EntityManager)
+ */
+ public boolean isPersistence()
+ {
+ return persistence;
+ }
+
+ public PersistenceManager getPersistenceManager()
+ {
+ if (persistenceManager == null)
+ {
+ persistenceManager = ConversationManager.getInstance().createPersistenceManager();
+ }
+
+ return persistenceManager;
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java Sun Apr 30 00:03:59 2006
@@ -16,15 +16,9 @@
package org.apache.myfaces.custom.conversation;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.TreeMap;
-import java.util.TreeSet;
-
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
/**
* The ConversationContext handles all conversations within the current context
@@ -46,18 +40,18 @@
* All nested conversations (if any) are closed if the conversation already existed.
* @param name
*/
- public void startConversation(String name)
+ public void startConversation(String name, boolean persistence)
{
Conversation conversation = (Conversation) conversations.get(name);
if (conversation == null)
{
- conversation = new Conversation(name);
+ conversation = new Conversation(name, persistence);
conversations.put(name, conversation);
conversationStack.add(conversation);
}
else
{
- endNestedConversations(conversation);
+ endNestedConversations(conversation, false);
}
currentConversation = conversation;
}
@@ -65,7 +59,7 @@
/**
* Ends all conversations nested under conversation
*/
- protected void endNestedConversations(Conversation conversation)
+ protected void endNestedConversations(Conversation conversation, boolean regularEnd)
{
while (conversationStack.size()>0)
{
@@ -76,16 +70,16 @@
return;
}
- endConversation((Conversation) conversationStack.remove(index));
+ endConversation((Conversation) conversationStack.remove(index), regularEnd);
}
}
/**
* End the given conversation
*/
- protected void endConversation(Conversation conversation)
+ protected void endConversation(Conversation conversation, boolean regularEnd)
{
- conversation.endConversation();
+ conversation.endConversation(regularEnd);
}
/**
@@ -100,7 +94,7 @@
while (conversationStack.size()>0)
{
Conversation dependingConversation = (Conversation) conversationStack.remove(conversationStack.size()-1);
- endConversation(dependingConversation);
+ endConversation(dependingConversation, false);
if (dependingConversation == conversation)
{
if (conversationStack.size() > 0)
@@ -110,6 +104,7 @@
return;
}
}
+ endConversation(conversation, true);
}
}
@@ -160,6 +155,9 @@
}
*/
+ /**
+ * find the bean named <code>name</code> in the conversation stack
+ */
public Object findBean(String name)
{
for (int i = conversationStack.size(); i>0; i--)
@@ -168,6 +166,23 @@
if (conversation.hasBean(name))
{
return conversation.getBean(name);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * find the persistence manager in the conversation stack
+ */
+ public PersistenceManager getPersistenceManager()
+ {
+ for (int i = conversationStack.size(); i>0; i--)
+ {
+ Conversation conversation = (Conversation) conversationStack.get(i-1);
+ if (conversation.isPersistence())
+ {
+ return conversation.getPersistenceManager();
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java Sun Apr 30 00:03:59 2006
@@ -20,8 +20,11 @@
import java.util.List;
import java.util.Map;
+import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
/**
* The manager will deal with the various contexts in the current session.
* A new context will be created if the current window has none associated.
@@ -30,12 +33,16 @@
*/
public class ConversationManager
{
- private final static String CONVERSATION_MANAGER_KEY = "org.apache.myfaces.ConversationManager";
public final static String CONVERSATION_CONTEXT_PARAM = "conversationContext";
+
+ private final static String INIT_PERSISTENCE_MANAGER_FACOTRY = "org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY";
+ private final static String CONVERSATION_MANAGER_KEY = "org.apache.myfaces.ConversationManager";
private final static String CONVERSATION_CONTEXT_REQ = "org.apache.myfaces.ConversationManager.conversationContext";
private static long NEXT_CONVERSATION_CONTEXT = 1;
+ private PersistenceManagerFactory persistenceManagerFactory;
+
private final Map conversationContexts = new HashMap();
private final List registeredEndConversations = new ArrayList(10);
@@ -140,11 +147,11 @@
* Start a conversation
* @see ConversationContext#startConversation(String)
*/
- public void startConversation(String name)
+ public void startConversation(String name, boolean persistence)
{
Long conversationContextId = getConversationContextId();
ConversationContext conversationContext = getOrCreateConversationContext(conversationContextId);
- conversationContext.startConversation(name);
+ conversationContext.startConversation(name, persistence);
}
/**
@@ -235,5 +242,62 @@
return context.getExternalContext().getRequestMap().containsKey(CONVERSATION_CONTEXT_REQ) ||
context.getExternalContext().getRequestParameterMap().containsKey(CONVERSATION_CONTEXT_PARAM);
+ }
+
+ /**
+ * get the persistence manager responsible for the current conversation
+ */
+ public PersistenceManager getPersistenceManager()
+ {
+ ConversationContext conversationContext = getConversationContext();
+ if (conversationContext == null)
+ {
+ return null;
+ }
+
+ return conversationContext.getPersistenceManager();
+ }
+
+ /**
+ * create a persistence manager
+ */
+ protected PersistenceManager createPersistenceManager()
+ {
+ return getPersistenceManagerFactory().create();
+ }
+
+ /**
+ * Get the persistenceManagerFactory.<br />
+ * The factory can be configured in your web.xml using the init parameter named
+ * <code>org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY</code>
+ */
+ protected PersistenceManagerFactory getPersistenceManagerFactory()
+ {
+ if (persistenceManagerFactory == null)
+ {
+ String persistenceManagerFactoryName = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("INIT_PERSISTENCE_MANAGER_FACOTRY");
+ if (persistenceManagerFactoryName == null)
+ {
+ throw new IllegalArgumentException("please configure '" + INIT_PERSISTENCE_MANAGER_FACOTRY + "' in your web.xml");
+ }
+ try
+ {
+ persistenceManagerFactory = (PersistenceManagerFactory) ClassUtils.classForName(persistenceManagerFactoryName).newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new FacesException("error creating persistenceManagerFactory named: " + persistenceManagerFactoryName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new FacesException("error creating persistenceManagerFactory named: " + persistenceManagerFactoryName, e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new FacesException("error creating persistenceManagerFactory named: " + persistenceManagerFactoryName, e);
+ }
+ }
+
+ return persistenceManagerFactory;
}
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java?rev=398289&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java Sun Apr 30 00:03:59 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.myfaces.custom.conversation;
+
+/**
+ * the interface to help the conversation framework to deal with your persistence manager (EntityManager)
+ *
+ * @author imario@apache.org
+ */
+public interface PersistenceManager
+{
+ public void commit();
+ public void rollback();
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java?rev=398289&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java Sun Apr 30 00:03:59 2006
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.myfaces.custom.conversation;
+
+/**
+ * Implement and configure this factory to create your PersistenceManager if required.<br />
+ * The factory can be configured in your web.xml using the init parameter named
+ * <code>org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY</code>
+ *
+ * @author imario@apache.org
+ */
+public interface PersistenceManagerFactory
+{
+ public PersistenceManager create();
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManagerFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/StartConversationTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/StartConversationTag.java?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/StartConversationTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/StartConversationTag.java Sun Apr 30 00:03:59 2006
@@ -24,6 +24,8 @@
*/
public class StartConversationTag extends AbstractConversationTag
{
+ private String persistence;
+
public String getComponentType()
{
return UIStartConversation.COMPONENT_TYPE;
@@ -32,5 +34,17 @@
protected void setProperties(UIComponent component)
{
super.setProperties(component);
+
+ setBooleanProperty(component, "persistence", persistence);
}
+
+ public String getPersistence()
+ {
+ return persistence;
+ }
+
+ public void setPersistence(String persistence)
+ {
+ this.persistence = persistence;
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java Sun Apr 30 00:03:59 2006
@@ -20,6 +20,7 @@
import javax.faces.application.ViewHandler;
import javax.faces.component.UICommand;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import javax.faces.el.VariableResolver;
/**
@@ -33,13 +34,26 @@
private final static String CONVERSATION_SYSTEM_SETUP = "org.apache.myfaces.ConversationSystemSetup";
private boolean inited;
+ private Boolean persistence;
public static class ConversationStartAction extends AbstractConversationActionListener
{
+ private boolean persistence;
+
public void doConversationAction(AbstractConversationComponent abstractConversationComponent)
{
ConversationManager conversationManager = ConversationManager.getInstance();
- conversationManager.startConversation(getConversationName());
+ conversationManager.startConversation(getConversationName(), isPersistence());
+ }
+
+ public boolean isPersistence()
+ {
+ return persistence;
+ }
+
+ public void setPersistence(boolean persistence)
+ {
+ this.persistence = persistence;
}
}
@@ -56,6 +70,7 @@
{
ConversationStartAction actionListener = new ConversationStartAction();
actionListener.setConversationName(getName());
+ actionListener.setPersistence(toBoolean(getPersistence()));
command.addActionListener(actionListener);
inited = true;
}
@@ -63,10 +78,19 @@
else
{
ConversationManager conversationManager = ConversationManager.getInstance();
- conversationManager.startConversation(getName());
+ conversationManager.startConversation(getName(), toBoolean(getPersistence()));
}
}
+ protected boolean toBoolean(Boolean bool)
+ {
+ if (bool != null)
+ {
+ return bool.booleanValue();
+ }
+ return false;
+ }
+
protected void setupConversationSystem(FacesContext context)
{
if (Boolean.TRUE.equals(context.getExternalContext().getApplicationMap().get(CONVERSATION_SYSTEM_SETUP)))
@@ -88,6 +112,7 @@
Object[] states = (Object[]) state;
super.restoreState(context, states[0]);
inited = ((Boolean) states[1]).booleanValue();
+ persistence = (Boolean) states[2];
}
public Object saveState(FacesContext context)
@@ -95,7 +120,23 @@
return new Object[]
{
super.saveState(context),
- inited?Boolean.TRUE:Boolean.FALSE
+ inited?Boolean.TRUE:Boolean.FALSE,
+ persistence
};
+ }
+
+ public Boolean getPersistence()
+ {
+ if (persistence != null)
+ {
+ return persistence;
+ }
+ ValueBinding vb = getValueBinding("persistence");
+ return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
+ }
+
+ public void setPersistence(Boolean persistence)
+ {
+ this.persistence = persistence;
}
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml?rev=398289&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml Sun Apr 30 00:03:59 2006
@@ -0,0 +1,8 @@
+<attribute>
+ <name>persistence</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ true|false - if this conversation requires a persistence manager. Default: false
+ </description>
+</attribute>
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/start_conversation_attributes.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Sun Apr 30 00:03:59 2006
@@ -1053,6 +1053,7 @@
<body-content>JSP</body-content>
<description>Starts a new conversation</description>
+ &start_conversation_attributes;
&standard_conversation_attributes;
</tag>
<tag>
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml?rev=398289&r1=398288&r2=398289&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml Sun Apr 30 00:03:59 2006
@@ -566,7 +566,7 @@
<managed-bean-class>org.apache.myfaces.examples.conversation.ConvData</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
-
+
<!-- navigation rules -->
<navigation-rule>
<navigation-case>