View Javadoc
1 package org.smartcomps.twister.engine.priv.core.dynamic.impl; 2 3 import org.smartcomps.twister.engine.priv.core.dynamic.InvokeEC; 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.Invoke; 7 import org.smartcomps.twister.engine.priv.core.definition.CorrelationRef; 8 import org.smartcomps.twister.engine.priv.core.definition.ActivityFactory; 9 import org.smartcomps.twister.engine.priv.messaging.MessagingFactory; 10 import org.smartcomps.twister.engine.priv.util.CorrelationExtractor; 11 import org.smartcomps.twister.engine.exception.UninitializedVariableException; 12 import org.smartcomps.twister.engine.exception.ExecutionException; 13 import org.smartcomps.twister.common.persistence.FinderException; 14 import org.smartcomps.twister.engine.exception.SelectionFailureException; 15 import org.smartcomps.twister.engine.exception.CorrelationViolationException; 16 import org.smartcomps.twister.common.persistence.XMLSessionException; 17 import org.smartcomps.twister.common.persistence.DBSessionException; 18 import org.dom4j.Element; 19 import org.dom4j.Document; 20 import org.dom4j.DocumentHelper; 21 22 import java.security.InvalidParameterException; 23 import java.util.Iterator; 24 import java.util.Map; 25 26 /*** 27 * Persistent implementation of the InvokeEC interface. 28 */ 29 public class InvokeECImpl extends BasicECImpl implements InvokeEC { 30 31 public void execute() { 32 this.setStatus(ACTIVE); 33 34 // Notify the container for execution 35 notifyExecutionToContainer(); 36 37 Invoke origin = (Invoke) getInitialActivity(); 38 39 // Getting input variable and setting input correlations if some have to be 40 // initiated. 41 Document inputVar = getInput(origin); 42 setCorrelations(origin, inputVar, CorrelationRef.OUT); 43 if (origin.getOutputVariable() == null || origin.getOutputVariable().length() == 0) { 44 // No output variable : asynchronous invocation 45 MessagingFactory.getMessageBroker().asyncInvoke(origin.getPartner(), origin.getPortType(), 46 origin.getOperation(), inputVar); 47 } else { 48 // Getting output variable and setting output correlations if some have to be 49 // initiated. 50 Document outputVar = MessagingFactory.getMessageBroker().syncInvoke(origin.getPartner(), 51 origin.getPortType(), origin.getOperation(), inputVar); 52 setCorrelations(origin, outputVar, CorrelationRef.IN); 53 // Synchronous invocation 54 try { 55 VariableXAO.createVariable(origin.fetchProcess().getName(), origin.getOutputVariable(), 56 fetchInstance().getId(), outputVar); 57 } catch (XMLSessionException e) { 58 throw new ExecutionException("An error occured when trying to create a new variable" + 59 " from an invocation return value", e); 60 } 61 } 62 63 // Notify container for termintation 64 notifyTerminationToContainer(); 65 66 // Terminate this activity 67 this.setStatus(COMPLETED); 68 } 69 70 private Document getInput(Invoke origin) { 71 Document inputVar = null; 72 if (origin.getInputVariable() != null && origin.getInputVariable().length() > 0) { 73 try { 74 inputVar = VariableXAO.getVariable(origin.fetchProcess().getName(), 75 origin.getInputVariable(), fetchInstance().getId()); 76 } catch (XMLSessionException e) { 77 throw new UninitializedVariableException("The invoke execution context " + getId() + 78 "references a variable that hasn't been initialized yet " + origin.getInputVariable(), e); 79 } catch (FinderException e) { 80 throw new SelectionFailureException(e); 81 } 82 } 83 return inputVar; 84 } 85 86 private void setCorrelations(Invoke origin, Document variable, int correlationMode) { 87 for (Iterator correlIter = origin.getCorrelations().iterator(); correlIter.hasNext();) { 88 CorrelationRef ref = (CorrelationRef) correlIter.next(); 89 if (ref.isInitiate() && (ref.getPattern() == correlationMode || ref.getPattern() == CorrelationRef.OUT_IN)) { 90 if (variable == null) { 91 throw new UninitializedVariableException("The correlation set " + ref.getSet() + 92 " is declared as initiate but the associated variable " + origin.getInputVariable() + 93 " has not been initiated."); 94 } else { 95 try { 96 Map corrValues = CorrelationExtractor.extractCorrelationValues( 97 origin.fetchProcess(), ref, variable); 98 ProcessInstanceFactory.addCorrelation(fetchInstance(), ref.getSet(), corrValues); 99 } catch (DBSessionException e) { 100 throw new ExecutionException(e); 101 } catch (XMLSessionException e) { 102 throw new ExecutionException(e); 103 } catch (CorrelationViolationException e) { 104 throw new ExecutionException(e); 105 } 106 } 107 } 108 } 109 } 110 }

This page was automatically generated by Maven