You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/11/07 15:45:17 UTC
svn commit: r712141 - in
/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow:
./ components/ config/ utils/
Author: skitching
Date: Fri Nov 7 06:44:57 2008
New Revision: 712141
URL: http://svn.apache.org/viewvc?rev=712141&view=rev
Log:
* use java1.5 syntax now orchestra-flow is JSF1.2-or-later
* FlowParam* classes use ValueExpression instead of ValueBinding.
* FlowParam* classes now create ValueExpression objects immediately (rather than delaying until the value is read) in order to correctly capture the ELContext state. This is necessary to handle of:flowCall tags that are nested within ui:include that uses ui:param.
* tunnel the ELContext from the of:flowCall tag through to where the FlowParam* classes create their ValueExpression objects.
Added:
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/_ExpressionFactory.java (with props)
Modified:
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowHandler.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommit.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommitTag.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponent.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponentHandler.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallTag.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlow.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlowTag.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowAccept.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowCall.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowConfig.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowOnCommit.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamAccept.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamSend.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnAccept.java
myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnSend.java
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowHandler.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowHandler.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowHandler.java Fri Nov 7 06:44:57 2008
@@ -320,8 +320,9 @@
// Note that the ViewController methods are not invoked even though
// the backing bean for the view is. This is not a problem really, just
// something to be aware of.
- flowInfo.getFlowCall().writeAcceptParams(facesContext, map);
- FlowOnCommit onCommit = flowInfo.getFlowCall().getOnCommit();
+ FlowCall flowCall = flowInfo.getFlowCall();
+ flowCall.writeAcceptParams(facesContext, map);
+ FlowOnCommit onCommit = flowCall.getOnCommit();
outcome = null;
if (onCommit != null)
{
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommit.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommit.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommit.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommit.java Fri Nov 7 06:44:57 2008
@@ -19,8 +19,6 @@
package org.apache.myfaces.orchestra.flow.components;
-import java.util.Iterator;
-
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
@@ -78,6 +76,7 @@
private String outcome;
private String target;
+ @Override
public String getFamily()
{
return COMPONENT_FAMILY;
@@ -143,6 +142,7 @@
// ================ State Methods =================
+ @Override
public void restoreState(FacesContext context, Object state)
throws FacesException
{
@@ -152,6 +152,7 @@
target = (String) states[2];
}
+ @Override
public Object saveState(FacesContext context)
{
return new Object[]
@@ -187,11 +188,9 @@
return;
}
- Iterator i = c.getChildren().iterator();
- while (i.hasNext())
+ for(UIComponent child: c.getChildren())
{
- applyToAll((UIComponent) i.next(), outcome);
+ applyToAll(child, outcome);
}
}
-
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommitTag.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommitTag.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommitTag.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ClearOnCommitTag.java Fri Nov 7 06:44:57 2008
@@ -20,28 +20,40 @@
package org.apache.myfaces.orchestra.flow.components;
import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.webapp.UIComponentELTag;
-import org.apache.myfaces.shared_orchestra.taglib.UIComponentTagBase;
+import org.apache.myfaces.shared_orchestra.taglib.UIComponentTagUtils;
/**
* Tag for ClearOnCommit component.
*/
-public class ClearOnCommitTag extends UIComponentTagBase
+public class ClearOnCommitTag extends UIComponentELTag
{
private String outcome;
private String target;
+ @Override
public String getComponentType()
{
return ClearOnCommit.COMPONENT_TYPE;
}
+ @Override
+ public String getRendererType()
+ {
+ return null;
+ }
+
+ @Override
protected void setProperties(UIComponent component)
{
super.setProperties(component);
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
- setStringProperty(component, "outcome", outcome);
- setStringProperty(component, "target", target);
+ UIComponentTagUtils.setStringProperty(facesContext, component, "outcome", outcome);
+ UIComponentTagUtils.setStringProperty(facesContext, component, "target", target);
}
public void setOutcome(String outcome)
@@ -53,9 +65,4 @@
{
this.target = target;
}
-
- public String getRendererType()
- {
- return null;
- }
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponent.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponent.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponent.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponent.java Fri Nov 7 06:44:57 2008
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.Map;
+import javax.el.ELContext;
import javax.faces.FacesException;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
@@ -32,6 +33,7 @@
import org.apache.myfaces.orchestra.flow.config.FlowCall;
import org.apache.myfaces.orchestra.flow.config.FlowConfig;
import org.apache.myfaces.orchestra.flow.digest.FlowDigester;
+import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
import org.apache.myfaces.orchestra.lib.OrchestraException;
/**
@@ -73,6 +75,7 @@
private transient String viewId;
private transient String service;
+ @Override
public String getFamily()
{
return COMPONENT_FAMILY;
@@ -98,7 +101,7 @@
this.service = service;
}
- public void setBody(String content)
+ public void setBody(ELContext elContext, String content)
{
if (flowCall != null)
{
@@ -137,7 +140,17 @@
flowCall.setOutcome(outcome);
flowCall.setViewId(viewId);
flowCall.setService(service);
- FlowDigester.digestFlowCall(flowCall, content);
+
+ _ExpressionFactory.pushContext(elContext);
+ try
+ {
+ FlowDigester.digestFlowCall(flowCall, content);
+ }
+ finally
+ {
+ _ExpressionFactory.popContext(elContext);
+ }
+
flowCall.validate();
}
catch(OrchestraException e)
@@ -151,6 +164,7 @@
// ================ State Methods =================
+ @Override
public void restoreState(FacesContext context, Object state)
throws FacesException
{
@@ -161,6 +175,7 @@
getFlowConfigForRequest(context).addFlowCall(flowCall);
}
+ @Override
public Object saveState(FacesContext context)
{
return new Object[]
@@ -172,6 +187,7 @@
// ================ Renderer Methods =================
+ @Override
protected Renderer getRenderer(FacesContext context)
{
return null;
@@ -180,6 +196,7 @@
/**
* Return true so that method encodeChildren gets called.
*/
+ @Override
public boolean getRendersChildren()
{
return true;
@@ -190,6 +207,7 @@
* <p>
* We don't expect there to ever be children here. However it's best to be sure...
*/
+ @Override
public void encodeChildren(FacesContext context)
throws IOException
{
@@ -206,7 +224,7 @@
private static FlowConfig getFlowConfigForRequest(FacesContext facesContext)
{
- Map reqMap = facesContext.getExternalContext().getRequestMap();
+ Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
FlowConfig flowConfig = (FlowConfig) reqMap.get(FlowConfig.CONFIG_KEY);
if (flowConfig == null)
{
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponentHandler.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponentHandler.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallComponentHandler.java Fri Nov 7 06:44:57 2008
@@ -63,6 +63,7 @@
* Instruction nodes after this method has returned. Therefore the applyNextHandler method is overridden
* to prevent that.
*/
+ @Override
protected void onComponentCreated(FaceletContext ctx, UIComponent c, UIComponent parent)
{
StringBuffer content = new StringBuffer();
@@ -79,7 +80,7 @@
// not expected. The iterator always stops (hasNext is false) when there are no more child nodes
// for this flowCall element.
content.append("<flowCall>\n");
- Iterator iter = findNextByType(TextHandler.class);
+ Iterator<?> iter = findNextByType(TextHandler.class);
while (iter.hasNext())
{
TextHandler text = (TextHandler) iter.next();
@@ -92,14 +93,16 @@
}
content.append("</flowCall>");
- ((FlowCallComponent) c).setBody(content.toString());
+ ((FlowCallComponent) c).setBody(ctx, content.toString());
}
+ @Override
protected void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent)
{
// do nothing
}
+ @Override
protected void applyNextHandler(FaceletContext ctx, UIComponent c)
throws IOException, FacesException, ELException
{
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallTag.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallTag.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallTag.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/FlowCallTag.java Fri Nov 7 06:44:57 2008
@@ -19,8 +19,10 @@
package org.apache.myfaces.orchestra.flow.components;
-import javax.faces.webapp.UIComponentBodyTag;
+import javax.el.ELContext;
+import javax.faces.webapp.UIComponentELTag;
import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
/**
@@ -28,17 +30,28 @@
* <p>
* Note that JSP tag-handlers are invoked on every render of a view.
*/
-public class FlowCallTag extends UIComponentBodyTag
+public class FlowCallTag extends UIComponentELTag
{
+ private PageContext pageContext;
+
private String outcome;
private String viewId;
private String service;
+ @Override
+ public void setPageContext(PageContext pageContext)
+ {
+ super.setPageContext(pageContext);
+ this.pageContext = pageContext;
+ }
+
+ @Override
public String getComponentType()
{
return FlowCallComponent.COMPONENT_TYPE;
}
+ @Override
public String getRendererType()
{
return null;
@@ -59,6 +72,7 @@
this.service = service;
}
+ @Override
protected int getDoStartValue()
throws JspException
{
@@ -68,11 +82,14 @@
return BodyTag.EVAL_BODY_BUFFERED;
}
+ @Override
public int doAfterBody() throws JspException
{
FlowCallComponent component = (FlowCallComponent) getComponentInstance();
if (!component.isInitialized())
{
+ ELContext elContext = pageContext.getELContext();
+
component.setOutcome(outcome);
component.setViewId(viewId);
component.setService(service);
@@ -84,7 +101,7 @@
buf.append(bodyText);
buf.append("</flowCall>");
String xml = buf.toString();
- component.setBody(xml);
+ component.setBody(elContext, xml);
}
return 0;
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlow.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlow.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlow.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlow.java Fri Nov 7 06:44:57 2008
@@ -81,6 +81,7 @@
// transient property
private boolean active = false;
+ @Override
public String getFamily()
{
return COMPONENT_FAMILY;
@@ -154,6 +155,7 @@
// ================ State Methods =================
+ @Override
public void restoreState(FacesContext context, Object state)
throws FacesException
{
@@ -170,11 +172,12 @@
//
// Note that a null outcome is valid.
- Map reqMap = context.getExternalContext().getRequestMap();
- Map flowMap = (Map) reqMap.get("modalFlows");
+ Map<String, Object> reqMap = context.getExternalContext().getRequestMap();
+ @SuppressWarnings("unchecked")
+ Map<String, ModalFlow> flowMap = (Map<String, ModalFlow>) reqMap.get("modalFlows");
if (flowMap == null)
{
- flowMap = new HashMap();
+ flowMap = new HashMap<String, ModalFlow>();
reqMap.put("modalFlows", flowMap);
}
if (flowMap.containsKey(outcome))
@@ -184,6 +187,7 @@
flowMap.put(outcome, this);
}
+ @Override
public Object saveState(FacesContext context)
{
return new Object[]
@@ -204,6 +208,7 @@
* <p>
* When this component is not active, nothing is rendered.
*/
+ @Override
public void encodeBegin(FacesContext context) throws IOException
{
super.encodeBegin(context);
@@ -239,8 +244,9 @@
*/
public static ModalFlow getForOutcome(FacesContext context, String outcome)
{
- Map reqMap = context.getExternalContext().getRequestMap();
- Map flowMap = (Map) reqMap.get("modalFlows");
+ Map<String, Object> reqMap = context.getExternalContext().getRequestMap();
+ @SuppressWarnings("unchecked")
+ Map<String, ModalFlow> flowMap = (Map<String, ModalFlow>) reqMap.get("modalFlows");
if (flowMap == null)
{
return null;
@@ -255,5 +261,4 @@
// look for a global one
return (ModalFlow) flowMap.get(null);
}
-
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlowTag.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlowTag.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlowTag.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/components/ModalFlowTag.java Fri Nov 7 06:44:57 2008
@@ -32,11 +32,13 @@
private String onEntry;
private String onExit;
+ @Override
public String getComponentType()
{
return ModalFlow.COMPONENT_TYPE;
}
+ @Override
protected void setProperties(UIComponent component)
{
super.setProperties(component);
@@ -61,6 +63,7 @@
this.onExit = onExit;
}
+ @Override
public String getRendererType()
{
return null;
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowAccept.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowAccept.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowAccept.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowAccept.java Fri Nov 7 06:44:57 2008
@@ -21,12 +21,10 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
import org.apache.myfaces.orchestra.lib.OrchestraException;
@@ -37,14 +35,14 @@
{
// For serialization. IMPORTANT; update this when changing the
// binary format of this class (eg adding fields).
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 2L;
private String service;
private String commitWhen = "commit";
private String cancelWhen = "cancel";
private String restartWhen = "restart";
- private List params = new ArrayList(4); // list of FlowParamAccept
- private List returns = new ArrayList(4); // list of FlowReturnSend
+ private List<FlowParamAccept> params = new ArrayList<FlowParamAccept>(4);
+ private List<FlowReturnSend> returns = new ArrayList<FlowReturnSend>(4);
/**
* Constructor.
@@ -89,15 +87,13 @@
throw new OrchestraException("returns is empty");
}
- for(Iterator i = params.iterator(); i.hasNext(); )
+ for(FlowParamAccept p: params)
{
- FlowParamAccept p = (FlowParamAccept) i.next();
p.validate();
}
- for(Iterator i = returns.iterator(); i.hasNext(); )
+ for(FlowReturnSend p : returns)
{
- FlowReturnSend p = (FlowReturnSend) i.next();
p.validate();
}
}
@@ -109,16 +105,13 @@
* The data in this map is then expected to be passed back to the caller by
* executing the "return param" expressions of the matching FlowCall object.
*/
- public Map readReturnParams(FacesContext facesContext)
+ public Map<String, Object> readReturnParams(FacesContext facesContext)
{
- Map data = new HashMap();
- for(Iterator i = returns.iterator(); i.hasNext(); )
+ Map<String, Object> data = new HashMap<String, Object>();
+ for(FlowReturnSend param : returns)
{
- FlowReturnSend param = (FlowReturnSend) i.next();
String paramName = param.getName();
- String src = param.getSrc();
- ValueBinding vb = facesContext.getApplication().createValueBinding(src);
- Object paramValue = vb.getValue(facesContext);
+ Object paramValue = param.getSrcValue(facesContext);
data.put(paramName, paramValue);
}
return data;
@@ -132,11 +125,10 @@
* The map is expected to have been populated by executing the "send param"
* expressions of the matching FlowCall object.
*/
- public void writeAcceptParams(FacesContext facesContext, Map data)
+ public void writeAcceptParams(FacesContext facesContext, Map<String, Object> data)
{
- for(Iterator i = params.iterator(); i.hasNext(); )
+ for(FlowParamAccept param : params)
{
- FlowParamAccept param = (FlowParamAccept) i.next();
String paramName = param.getName();
Object paramValue;
@@ -153,13 +145,10 @@
{
throw new OrchestraException("Missing parameter:" + paramName);
}
- ValueBinding dfltVb = facesContext.getApplication().createValueBinding(dflt);
- paramValue = dfltVb.getValue(facesContext);
+ paramValue = param.getDfltValue(facesContext);
}
-
- String dst = param.getDst();
- ValueBinding vb = facesContext.getApplication().createValueBinding(dst);
- vb.setValue(facesContext, paramValue);
+
+ param.setDstValue(facesContext, paramValue);
}
}
@@ -251,7 +240,7 @@
* Return list of FlowParamAccept objects which defines what input
* parameters this callable flow accepts.
*/
- public List getParams()
+ public List<FlowParamAccept> getParams()
{
return params;
}
@@ -266,7 +255,7 @@
* Return list of FlowReturnSend objects which defines what output
* parameters this callable flow returns to the caller on commit.
*/
- public List getReturns()
+ public List<FlowReturnSend> getReturns()
{
return returns;
}
@@ -280,6 +269,7 @@
/**
* Custom string format to improve log messages.
*/
+ @Override
public String toString()
{
return "flowAccept: service=" + service;
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowCall.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowCall.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowCall.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowCall.java Fri Nov 7 06:44:57 2008
@@ -21,12 +21,10 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
import org.apache.myfaces.orchestra.lib.OrchestraException;
@@ -40,12 +38,11 @@
private static final long serialVersionUID = 1L;
private String outcome;
-
private String viewId;
private String service;
- private List params = new ArrayList(4); // list of FlowParamSend
- private List returns = new ArrayList(4); // list of FlowReturnAccept
+ private List<FlowParamSend> params = new ArrayList<FlowParamSend>(4);
+ private List<FlowReturnAccept> returns = new ArrayList<FlowReturnAccept>(4);
private FlowOnCommit onCommit;
@@ -102,15 +99,13 @@
throw new OrchestraException("returns is empty");
}
- for(Iterator i = params.iterator(); i.hasNext(); )
+ for(FlowParamSend p : params)
{
- FlowParamSend p = (FlowParamSend) i.next();
p.validate();
}
- for(Iterator i = returns.iterator(); i.hasNext(); )
+ for(FlowReturnAccept p : returns)
{
- FlowReturnAccept p = (FlowReturnAccept) i.next();
p.validate();
}
}
@@ -122,16 +117,13 @@
* The data in this map is then expected to be imported into beans belonging
* to the called flow
*/
- public Map readSendParams(FacesContext facesContext)
+ public Map<String, Object> readSendParams(FacesContext facesContext)
{
- Map data = new HashMap();
- for(Iterator i = params.iterator(); i.hasNext(); )
+ Map<String, Object> data = new HashMap<String, Object>();
+ for(FlowParamSend param : params)
{
- FlowParamSend param = (FlowParamSend) i.next();
String paramName = param.getName();
- String src = param.getSrc();
- ValueBinding vb = facesContext.getApplication().createValueBinding(src);
- Object paramValue = vb.getValue(facesContext);
+ Object paramValue = param.getSrcValue(facesContext);
data.put(paramName, paramValue);
}
return data;
@@ -144,19 +136,13 @@
* The map is expected to have been populated by executing the
* "return param" expressions of the called flow.
*/
- public void writeAcceptParams(FacesContext facesContext, Map data)
+ public void writeAcceptParams(FacesContext facesContext, Map<String, Object> data)
{
- for(Iterator i = returns.iterator(); i.hasNext(); )
+ for(FlowReturnAccept param : returns)
{
- FlowReturnAccept param = (FlowReturnAccept) i.next();
String paramName = param.getName();
- String dst = param.getDst();
- if (dst != null)
- {
- // note: dst is null when the caller doesn't want to use the returned value.
- ValueBinding vb = facesContext.getApplication().createValueBinding(dst);
- vb.setValue(facesContext, data.get(paramName));
- }
+ Object newValue = data.get(paramName);
+ param.setDstValue(facesContext, newValue);
}
}
@@ -221,7 +207,7 @@
* Return list of FlowParamSend objects which defines what values the flow
* caller passes to the called flow when this FlowCall is triggered.
*/
- public List getParams()
+ public List<FlowParamSend> getParams()
{
return params;
}
@@ -237,7 +223,7 @@
* flow is expected to return on commit, and where they should be stored
* within the caller's environment.
*/
- public List getReturns()
+ public List<FlowReturnAccept> getReturns()
{
return returns;
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowConfig.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowConfig.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowConfig.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowConfig.java Fri Nov 7 06:44:57 2008
@@ -20,7 +20,6 @@
import java.io.Serializable;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.myfaces.orchestra.lib.OrchestraException;
@@ -38,8 +37,8 @@
// binary format of this class (eg adding fields).
private static final long serialVersionUID = 1L;
- // key is outcome, value is FlowCall
- private Map flowCalls = new HashMap();
+ // Key is the outcome string
+ private Map<String, FlowCall> flowCalls = new HashMap<String, FlowCall>();
private FlowAccept flowAccept;
@@ -63,9 +62,8 @@
flowAccept.validate();
}
- for(Iterator i = flowCalls.values().iterator(); i.hasNext(); )
+ for(FlowCall flowCall : flowCalls.values())
{
- FlowCall flowCall = (FlowCall) i.next();
flowCall.validate();
}
}
@@ -121,6 +119,7 @@
/**
* Custom string format to improve log messages.
*/
+ @Override
public String toString()
{
StringBuffer buf = new StringBuffer();
@@ -134,9 +133,9 @@
if (!flowCalls.isEmpty())
{
buf.append("\n{");
- for(Iterator i = flowCalls.entrySet().iterator(); i.hasNext(); )
+ for(Object mapEntry : flowCalls.entrySet())
{
- buf.append(i.next().toString());
+ buf.append(mapEntry.toString());
buf.append("\n");
}
buf.append("}\n");
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowOnCommit.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowOnCommit.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowOnCommit.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowOnCommit.java Fri Nov 7 06:44:57 2008
@@ -20,9 +20,10 @@
import java.io.Serializable;
+import javax.el.MethodExpression;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
+import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
import org.apache.myfaces.orchestra.lib.OrchestraException;
@@ -48,6 +49,7 @@
private static final long serialVersionUID = 1L;
private String action;
+ private MethodExpression actionExpr;
/** Constructor. */
public FlowOnCommit()
@@ -80,6 +82,10 @@
public void setAction(String action)
{
this.action = action;
+
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ actionExpr = _ExpressionFactory.createMethodExpression(fc, action);
}
/**
@@ -87,8 +93,7 @@
*/
public Object execute(FacesContext facesContext)
{
- MethodBinding mb = facesContext.getApplication().createMethodBinding(action, null);
- Object o = mb.invoke(facesContext, null);
+ Object o = actionExpr.invoke(facesContext.getELContext(), null);
return o;
}
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamAccept.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamAccept.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamAccept.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamAccept.java Fri Nov 7 06:44:57 2008
@@ -20,6 +20,10 @@
import java.io.Serializable;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
import org.apache.myfaces.orchestra.lib.OrchestraException;
/**
@@ -34,7 +38,9 @@
private String name;
private String dst;
+ private ValueExpression dstExpr;
private String dflt;
+ private ValueExpression dfltExpr;
/** Constructor. */
public FlowParamAccept()
@@ -95,6 +101,18 @@
public void setDst(String expr)
{
this.dst = expr;
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ dstExpr = _ExpressionFactory.createValueExpression(fc, dst);
+ }
+
+ public void setDstValue(FacesContext facesContext, Object newValue)
+ {
+ if (dstExpr != null)
+ {
+ // note: dst is null when the caller doesn't want to use the returned value.
+ dstExpr.setValue(facesContext.getELContext(), newValue);
+ }
}
/**
@@ -116,5 +134,16 @@
public void setDflt(String dflt)
{
this.dflt = dflt;
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ dfltExpr = _ExpressionFactory.createValueExpression(fc, dflt);
+ }
+
+ /**
+ * Evaluate the src EL expression and return the resulting object (or null).
+ */
+ public Object getDfltValue(FacesContext facesContext)
+ {
+ return dfltExpr.getValue(facesContext.getELContext());
}
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamSend.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamSend.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamSend.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowParamSend.java Fri Nov 7 06:44:57 2008
@@ -20,6 +20,10 @@
import java.io.Serializable;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
import org.apache.myfaces.orchestra.lib.OrchestraException;
/**
@@ -30,11 +34,12 @@
{
// For serialization. IMPORTANT; update this when changing the
// binary format of this class (eg adding fields).
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 2L;
private String name;
private String src;
-
+ private ValueExpression srcExpr;
+
/** Constructor. */
public FlowParamSend()
{
@@ -90,5 +95,16 @@
public void setSrc(String expr)
{
this.src = expr;
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ srcExpr = _ExpressionFactory.createValueExpression(fc, src);
+ }
+
+ /**
+ * Evaluate the src EL expression and return the resulting object (or null).
+ */
+ public Object getSrcValue(FacesContext facesContext)
+ {
+ return srcExpr.getValue(facesContext.getELContext());
}
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnAccept.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnAccept.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnAccept.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnAccept.java Fri Nov 7 06:44:57 2008
@@ -20,6 +20,10 @@
import java.io.Serializable;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
import org.apache.myfaces.orchestra.lib.OrchestraException;
/**
@@ -33,6 +37,7 @@
private String name;
private String dst;
+ private ValueExpression dstExpr;
/** Constructor. */
public FlowReturnAccept()
@@ -93,5 +98,17 @@
public void setDst(String expr)
{
dst = expr;
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ dstExpr = _ExpressionFactory.createValueExpression(fc, dst);
+ }
+
+ public void setDstValue(FacesContext facesContext, Object newValue)
+ {
+ if (dstExpr != null)
+ {
+ // note: dst is null when the caller doesn't want to use the returned value.
+ dstExpr.setValue(facesContext.getELContext(), newValue);
+ }
}
}
Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnSend.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnSend.java?rev=712141&r1=712140&r2=712141&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnSend.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/config/FlowReturnSend.java Fri Nov 7 06:44:57 2008
@@ -20,6 +20,10 @@
import java.io.Serializable;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
import org.apache.myfaces.orchestra.lib.OrchestraException;
/**
@@ -34,6 +38,7 @@
private String name;
private String src;
+ private ValueExpression srcExpr;
/** Constructor. */
public FlowReturnSend()
@@ -90,5 +95,16 @@
public void setSrc(String expr)
{
this.src = expr;
+
+ FacesContext fc = FacesContext.getCurrentInstance();
+ srcExpr = _ExpressionFactory.createValueExpression(fc, src);
+ }
+
+ /**
+ * Evaluate the src EL expression and return the resulting object (or null).
+ */
+ public Object getSrcValue(FacesContext facesContext)
+ {
+ return srcExpr.getValue(facesContext.getELContext());
}
}
Added: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/_ExpressionFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/_ExpressionFactory.java?rev=712141&view=auto
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/_ExpressionFactory.java (added)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/_ExpressionFactory.java Fri Nov 7 06:44:57 2008
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.orchestra.flow.utils;
+
+import java.util.Stack;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.lib.OrchestraException;
+
+import com.sun.facelets.FaceletContext;
+
+/**
+ * Creates ValueExpression objects based on the "current" ELContext.
+ * <p>
+ * This class allows an ELContext to be "tunnelled" as a thread-local variable to places where code
+ * wants to create a ValueExpression even though the ELContext is not available as a parameter.
+ */
+public class _ExpressionFactory
+{
+ private static final ThreadLocal<Stack<ELContext>> _contextsThreadLocal = new ThreadLocal<Stack<ELContext>>();
+
+ public static void pushContext(ELContext ctx)
+ {
+ if (ctx == null)
+ {
+ throw new IllegalArgumentException("ctx must not be null");
+ }
+ Stack<ELContext> s = _contextsThreadLocal.get();
+ if (s == null)
+ {
+ s = new Stack<ELContext>();
+ _contextsThreadLocal.set(s);
+ }
+ s.push(ctx);
+ }
+
+ public static void popContext(ELContext ctx)
+ {
+ Stack<ELContext> s = _contextsThreadLocal.get();
+ if (s == null)
+ {
+ throw new IllegalStateException("context stack is null");
+ }
+ if (s.isEmpty())
+ {
+ throw new IllegalStateException("context stack is empty");
+ }
+ Object o = s.pop();
+ if (o != ctx)
+ {
+ throw new IllegalStateException("context stack unbalanced");
+ }
+ if (s.isEmpty())
+ {
+ _contextsThreadLocal.remove();
+ }
+ }
+
+ private static FaceletContext peekContext()
+ {
+ Stack<ELContext> s = _contextsThreadLocal.get();
+ if (s == null)
+ {
+ return null;
+ }
+ return (FaceletContext) s.peek();
+ }
+
+ public static ValueExpression createValueExpression(FacesContext facesContext, String expr)
+ {
+ ELContext elContext = peekContext();
+ if (elContext == null)
+ {
+ // ok, we are not running within the context of some particular UIComponent, ie we are
+ // not processing xml embedded within an of:flowCall tag in a JSP page. We are probably
+ // processing a flow.xml file loaded from the disk. In this case, just use the "global"
+ // el context held by the FacesContext object.
+ elContext = facesContext.getELContext();
+ }
+
+ try
+ {
+ ExpressionFactory ef = facesContext.getApplication().getExpressionFactory();
+ ValueExpression ve = ef.createValueExpression(elContext, expr, Object.class);
+ return ve;
+ }
+ catch(Exception e)
+ {
+ Log log = LogFactory.getLog(_ExpressionFactory.class);
+ String msg = "Unable to parse value expression in flow:" + expr;
+ log.warn(msg, e);
+ throw new OrchestraException(msg, e);
+ }
+ }
+
+ public static MethodExpression createMethodExpression(FacesContext facesContext, String expr)
+ {
+ ELContext elContext = peekContext();
+ if (elContext == null)
+ {
+ // ok, we are not running within the context of some particular UIComponent, ie we are
+ // not processing xml embedded within an of:flowCall tag in a JSP page. We are probably
+ // processing a flow.xml file loaded from the disk. In this case, just use the "global"
+ // el context held by the FacesContext object.
+ elContext = facesContext.getELContext();
+ }
+
+ try
+ {
+ ExpressionFactory ef = facesContext.getApplication().getExpressionFactory();
+ MethodExpression me = ef.createMethodExpression(elContext, expr, Object.class, null);
+ return me;
+ }
+ catch(Exception e)
+ {
+ Log log = LogFactory.getLog(_ExpressionFactory.class);
+ String msg = "Unable to parse method expression in flow:" + expr;
+ log.warn(msg, e);
+ throw new OrchestraException(msg, e);
+ }
+ }
+}
Propchange: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/utils/_ExpressionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native