added binding model; remove unused code; fixed bug in var model merging

This commit is contained in:
Keith Donald
2008-07-14 21:52:24 +00:00
parent 902672eb3b
commit 415fce8908
25 changed files with 181 additions and 417 deletions

View File

@@ -56,19 +56,6 @@ public abstract class AbstractActionModel extends AbstractModel {
this.attributes = attributes;
}
/**
* @param attribute the attribute to add
*/
public void addAttribute(AttributeModel attribute) {
if (attribute == null) {
return;
}
if (attributes == null) {
attributes = new LinkedList();
}
attributes.add(attribute);
}
/**
* @param attributes the attributes to add
*/

View File

@@ -25,8 +25,11 @@ import org.springframework.util.StringUtils;
public abstract class AbstractMappingModel extends AbstractModel {
private String name;
private String value;
private String type;
private String required;
/**

View File

@@ -25,11 +25,17 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public abstract class AbstractStateModel extends AbstractModel {
private String id;
private String parent;
private LinkedList attributes;
private SecuredModel secured;
private LinkedList onEntryActions;
private LinkedList exceptionHandlers;
/**
@@ -82,32 +88,6 @@ public abstract class AbstractStateModel extends AbstractModel {
this.attributes = attributes;
}
/**
* @param attribute the attribute to add
*/
public void addAttribute(AttributeModel attribute) {
if (attribute == null) {
return;
}
if (attributes == null) {
attributes = new LinkedList();
}
attributes.add(attribute);
}
/**
* @param attributes the attributes to add
*/
public void addAttributes(LinkedList attributes) {
if (attributes == null || attributes.isEmpty()) {
return;
}
if (this.attributes == null) {
this.attributes = new LinkedList();
}
this.attributes.addAll(attributes);
}
/**
* @return the secured
*/
@@ -136,32 +116,6 @@ public abstract class AbstractStateModel extends AbstractModel {
this.onEntryActions = onEntryActions;
}
/**
* @param onEntryAction the on entry action to add
*/
public void addOnEntryAction(AbstractActionModel onEntryAction) {
if (onEntryAction == null) {
return;
}
if (onEntryActions == null) {
onEntryActions = new LinkedList();
}
onEntryActions.add(onEntryAction);
}
/**
* @param onEntryActions the on entry actions to add
*/
public void addOnEntryActions(LinkedList onEntryActions) {
if (onEntryActions == null || onEntryActions.isEmpty()) {
return;
}
if (this.onEntryActions == null) {
this.onEntryActions = new LinkedList();
}
this.onEntryActions.addAll(onEntryActions);
}
/**
* @return the exception handlers
*/
@@ -176,29 +130,4 @@ public abstract class AbstractStateModel extends AbstractModel {
this.exceptionHandlers = exceptionHandlers;
}
/**
* @param exceptionHandler the exception handler to add
*/
public void addExceptionHandler(ExceptionHandlerModel exceptionHandler) {
if (exceptionHandler == null) {
return;
}
if (exceptionHandlers == null) {
exceptionHandlers = new LinkedList();
}
exceptionHandlers.add(exceptionHandler);
}
/**
* @param exceptionHandlers the exception handlers to add
*/
public void addExceptionHandlers(LinkedList exceptionHandlers) {
if (exceptionHandlers == null || exceptionHandlers.isEmpty()) {
return;
}
if (this.exceptionHandlers == null) {
this.exceptionHandlers = new LinkedList();
}
this.exceptionHandlers.addAll(exceptionHandlers);
}
}
}

View File

@@ -23,7 +23,9 @@ import java.util.LinkedList;
* @author Scott Andrews
*/
public abstract class AbstractTransitionableStateModel extends AbstractStateModel {
private LinkedList transitions;
private LinkedList onExitActions;
/**
@@ -40,32 +42,6 @@ public abstract class AbstractTransitionableStateModel extends AbstractStateMode
this.transitions = transitions;
}
/**
* @param transition the transition to add
*/
public void addTransition(TransitionModel transition) {
if (transition == null) {
return;
}
if (transitions == null) {
transitions = new LinkedList();
}
transitions.add(transition);
}
/**
* @param transitions the transitions to add
*/
public void addTransitions(LinkedList transitions) {
if (transitions == null || transitions.isEmpty()) {
return;
}
if (this.transitions == null) {
this.transitions = new LinkedList();
}
this.transitions.addAll(transitions);
}
/**
* @return the on exit actions
*/
@@ -80,29 +56,4 @@ public abstract class AbstractTransitionableStateModel extends AbstractStateMode
this.onExitActions = onExitActions;
}
/**
* @param onExitAction the on exit action to add
*/
public void addOnExitAction(AbstractActionModel onExitAction) {
if (onExitAction == null) {
return;
}
if (this.onExitActions == null) {
this.onExitActions = new LinkedList();
}
this.onExitActions.add(onExitAction);
}
/**
* @param onExitActions the on exit actions to add
*/
public void addOnExitsActions(LinkedList onExitActions) {
if (onExitActions == null || onExitActions.isEmpty()) {
return;
}
if (this.onExitActions == null) {
this.onExitActions = new LinkedList();
}
this.onExitActions.addAll(onExitActions);
}
}
}

View File

@@ -24,6 +24,7 @@ import org.springframework.util.ObjectUtils;
* @author Scott Andrews
*/
public class ActionStateModel extends AbstractTransitionableStateModel {
private LinkedList actions;
/**
@@ -68,29 +69,4 @@ public class ActionStateModel extends AbstractTransitionableStateModel {
this.actions = actions;
}
/**
* @param action the action to add
*/
public void addAction(AbstractActionModel action) {
if (action == null) {
return;
}
if (actions == null) {
actions = new LinkedList();
}
actions.add(action);
}
/**
* @param actions the actions to add
*/
public void addAction(LinkedList actions) {
if (actions == null || actions.isEmpty()) {
return;
}
if (this.actions == null) {
this.actions = new LinkedList();
}
this.actions.addAll(actions);
}
}
}

View File

@@ -26,8 +26,11 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class AttributeModel extends AbstractModel {
private String name;
private String type;
private String value;
/**

View File

@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class BeanImportModel extends AbstractModel {
private String resource;
/**

View File

@@ -24,7 +24,9 @@ import org.springframework.util.ObjectUtils;
* @author Scott Andrews
*/
public class DecisionStateModel extends AbstractStateModel {
private LinkedList ifs;
private LinkedList onExitActions;
/**
@@ -68,32 +70,6 @@ public class DecisionStateModel extends AbstractStateModel {
this.ifs = ifs;
}
/**
* @param conditional the if to add
*/
public void addIf(IfModel conditional) {
if (conditional == null) {
return;
}
if (ifs == null) {
ifs = new LinkedList();
}
ifs.add(conditional);
}
/**
* @param ifs the ifs to add
*/
public void addIf(LinkedList ifs) {
if (ifs == null || ifs.isEmpty()) {
return;
}
if (this.ifs == null) {
this.ifs = new LinkedList();
}
this.ifs.addAll(ifs);
}
/**
* @return the on exit actions
*/
@@ -108,29 +84,4 @@ public class DecisionStateModel extends AbstractStateModel {
this.onExitActions = onExitActions;
}
/**
* @param onExitAction the on exit action to add
*/
public void addOnExitAction(AbstractActionModel onExitAction) {
if (onExitAction == null) {
return;
}
if (onExitActions == null) {
onExitActions = new LinkedList();
}
onExitActions.add(onExitAction);
}
/**
* @param onExitActions the on exit actions to add
*/
public void addOnExitActions(LinkedList onExitActions) {
if (onExitActions == null || onExitActions.isEmpty()) {
return;
}
if (this.onExitActions == null) {
this.onExitActions = new LinkedList();
}
this.onExitActions.addAll(onExitActions);
}
}
}

View File

@@ -25,8 +25,11 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class EndStateModel extends AbstractStateModel {
private String view;
private String commit;
private LinkedList outputs;
/**
@@ -120,16 +123,4 @@ public class EndStateModel extends AbstractStateModel {
outputs.add(output);
}
/**
* @param outputs the output mappings to add
*/
public void addOutputs(LinkedList outputs) {
if (outputs == null || outputs.isEmpty()) {
return;
}
if (this.outputs == null) {
this.outputs = new LinkedList();
}
this.outputs.addAll(outputs);
}
}

View File

@@ -25,8 +25,11 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class EvaluateModel extends AbstractActionModel {
private String expression;
private String result;
private String resultType;
/**

View File

@@ -46,21 +46,35 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class FlowModel extends AbstractModel {
// private String id;
private String abztract;
private String parent;
private String startStateId;
private LinkedList attributes;
private SecuredModel secured;
private PersistenceContextModel persistenceContext;
private LinkedList vars;
private LinkedList inputs;
private LinkedList outputs;
private LinkedList onStartActions;
private LinkedList states;
private LinkedList globalTransitions;
private LinkedList onEndActions;
private LinkedList exceptionHandlers;
private LinkedList beanImports;
/**
@@ -448,13 +462,6 @@ public class FlowModel extends AbstractModel {
addState(state);
}
/**
* @param states the action states to add
*/
public void addActionStates(LinkedList states) {
addStates(states);
}
/**
* @param state the view state to add
*/
@@ -462,13 +469,6 @@ public class FlowModel extends AbstractModel {
addState(state);
}
/**
* @param states the view states to add
*/
public void addViewStates(LinkedList states) {
addStates(states);
}
/**
* @param state the decision state to add
*/
@@ -476,13 +476,6 @@ public class FlowModel extends AbstractModel {
addState(state);
}
/**
* @param states the decision states to add
*/
public void addDecisionStates(LinkedList states) {
addStates(states);
}
/**
* @param state the subflow state to add
*/
@@ -490,13 +483,6 @@ public class FlowModel extends AbstractModel {
addState(state);
}
/**
* @param states the subflow states to add
*/
public void addSubflowStates(LinkedList states) {
addStates(states);
}
/**
* @param state the end state to add
*/
@@ -504,13 +490,6 @@ public class FlowModel extends AbstractModel {
addState(state);
}
/**
* @param states the end states to add
*/
public void addEndStates(LinkedList states) {
addStates(states);
}
/**
* @return the global transitions
*/

View File

@@ -28,8 +28,11 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class IfModel extends AbstractModel {
private String test;
private String then;
private String elze;
/**

View File

@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class RenderModel extends AbstractActionModel {
private String fragments;
/**

View File

@@ -32,7 +32,9 @@ import org.springframework.webflow.security.SecurityFlowExecutionListener;
* @author Scott Andrews
*/
public class SecuredModel extends AbstractModel {
private String attributes;
private String match;
/**

View File

@@ -25,8 +25,11 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class SetModel extends AbstractActionModel {
private String name;
private String value;
private String type;
/**

View File

@@ -25,9 +25,13 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class SubflowStateModel extends AbstractTransitionableStateModel {
private String subflow;
private String subflowAttributeMapper;
private LinkedList inputs;
private LinkedList outputs;
/**
@@ -113,32 +117,6 @@ public class SubflowStateModel extends AbstractTransitionableStateModel {
this.inputs = inputs;
}
/**
* @param input the input mapping to add
*/
public void addInput(InputModel input) {
if (input == null) {
return;
}
if (inputs == null) {
inputs = new LinkedList();
}
inputs.add(input);
}
/**
* @param inputs the input mappings to add
*/
public void addInputs(LinkedList inputs) {
if (inputs == null || inputs.isEmpty()) {
return;
}
if (this.inputs == null) {
this.inputs = new LinkedList();
}
this.inputs.addAll(inputs);
}
/**
* @return the output mappings
*/
@@ -153,29 +131,4 @@ public class SubflowStateModel extends AbstractTransitionableStateModel {
this.outputs = outputs;
}
/**
* @param output the output mapping to add
*/
public void addOutput(OutputModel output) {
if (output == null) {
return;
}
if (outputs == null) {
outputs = new LinkedList();
}
outputs.add(output);
}
/**
* @param outputs the output mappings to add
*/
public void addOutputs(LinkedList outputs) {
if (outputs == null || outputs.isEmpty()) {
return;
}
if (this.outputs == null) {
this.outputs = new LinkedList();
}
this.outputs.addAll(outputs);
}
}
}

View File

@@ -30,13 +30,21 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class TransitionModel extends AbstractModel {
private String on;
private String onException;
private String to;
private String bind;
private String history;
private LinkedList attributes;
private SecuredModel secured;
private LinkedList actions;
/**
@@ -168,32 +176,6 @@ public class TransitionModel extends AbstractModel {
this.attributes = attributes;
}
/**
* @param attribute the attribute to add
*/
public void addAttribute(AttributeModel attribute) {
if (attribute == null) {
return;
}
if (attributes == null) {
attributes = new LinkedList();
}
attributes.add(attribute);
}
/**
* @param attributes the attributes to add
*/
public void addAttributes(LinkedList attributes) {
if (attributes == null || attributes.isEmpty()) {
return;
}
if (this.attributes == null) {
this.attributes = new LinkedList();
}
this.attributes.addAll(attributes);
}
/**
* @return the secured
*/
@@ -221,30 +203,4 @@ public class TransitionModel extends AbstractModel {
public void setActions(LinkedList actions) {
this.actions = actions;
}
/**
* @param action the action to add
*/
public void addAction(AbstractActionModel action) {
if (action == null) {
return;
}
if (actions == null) {
actions = new LinkedList();
}
actions.add(action);
}
/**
* @param actions the actions to add
*/
public void addActions(LinkedList actions) {
if (actions == null || actions.isEmpty()) {
return;
}
if (this.actions == null) {
this.actions = new LinkedList();
}
this.actions.addAll(actions);
}
}
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.webflow.engine.model;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
@@ -26,7 +27,9 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class VarModel extends AbstractModel {
private String name;
private String className;
/**
@@ -40,11 +43,16 @@ public class VarModel extends AbstractModel {
}
public boolean isMergeableWith(Model model) {
return false;
if (!(model instanceof VarModel)) {
return false;
}
VarModel var = (VarModel) model;
return ObjectUtils.nullSafeEquals(getName(), var.getName());
}
public void merge(Model model) {
VarModel var = (VarModel) model;
setClassName(merge(getClassName(), var.getClassName()));
}
/**

View File

@@ -26,11 +26,19 @@ import org.springframework.util.StringUtils;
* @author Scott Andrews
*/
public class ViewStateModel extends AbstractTransitionableStateModel {
private String view;
private String redirect;
private String popup;
private String model;
private LinkedList vars;
private LinkedList bindings;
private LinkedList onRenderActions;
/**
@@ -63,6 +71,7 @@ public class ViewStateModel extends AbstractTransitionableStateModel {
setPopup(merge(getPopup(), state.getPopup()));
setModel(merge(getModel(), state.getModel()));
setVars(merge(getVars(), state.getVars(), false));
setBindings(merge(getBindings(), state.getBindings(), false));
setOnRenderActions(merge(getOnRenderActions(), state.getOnRenderActions(), false));
}
@@ -166,16 +175,30 @@ public class ViewStateModel extends AbstractTransitionableStateModel {
}
/**
* @param vars the vars to add
* @return the bindings
*/
public void addVars(LinkedList vars) {
if (vars == null || vars.isEmpty()) {
public LinkedList getBindings() {
return bindings;
}
/**
* @param bindings the bindings to set
*/
public void setBindings(LinkedList bindings) {
this.bindings = bindings;
}
/**
* @param var the var to add
*/
public void addBinding(BindingModel binding) {
if (binding == null) {
return;
}
if (this.vars == null) {
this.vars = new LinkedList();
if (bindings == null) {
bindings = new LinkedList();
}
this.vars.addAll(vars);
bindings.add(binding);
}
/**
@@ -191,31 +214,4 @@ public class ViewStateModel extends AbstractTransitionableStateModel {
public void setOnRenderActions(LinkedList onRenderActions) {
this.onRenderActions = onRenderActions;
}
/**
* @param onRenderAction the on render action to add
*/
public void addOnRenderAction(AbstractActionModel onRenderAction) {
if (onRenderAction == null) {
return;
}
if (this.onRenderActions == null) {
this.onRenderActions = new LinkedList();
}
this.onRenderActions.add(onRenderAction);
}
/**
* @param onRenderActions the on render actions to add
*/
public void addOnRenderActions(LinkedList onRenderActions) {
if (onRenderActions == null || onRenderActions.isEmpty()) {
return;
}
if (this.onRenderActions == null) {
this.onRenderActions = new LinkedList();
}
this.onRenderActions.addAll(onRenderActions);
}
}

View File

@@ -33,6 +33,7 @@ import org.springframework.webflow.engine.model.AbstractStateModel;
import org.springframework.webflow.engine.model.ActionStateModel;
import org.springframework.webflow.engine.model.AttributeModel;
import org.springframework.webflow.engine.model.BeanImportModel;
import org.springframework.webflow.engine.model.BindingModel;
import org.springframework.webflow.engine.model.DecisionStateModel;
import org.springframework.webflow.engine.model.EndStateModel;
import org.springframework.webflow.engine.model.EvaluateModel;
@@ -517,6 +518,22 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
}
}
private LinkedList parseBindings(Element element) {
List bindingElements = DomUtils.getChildElementsByTagName(element, "binding");
if (bindingElements.isEmpty()) {
return null;
}
LinkedList bindings = new LinkedList();
for (Iterator it = bindingElements.iterator(); it.hasNext();) {
bindings.add(parseBinding((Element) it.next()));
}
return bindings;
}
private BindingModel parseBinding(Element element) {
return new BindingModel(element.getAttribute("property"), element.getAttribute("converter"));
}
private LinkedList parseOnExitActions(Element element) {
Element onExitElement = DomUtils.getChildElementByTagName(element, "on-exit");
if (onExitElement != null) {
@@ -577,6 +594,7 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
state.setPopup(element.getAttribute("popup"));
state.setModel(element.getAttribute("model"));
state.setVars(parseVars(element));
state.setBindings(parseBindings(element));
state.setOnRenderActions(parseOnRenderActions(element));
state.setAttributes(parseAttributes(element));
state.setSecured(parseSecured(element));

View File

@@ -321,6 +321,35 @@ The name of this variable.
<![CDATA[
The name of this variable's implementation class. The class name may be an alias (e.g 'int') or the
fully-qualified class name (e.g. 'java.lang.Integer'). The class must be a concrete class.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="binding" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
A view model binding. A binding connects a UI element in this view to a model property.
]]>
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="property" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The name of the model property to bind to.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="converter" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The name of a custom converter to use to format the property for display in the UI.
]]>
</xsd:documentation>
</xsd:annotation>

View File

@@ -72,15 +72,15 @@ public class FlowModelTests extends TestCase {
}
public void testMergeVars() {
FlowModel child = new FlowModel();
FlowModel parent = new FlowModel();
VarModel var = new VarModel("name", "value");
parent.addVar(var);
FlowModel child = new FlowModel();
var = new VarModel("name", "value2");
child.addVar(var);
parent.addVar(var);
var = new VarModel("name", "value");
parent.addVar(var);
child.merge(parent);
assertEquals(3, child.getVars().size());
assertEquals(1, child.getVars().size());
assertEquals("value2", ((VarModel) child.getVars().get(0)).getClassName());
}
public void testMergeMappings() {

View File

@@ -22,9 +22,8 @@ import junit.framework.TestCase;
*/
public class VarModelTests extends TestCase {
public void testNotMergeable() {
public void testMergeable() {
VarModel child = new VarModel("name", "value");
assertFalse(child.isMergeableWith(child));
assertTrue(child.isMergeableWith(child));
}
}

View File

@@ -14,6 +14,7 @@ import org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder;
import org.springframework.webflow.engine.impl.FlowExecutionImplFactory;
import org.springframework.webflow.engine.model.AbstractStateModel;
import org.springframework.webflow.engine.model.AttributeModel;
import org.springframework.webflow.engine.model.BindingModel;
import org.springframework.webflow.engine.model.ExceptionHandlerModel;
import org.springframework.webflow.engine.model.FlowModel;
import org.springframework.webflow.engine.model.SecuredModel;
@@ -143,6 +144,18 @@ public class XmlFlowModelBuilderTests extends TestCase {
assertEquals("foo", ((VarModel) ((ViewStateModel) flow.getStates().get(0)).getVars().get(0)).getName());
}
public void testViewStateModelBinding() {
ClassPathResource resource = new ClassPathResource("flow-viewstate-model-binding.xml", getClass());
FlowModelBuilder builder = new XmlFlowModelBuilder(resource, registry);
builder.init();
builder.build();
FlowModel flow = builder.getFlowModel();
ViewStateModel model = (ViewStateModel) flow.getStates().get(0);
assertEquals("formObject", model.getModel());
assertEquals("objectProperty", ((BindingModel) model.getBindings().get(0)).getProperty());
assertEquals("customConverter", ((BindingModel) model.getBindings().get(0)).getConverter());
}
public void testViewStateRedirect() {
ClassPathResource resource = new ClassPathResource("flow-viewstate-redirect.xml", getClass());
FlowModelBuilder builder = new XmlFlowModelBuilder(resource, registry);

View File

@@ -0,0 +1,9 @@
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<view-state id="form" model="formObject">
<binding property="objectProperty" converter="customConverter"/>
</view-state>
</flow>