View Javadoc
1 package org.smartcomps.twister.engine.priv.core.dynamic.impl; 2 3 import org.smartcomps.twister.engine.priv.core.dynamic.ReplyEC; 4 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory; 5 import org.smartcomps.twister.engine.priv.core.dynamic.impl.xao.VariableXAO; 6 import org.smartcomps.twister.engine.priv.core.definition.CorrelationRef; 7 import org.smartcomps.twister.engine.priv.core.definition.Reply; 8 import org.smartcomps.twister.engine.priv.messaging.MessagingFactory; 9 import org.smartcomps.twister.engine.priv.util.CorrelationExtractor; 10 11 import org.smartcomps.twister.engine.exception.ExecutionException; 12 import org.smartcomps.twister.engine.exception.UninitializedVariableException; 13 import org.smartcomps.twister.engine.exception.SelectionFailureException; 14 import org.smartcomps.twister.engine.exception.CorrelationViolationException; 15 16 import org.smartcomps.twister.common.persistence.XMLSessionException; 17 import org.smartcomps.twister.common.persistence.FinderException; 18 import org.smartcomps.twister.common.persistence.DBSessionException; 19 20 import org.dom4j.Document; 21 22 import java.util.Iterator; 23 import java.util.Map; 24 25 /*** 26 * Persistent implementation of the ReplyEC interface. 27 */ 28 public class ReplyECImpl extends BasicECImpl implements ReplyEC { 29 30 public void execute() { 31 this.setStatus(ACTIVE); 32 33 // Notify the container for execution 34 notifyExecutionToContainer(); 35 36 Reply origin = (Reply) getInitialActivity(); 37 38 // Getting variable and input correlations if some have to be initiated. 39 Document var = getVariable(origin); 40 setCorrelations(origin, var, CorrelationRef.OUT); 41 MessagingFactory.getMessageBroker().asyncInvoke(origin.getPartner(), origin.getPortType(), 42 origin.getOperation(), var); 43 44 // Notify container for termintation 45 notifyTerminationToContainer(); 46 47 // Terminate this activity 48 this.setStatus(COMPLETED); 49 } 50 51 private Document getVariable(Reply origin) { 52 Document variable = null; 53 if (origin.getVariable() != null && origin.getVariable().length() > 0) { 54 try { 55 variable = VariableXAO.getVariable(origin.fetchProcess().getName(), 56 origin.getVariable(), fetchInstance().getId()); 57 } catch (XMLSessionException e) { 58 throw new UninitializedVariableException("The reply execution context " + getId() + 59 "references a variable that hasn't been initialized yet " + origin.getVariable(), e); 60 } catch (FinderException e) { 61 throw new SelectionFailureException(e); 62 } 63 } 64 return variable; 65 } 66 67 private void setCorrelations(Reply origin, Document variable, int correlationMode) { 68 for (Iterator correlIter = origin.getCorrelations().iterator(); correlIter.hasNext();) { 69 CorrelationRef ref = (CorrelationRef) correlIter.next(); 70 if (ref.isInitiate() && ref.getPattern() == correlationMode) { 71 if (variable == null) { 72 throw new UninitializedVariableException("The correlation set " + ref.getSet() + 73 " is declared as initiate but the associated variable " + origin.getVariable() + 74 " has not been initiated."); 75 } else { 76 try { 77 Map corrValues = CorrelationExtractor.extractCorrelationValues( 78 origin.fetchProcess(), ref, variable); 79 ProcessInstanceFactory.addCorrelation(fetchInstance(), ref.getSet(), corrValues); 80 } catch (DBSessionException e) { 81 throw new ExecutionException(e); 82 } catch (XMLSessionException e) { 83 throw new ExecutionException(e); 84 } catch (CorrelationViolationException e) { 85 throw new ExecutionException(e); 86 } 87 } 88 } 89 } 90 } 91 92 }

This page was automatically generated by Maven