1 package com.opensymphony.workflow.loader; 2 3 import com.opensymphony.workflow.designer.Utils; 4 import com.opensymphony.workflow.designer.WorkflowGraphModel; 5 6 10 public class DescriptorBuilder 11 { 12 public static StepDescriptor createStep(String name, int id) 13 { 14 StepDescriptor step = new StepDescriptor(); 15 step.setName(name); 16 step.setId(id); 17 return step; 18 } 19 20 public static ActionDescriptor createAction(StepDescriptor step, String name, int id) 21 { 22 ActionDescriptor action = new ActionDescriptor(); 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 { 34 JoinDescriptor join = new JoinDescriptor(); 35 join.setId(id); 36 return join; 37 } 38 39 public static SplitDescriptor createSplit(int id) 40 { 41 SplitDescriptor split = new SplitDescriptor(); 42 split.setId(id); 43 return split; 44 } 45 46 public static ResultDescriptor createResult(WorkflowGraphModel model, AbstractDescriptor desc) 47 { 48 ResultDescriptor result = new ResultDescriptor(); 49 Utils.checkId(model.getContext(), desc); 50 if(result.getId()==0) 51 result.setId(Utils.getNextId(model.getContext())); 52 result.setOldStatus(model.getPalette().getDefaultOldStatus()); 53 result.setStatus(model.getPalette().getDefaultNextStatus()); 54 if(desc instanceof StepDescriptor) 55 { 56 result.setStep(desc.getId()); 57 } 58 else if(desc instanceof SplitDescriptor) 59 { 60 result.setSplit(desc.getId()); 61 } 62 else if(desc instanceof JoinDescriptor) 63 { 64 result.setJoin(desc.getId()); 65 } 66 else 67 { 68 return null; 69 } 70 return result; 71 } 72 73 public static ConditionalResultDescriptor createConditionalResult(WorkflowGraphModel model, AbstractDescriptor desc) 74 { 75 ConditionalResultDescriptor result = new ConditionalResultDescriptor(); 76 Utils.checkId(model.getContext(), desc); 77 if(result.getId()==0) 78 result.setId(Utils.getNextId(model.getContext())); 79 result.setOldStatus(model.getPalette().getDefaultOldStatus()); 80 result.setStatus(model.getPalette().getDefaultNextStatus()); 81 if(desc instanceof StepDescriptor) 82 { 83 result.setStep(desc.getId()); 84 } 85 else if(desc instanceof SplitDescriptor) 86 { 87 result.setSplit(desc.getId()); 88 } 89 else if(desc instanceof JoinDescriptor) 90 { 91 result.setJoin(desc.getId()); 92 } 93 else 94 { 95 return null; 96 } 97 98 return result; 99 } 100 } 101 | Popular Tags |