01: package com.opensymphony.workflow.loader;
02:
03: import com.opensymphony.workflow.designer.Utils;
04: import com.opensymphony.workflow.designer.WorkflowGraphModel;
05:
06: /**
07: * @author jackflit
08: * Date: 2003-11-18
09: */
10: public class DescriptorBuilder {
11: public static StepDescriptor createStep(String name, int id) {
12: StepDescriptor step = DescriptorFactory.getFactory()
13: .createStepDescriptor();
14: step.setName(name);
15: step.setId(id);
16: return step;
17: }
18:
19: public static ActionDescriptor createAction(StepDescriptor step,
20: String name, int id) {
21: ActionDescriptor action = DescriptorFactory.getFactory()
22: .createActionDescriptor();
23: step.getActions().add(action);
24: action.setParent(step);
25: action.setAutoExecute(false);
26: action.setId(id);
27: action.setName(name);
28: action.setView(name);
29: return action;
30: }
31:
32: public static JoinDescriptor createJoin(int id) {
33: JoinDescriptor join = DescriptorFactory.getFactory()
34: .createJoinDescriptor();
35: join.setId(id);
36: return join;
37: }
38:
39: public static SplitDescriptor createSplit(int id) {
40: SplitDescriptor split = DescriptorFactory.getFactory()
41: .createSplitDescriptor();
42: split.setId(id);
43: return split;
44: }
45:
46: public static ResultDescriptor createResult(
47: WorkflowGraphModel model, AbstractDescriptor desc) {
48: ResultDescriptor result = DescriptorFactory.getFactory()
49: .createResultDescriptor();
50: Utils.checkId(model.getContext(), desc);
51: if (result.getId() == 0)
52: result.setId(Utils.getNextId(model.getContext()));
53: result.setOldStatus(model.getPalette().getDefaultOldStatus());
54: result.setStatus(model.getPalette().getDefaultNextStatus());
55: if (desc instanceof StepDescriptor) {
56: result.setStep(desc.getId());
57: } else if (desc instanceof SplitDescriptor) {
58: result.setSplit(desc.getId());
59: } else if (desc instanceof JoinDescriptor) {
60: result.setJoin(desc.getId());
61: } else {
62: return null;
63: }
64: return result;
65: }
66:
67: public static ConditionalResultDescriptor createConditionalResult(
68: WorkflowGraphModel model, AbstractDescriptor desc) {
69: ConditionalResultDescriptor result = DescriptorFactory
70: .getFactory().createConditionalResultDescriptor();
71: Utils.checkId(model.getContext(), desc);
72: if (result.getId() == 0)
73: result.setId(Utils.getNextId(model.getContext()));
74: result.setOldStatus(model.getPalette().getDefaultOldStatus());
75: result.setStatus(model.getPalette().getDefaultNextStatus());
76: if (desc instanceof StepDescriptor) {
77: result.setStep(desc.getId());
78: } else if (desc instanceof SplitDescriptor) {
79: result.setSplit(desc.getId());
80: } else if (desc instanceof JoinDescriptor) {
81: result.setJoin(desc.getId());
82: } else {
83: return null;
84: }
85:
86: return result;
87: }
88: }
|