View Javadoc
1 package org.smartcomps.twister.engine.priv.core.dynamic.impl; 2 3 import org.smartcomps.twister.engine.priv.core.definition.impl.ActivityImpl; 4 import org.smartcomps.twister.engine.priv.core.definition.Activity; 5 import org.smartcomps.twister.engine.priv.core.dynamic.*; 6 import org.smartcomps.twister.engine.priv.core.dynamic.impl.xao.VariableXAO; 7 import org.smartcomps.twister.engine.exception.ProcessStructuralException; 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import java.util.Collection; 12 import java.util.HashSet; 13 import java.util.Set; 14 15 /*** 16 * Please put some JavaDoc here. 17 */ 18 public abstract class ExecutionContextImpl implements ExecutionContext, Comparable { 19 20 private VariableXAO variableXAO = null; 21 private ExecutionContextFactory ecFactory = null; 22 protected static Log log = LogFactory.getLog(ExecutionContextImpl.class); 23 24 private Long id; 25 private int status; 26 private StructuredEC container; 27 private Set processInstance = new HashSet(); 28 private Collection events = new HashSet(); 29 30 // This is a purely technical field to indicate the position of the context within 31 // its container. It should be managed by Hibernate in the future but right now 32 // there's no other choice than this. 33 private int index; 34 35 public Long getId() { 36 return id; 37 } 38 39 public void setId(Long id) { 40 this.id = id; 41 } 42 43 public int getStatus() { 44 return status; 45 } 46 47 public void setStatus(int status) { 48 this.status = status; 49 } 50 51 public StructuredEC getContainer() { 52 return container; 53 } 54 55 public void setContainer(StructuredEC container) { 56 this.container = container; 57 } 58 59 public Collection getEvents() { 60 return events; 61 } 62 63 public void setEvents(Collection events) { 64 this.events = events; 65 } 66 67 public void addEvent(ExecutionEvent event) { 68 this.events.add(event); 69 } 70 71 public ProcessInstance getInstance() { 72 if (processInstance == null || processInstance.size() == 0) return null; 73 return (ProcessInstance) processInstance.iterator().next(); 74 } 75 76 public void setInstance(ProcessInstance instance) { 77 HashSet instSet = new HashSet(1); 78 instSet.add(instance); 79 this.processInstance = instSet; 80 } 81 82 /*** 83 * TECHNICAL, DO NOT USE 84 */ 85 protected Set getProcessInstance() { 86 return processInstance; 87 } 88 89 /*** 90 * TECHNICAL, DO NOT USE 91 */ 92 protected void setProcessInstance(Set processInstance) { 93 this.processInstance = processInstance; 94 } 95 96 /*** 97 * TECHNICAL, DO NOT USE 98 */ 99 public int getIndex() { 100 return index; 101 } 102 103 /*** 104 * TECHNICAL, DO NOT USE 105 */ 106 public void setIndex(int index) { 107 this.index = index; 108 } 109 110 /*** 111 * Gets this execution context initial activity (the one whose execution 112 * resulted in the creation of this execution context) passing through 113 * its parent container or process instance. 114 * @return Activity 115 */ 116 protected Activity getInitialActivity() { 117 Activity result = null; 118 if (this.getContainer() != null) { 119 result = this.getContainer().getActivityForChildContext(this); 120 } else if (this.getInstance() != null) { 121 result = this.getInstance().getProcess().getActivity(); 122 } else { 123 throw new ProcessStructuralException("An activity doesn't have any container nor " + 124 "process instance : " + this); 125 } 126 return result; 127 } 128 129 public ProcessInstance fetchInstance() { 130 if (this.getInstance() != null) { 131 return getInstance(); 132 } else { 133 StructuredEC container = getContainer(); 134 while (container.getInstance() == null) container = container.getContainer(); 135 return container.getInstance(); 136 } 137 } 138 139 protected void notifyExecutionToContainer() { 140 if (this.getContainer() != null) { 141 this.getContainer().notifyExecution(this); 142 } else if (this.getInstance() != null) { 143 this.getInstance().notifyExecution(this); 144 } else { 145 throw new ProcessStructuralException("An activity doesn't have any container nor " + 146 "process instance : " + this); 147 } 148 } 149 150 protected void notifyTerminationToContainer() { 151 if (this.getContainer() != null) { 152 this.getContainer().notifyTermination(this); 153 } else if (this.getInstance() != null) { 154 this.getInstance().notifyTermination(this); 155 } else { 156 throw new ProcessStructuralException("An activity doesn't have any container nor " + 157 "process instance : " + this); 158 } 159 } 160 161 protected void completeChildren(StructuredEC ec) { 162 for (int m = 0; m < ec.getExecutionContexts().size(); m++) { 163 ExecutionContext childContext = (ExecutionContext) ec.getExecutionContexts().get(m); 164 if (childContext.getStatus() == ExecutionContext.ACTIVE) { 165 childContext.setStatus(ExecutionContext.COMPLETED); 166 if (childContext instanceof StructuredEC) { 167 completeChildren((StructuredEC)childContext); 168 } 169 } 170 } 171 } 172 173 protected ExecutionContextFactory getExecutionContextFactory() { 174 if (ecFactory == null) { 175 ecFactory = new ExecutionContextFactory(); 176 } 177 return ecFactory; 178 } 179 180 protected VariableXAO getVariableXAO() { 181 if (variableXAO == null) { 182 variableXAO = new VariableXAO(); 183 } 184 return variableXAO; 185 } 186 187 public int compareTo(Object o) { 188 if (o instanceof ExecutionContextImpl) { 189 if (((ExecutionContextImpl)o).getIndex() > this.getIndex()) return -1; 190 else if (((ExecutionContextImpl)o).getIndex() == this.getIndex()) return 0; 191 else return 1; 192 } 193 return 0; 194 } 195 196 }

This page was automatically generated by Maven