[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Sun Jul 8 17:13:36 EDT 2007
User: gavin
Date: 07/07/08 17:13:36
Modified: src/main/org/jboss/seam/core ConversationList.java
ConversationStack.java Manager.java
ResourceBundle.java
Log:
use @Factory instead of @Unwrap where that makes more sense
Revision Changes Path
1.19 +12 -16 jboss-seam/src/main/org/jboss/seam/core/ConversationList.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConversationList.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationList.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- ConversationList.java 22 Jun 2007 09:28:51 -0000 1.18
+++ ConversationList.java 8 Jul 2007 21:13:36 -0000 1.19
@@ -1,8 +1,8 @@
package org.jboss.seam.core;
+import static org.jboss.seam.ScopeType.PAGE;
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -10,42 +10,37 @@
import java.util.TreeSet;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.web.Session;
/**
- * Support for the conversation list
+ * Factory for the conversation list
*
* @author Gavin King
*/
- at Scope(ScopeType.PAGE)
- at Name("org.jboss.seam.core.conversationList")
+ at Scope(ScopeType.STATELESS)
+ at Name("org.jboss.seam.core.conversationListFactory")
@Install(precedence=BUILT_IN)
@BypassInterceptors
-public class ConversationList implements Serializable
+public class ConversationList
{
- private static final long serialVersionUID = -1515889862229134356L;
- private List<ConversationEntry> conversationEntryList;
-
- @Create
- public void createConversationEntryList()
+ protected List<ConversationEntry> createConversationEntryList()
{
ConversationEntries conversationEntries = ConversationEntries.getInstance();
if (conversationEntries==null)
{
- conversationEntryList = Collections.EMPTY_LIST;
+ return Collections.EMPTY_LIST;
}
else
{
Set<ConversationEntry> orderedEntries = new TreeSet<ConversationEntry>();
orderedEntries.addAll( conversationEntries.getConversationEntries() );
- conversationEntryList = new ArrayList<ConversationEntry>( conversationEntries.size() );
+ List<ConversationEntry> conversationEntryList = new ArrayList<ConversationEntry>( conversationEntries.size() );
for ( ConversationEntry entry: orderedEntries )
{
if ( entry.isDisplayable() && !Session.instance().isInvalid() )
@@ -53,12 +48,13 @@
conversationEntryList.add(entry);
}
}
+ return conversationEntryList;
}
}
- @Unwrap
+ @Factory(value="org.jboss.seam.core.conversationList", autoCreate=true, scope=PAGE)
public List<ConversationEntry> getConversationEntryList()
{
- return conversationEntryList;
+ return createConversationEntryList();
}
}
1.16 +18 -16 jboss-seam/src/main/org/jboss/seam/core/ConversationStack.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConversationStack.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationStack.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- ConversationStack.java 20 Jun 2007 22:11:30 -0000 1.15
+++ ConversationStack.java 8 Jul 2007 21:13:36 -0000 1.16
@@ -1,51 +1,52 @@
package org.jboss.seam.core;
+import static org.jboss.seam.ScopeType.PAGE;
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.web.Session;
/**
- * Support for "breadcrumbs".
+ * Factory for the "breadcrumbs", a stack with all
+ * parent conversations of the current conversation.
*
* @author Gavin King
*/
- at Scope(ScopeType.PAGE)
- at Name("org.jboss.seam.core.conversationStack")
+ at Scope(ScopeType.STATELESS)
+ at Name("org.jboss.seam.core.conversationStackFactory")
@Install(precedence=BUILT_IN)
@BypassInterceptors
-public class ConversationStack implements Serializable
+public class ConversationStack
{
- private static final long serialVersionUID = 7941458529299691801L;
- private List<ConversationEntry> conversationEntryStack;
- @Create
- public void createConversationEntryStack()
+ protected List<ConversationEntry> createConversationEntryStack()
{
ConversationEntries conversationEntries = ConversationEntries.getInstance();
if (conversationEntries==null)
{
- conversationEntryStack = Collections.EMPTY_LIST;
+ return Collections.EMPTY_LIST;
}
else
{
ConversationEntry currentConversationEntry = Manager.instance().getCurrentConversationEntry();
- if (currentConversationEntry!=null)
+ if (currentConversationEntry==null)
+ {
+ return Collections.EMPTY_LIST;
+ }
+ else
{
List<String> idStack = currentConversationEntry.getConversationIdStack();
- conversationEntryStack = new ArrayList<ConversationEntry>( conversationEntries.size() );
+ List<ConversationEntry> conversationEntryStack = new ArrayList<ConversationEntry>( conversationEntries.size() );
ListIterator<String> ids = idStack.listIterator( idStack.size() );
while ( ids.hasPrevious() )
{
@@ -55,14 +56,15 @@
conversationEntryStack.add(entry);
}
}
+ return conversationEntryStack;
}
}
}
- @Unwrap
+ @Factory(value="org.jboss.seam.core.conversationStack", autoCreate=true, scope=PAGE)
public List<ConversationEntry> getConversationEntryStack()
{
- return conversationEntryStack;
+ return createConversationEntryStack();
}
}
1.180 +5 -2 jboss-seam/src/main/org/jboss/seam/core/Manager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Manager.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -b -r1.179 -r1.180
--- Manager.java 6 Jul 2007 21:16:19 -0000 1.179
+++ Manager.java 8 Jul 2007 21:13:36 -0000 1.180
@@ -107,11 +107,14 @@
{
setCurrentConversationIdStack( ce.getConversationIdStack() );
//TODO: what about child conversations?!
- } else {
+ }
+ else
+ {
// when ce is null, the id stack will be left with a reference to
// the old conversation id, so we need patch that up
int pos = currentConversationIdStack.indexOf(priorId);
- if (pos != -1) {
+ if (pos != -1)
+ {
currentConversationIdStack.set(pos, id);
}
1.34 +30 -14 jboss-seam/src/main/org/jboss/seam/core/ResourceBundle.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ResourceBundle.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ResourceBundle.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- ResourceBundle.java 8 Jul 2007 11:23:08 -0000 1.33
+++ ResourceBundle.java 8 Jul 2007 21:13:36 -0000 1.34
@@ -1,8 +1,8 @@
package org.jboss.seam.core;
+import static org.jboss.seam.ScopeType.SESSION;
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
@@ -12,10 +12,10 @@
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.log.LogProvider;
@@ -25,15 +25,18 @@
import org.jboss.seam.util.Strings;
/**
- * A session-scoped localized resource bundle
+ * Factory for a session-scoped localized resource bundle
+ * that searches for resources in delegate resource bundles
+ * specified in pages.xml, and a configurable list of
+ * delegate resource bundles.
*
* @author Gavin King
*/
- at Scope(ScopeType.SESSION)
+ at Scope(ScopeType.STATELESS)
@BypassInterceptors
- at Name("org.jboss.seam.core.resourceBundle")
+ at Name("org.jboss.seam.core.resourceBundleFactory")
@Install(precedence=BUILT_IN)
-public class ResourceBundle implements Serializable
+public class ResourceBundle
{
protected java.util.Locale getCurrentLocale()
@@ -120,8 +123,12 @@
private static final LogProvider log = Logging.getLogProvider(ResourceBundle.class);
private String[] bundleNames = {"messages"};
- private transient java.util.ResourceBundle bundle;
+ /**
+ * The configurable list of delegate resource bundle names
+ *
+ * @return an array of resource bundle names
+ */
public String[] getBundleNames()
{
return bundleNames;
@@ -170,7 +177,7 @@
}
}
- private void createUberBundle()
+ protected java.util.ResourceBundle createUberBundle()
{
final List<java.util.ResourceBundle> littleBundles = new ArrayList<java.util.ResourceBundle>();
if (bundleNames!=null)
@@ -187,15 +194,21 @@
java.util.ResourceBundle validatorDefaultBundle = loadBundle("org/hibernate/validator/resources/DefaultValidatorMessages");
if (validatorDefaultBundle!=null) littleBundles.add(validatorDefaultBundle);
- bundle = new UberResourceBundle(littleBundles);
-
+ return new UberResourceBundle(littleBundles);
}
- @Unwrap
+ /**
+ * Create a ResourceBundle in the session scope. The session scope is used because
+ * creating the bundle is somewhat expensive, so it can be cached there because
+ * the session Locale changes infrequently. When the Locale is changed, LocaleSelector
+ * is responsible for removing the ResourceBundle from the session context.
+ *
+ * @return a ResourceBundle that wraps all the delegate bundles
+ */
+ @Factory(value="org.jboss.seam.core.resourceBundle", autoCreate=true, scope=SESSION)
public java.util.ResourceBundle getBundle()
{
- if (bundle==null) createUberBundle();
- return bundle;
+ return createUberBundle();
}
@Override
@@ -205,13 +218,16 @@
return "ResourceBundle(" + concat + ")";
}
+ /**
+ * @return the ResourceBundle instance
+ */
public static java.util.ResourceBundle instance()
{
if ( !Contexts.isSessionContextActive() )
{
throw new IllegalStateException("no session context active");
}
- return (java.util.ResourceBundle) Component.getInstance(ResourceBundle.class, true);
+ return (java.util.ResourceBundle) Component.getInstance("org.jboss.seam.core.resourceBundle", true);
}
}
More information about the jboss-cvs-commits
mailing list