[jboss-cvs] jboss-seam/src/main/org/jboss/seam ...
Gavin King
gavin.king at jboss.com
Wed Oct 11 20:09:45 EDT 2006
User: gavin
Date: 06/10/11 20:09:45
Modified: src/main/org/jboss/seam Component.java ScopeType.java
Log:
don't throw no context active exceptions during lifecycle methods
Revision Changes Path
1.188 +29 -18 jboss-seam/src/main/org/jboss/seam/Component.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Component.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Component.java,v
retrieving revision 1.187
retrieving revision 1.188
diff -u -b -r1.187 -r1.188
--- Component.java 11 Oct 2006 02:18:51 -0000 1.187
+++ Component.java 12 Oct 2006 00:09:45 -0000 1.188
@@ -109,7 +109,7 @@
*
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
* @author Gavin King
- * @version $Revision: 1.187 $
+ * @version $Revision: 1.188 $
*/
@Scope(ScopeType.APPLICATION)
public class Component
@@ -1060,7 +1060,7 @@
{
ScopeType scope = wrapper.getVariableScope(dataModelAnn);
- Object dataModel = getOutContext(scope, this).get(name);
+ Object dataModel = getOutScope(scope, this).getContext().get(name);
if ( dataModel != null )
{
@@ -1149,7 +1149,7 @@
ScopeType scope = wrapper.getVariableScope(dataModelAnn);
- Context context = getOutContext(scope, this);
+ Context context = getOutScope(scope, this).getContext();
Object existingDataModel = context.get(name);
boolean dirty = existingDataModel == null || scope==PAGE ||
wrapper.isDirty(dataModelAnn, existingDataModel, list);
@@ -1168,7 +1168,8 @@
}
- private static Context getOutContext(ScopeType specifiedScope, Component component) {
+ private static ScopeType getOutScope(ScopeType specifiedScope, Component component)
+ {
ScopeType scope = component==null ? EVENT : component.getScope();
if (scope==STATELESS)
{
@@ -1178,7 +1179,7 @@
{
scope = specifiedScope;
}
- return scope.getContext();
+ return scope;
}
private void injectMethods(Object bean, boolean enforceRequired)
@@ -1285,17 +1286,20 @@
);
}
- Context context = component==null ?
- getOutContext( out.scope(), this ) :
- component.getScope().getContext();
+ ScopeType outScope = component==null ?
+ getOutScope( out.scope(), this ) :
+ component.getScope();
+ if ( enforceRequired || outScope.isContextActive() )
+ {
if (value==null)
{
- context.remove(name);
+ outScope.getContext().remove(name);
}
else
{
- context.set(name, value);
+ outScope.getContext().set(name, value);
+ }
}
}
}
@@ -1537,7 +1541,7 @@
Object value = Contexts.lookupInStatefulContexts(name); //see if a value was outjected by the factory method
if (value==null) //usually a factory method returning a value
{
- getOutContext(scope, component).set(name, result);
+ getOutScope(scope, component).getContext().set(name, result);
return result;
}
else //usually a factory method with a void return type
@@ -1698,8 +1702,15 @@
{
log.debug("trying to inject from specified context: " + name + ", scope: " + scope);
}
+ if ( enforceRequired || in.scope().isContextActive() )
+ {
result = in.scope().getContext().get(name);
}
+ else
+ {
+ return null;
+ }
+ }
if ( result==null && enforceRequired && in.required() )
{
1.10 +24 -1 jboss-seam/src/main/org/jboss/seam/ScopeType.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ScopeType.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/ScopeType.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- ScopeType.java 10 Oct 2006 22:30:39 -0000 1.9
+++ ScopeType.java 12 Oct 2006 00:09:45 -0000 1.10
@@ -13,7 +13,7 @@
* The available scopes (contexts).
*
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public enum ScopeType
{
@@ -62,6 +62,29 @@
*/
UNSPECIFIED;
+ public boolean isContextActive()
+ {
+ switch (this)
+ {
+ case STATELESS:
+ return true;
+ case EVENT:
+ return Contexts.isEventContextActive();
+ case PAGE:
+ return Contexts.isPageContextActive();
+ case CONVERSATION:
+ return Contexts.isConversationContextActive();
+ case SESSION:
+ return Contexts.isSessionContextActive();
+ case APPLICATION:
+ return Contexts.isApplicationContextActive();
+ case BUSINESS_PROCESS:
+ return Contexts.isBusinessProcessContextActive();
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
/**
* @return the Context object for this scope
*/
More information about the jboss-cvs-commits
mailing list