IN PROGRESS - issue SWF-550: Allow FlowModels to be marked abstract

http://jira.springframework.org/browse/SWF-550
This commit is contained in:
Scott Andrews
2008-03-24 16:22:46 +00:00
parent c39f75bc07
commit 2cf1c71861
5 changed files with 42 additions and 0 deletions

View File

@@ -112,6 +112,9 @@ public class FlowModelFlowBuilder extends AbstractFlowBuilder {
*/
protected void doInit() throws FlowBuilderException {
flowModel = flowModelHolder.getFlowModel();
if ("true".equals(flowModel.getAbstract())) {
throw new FlowBuilderException("Abstract flow models cannot be instantiated.");
}
initLocalFlowContext();
}

View File

@@ -47,6 +47,7 @@ import org.springframework.util.StringUtils;
*/
public class FlowModel extends AbstractModel {
// private String id;
private String abztract;
private String parent;
private String startStateId;
private LinkedList attributes;
@@ -94,6 +95,24 @@ public class FlowModel extends AbstractModel {
setBeanImports(merge(getBeanImports(), flow.getBeanImports()));
}
/**
* @return the abstract
*/
public String getAbstract() {
return abztract;
}
/**
* @param abztract the abstract to set
*/
public void setAbstract(String abztract) {
if (StringUtils.hasText(abztract)) {
this.abztract = abztract;
} else {
this.abztract = null;
}
}
/**
* @return the parent
*/

View File

@@ -220,6 +220,7 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
private FlowModel parseFlow(Element element) {
FlowModel flow = new FlowModel();
flow.setAbstract(element.getAttribute("abstract"));
flow.setParent(element.getAttribute("parent"));
flow.setStartStateId(element.getAttribute("start-state"));
flow.addAttributes(parseAttributes(element));

View File

@@ -1012,6 +1012,15 @@ For example:
<xsd:documentation>
<![CDATA[
The starting point of this flow. If not specified, the start state is the first state defined in this document.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="abstract" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Marks a flow model as abstract, preventing it from instantiating as a flow definition.
]]>
</xsd:documentation>
</xsd:annotation>

View File

@@ -326,6 +326,16 @@ public class FlowModelFlowBuilderTests extends TestCase {
assertEquals("end", flow.getStartState().getId());
}
public void testAbstractFlow() {
model.setAbstract("true");
try {
getFlow(model);
fail("FlowBuilderException expected");
} catch (FlowBuilderException e) {
// we want this
}
}
private Flow getFlow(FlowModel model) {
FlowModelHolder holder = new StaticFlowModelHolder(model);
FlowModelFlowBuilder builder = new FlowModelFlowBuilder(holder);