| 1 | package de.uka.ipd.sdq.pcm.transformations.builder.seff; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collections; |
| 5 | import java.util.List; |
| 6 | |
| 7 | import de.uka.ipd.sdq.completions.CompletionsFactory; |
| 8 | import de.uka.ipd.sdq.completions.DelegatingExternalCallAction; |
| 9 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
| 10 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
| 11 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
| 12 | import de.uka.ipd.sdq.pcm.repository.Signature; |
| 13 | import de.uka.ipd.sdq.pcm.seff.AbstractAction; |
| 14 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
| 15 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
| 16 | import de.uka.ipd.sdq.pcm.seff.StartAction; |
| 17 | import de.uka.ipd.sdq.pcm.seff.StopAction; |
| 18 | |
| 19 | /** |
| 20 | * A builder which builds identical SEFFs for all services contained in the passed interface. Useful for creating components which delegate their |
| 21 | * call to other components |
| 22 | * @author Snowball |
| 23 | * |
| 24 | */ |
| 25 | public class DelegatorComponentSeffBuilder extends AbstractSeffBuilder |
| 26 | implements ISeffBuilder { |
| 27 | |
| 28 | protected ArrayList<AbstractActionDescriptor> preActions = new ArrayList<AbstractActionDescriptor>(); |
| 29 | protected ArrayList<AbstractActionDescriptor> postActions = new ArrayList<AbstractActionDescriptor>(); |
| 30 | protected OperationRequiredRole domainReqRole; |
| 31 | protected OperationProvidedRole domainProvRole; |
| 32 | private ArrayList<ResourceDemandingSEFF> createdSeffs = new ArrayList<ResourceDemandingSEFF>(); |
| 33 | |
| 34 | public DelegatorComponentSeffBuilder(OperationProvidedRole domainProvRole, OperationRequiredRole domainReqRole) { |
| 35 | this.domainReqRole = domainReqRole; |
| 36 | this.domainProvRole = domainProvRole; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Append an internal action in the chain of actions to be executed before the delegating call |
| 41 | * @param signatureDependentDemand A description of the internal action's demand |
| 42 | */ |
| 43 | public void appendPreAction( |
| 44 | AbstractActionDescriptor signatureDependentDemand) { |
| 45 | this.preActions.add(signatureDependentDemand); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Append an internal action in the chain of actions to be executed after the delegating call |
| 50 | * @param signatureDependentDemand A description of the internal action's demand |
| 51 | */ |
| 52 | public void appendPostAction( |
| 53 | AbstractActionDescriptor signatureDependentDemand) { |
| 54 | this.postActions.add(signatureDependentDemand); |
| 55 | } |
| 56 | |
| 57 | public void build() { |
| 58 | for (OperationSignature providedService : domainProvRole.getProvidedInterface__OperationProvidedRole().getSignatures__OperationInterface()){ |
| 59 | ResourceDemandingSEFF seff = buildSeff(providedService); |
| 60 | this.createdSeffs.add(seff); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | @Override |
| 66 | protected ResourceDemandingSEFF buildSeff(OperationSignature signature) { |
| 67 | ResourceDemandingSEFF seff = super.buildSeff(signature); |
| 68 | StartAction start = SeffFactory.eINSTANCE.createStartAction(); |
| 69 | AbstractAction lastAction = start; |
| 70 | |
| 71 | setSignatureInActions(preActions,signature); |
| 72 | setSignatureInActions(postActions,signature); |
| 73 | |
| 74 | for (AbstractActionDescriptor descriptor : preActions) { |
| 75 | AbstractAction action = descriptor.createAction(); |
| 76 | lastAction = createControlFlow(lastAction,action); |
| 77 | seff.getSteps_Behaviour().add(action); |
| 78 | } |
| 79 | |
| 80 | DelegatingExternalCallAction delegatingCall = CompletionsFactory.eINSTANCE.createDelegatingExternalCallAction(); |
| 81 | delegatingCall.setCalledService_ExternalService(signature); |
| 82 | delegatingCall.setRole_ExternalService(domainReqRole); |
| 83 | lastAction = createControlFlow(lastAction, delegatingCall); |
| 84 | |
| 85 | for (AbstractActionDescriptor descriptor : postActions) { |
| 86 | AbstractAction action = descriptor.createAction(); |
| 87 | lastAction = createControlFlow(lastAction,action); |
| 88 | seff.getSteps_Behaviour().add(action); |
| 89 | } |
| 90 | |
| 91 | StopAction stop = SeffFactory.eINSTANCE.createStopAction(); |
| 92 | createControlFlow(lastAction, stop); |
| 93 | |
| 94 | Collections.addAll(seff.getSteps_Behaviour(), start,stop,delegatingCall); |
| 95 | |
| 96 | return seff; |
| 97 | } |
| 98 | |
| 99 | private void setSignatureInActions( |
| 100 | ArrayList<AbstractActionDescriptor> actions, OperationSignature sig) { |
| 101 | for (AbstractActionDescriptor descriptor : actions) { |
| 102 | if (descriptor instanceof ISignatureDependentAction) { |
| 103 | ISignatureDependentAction sigDescriptor = (ISignatureDependentAction) descriptor; |
| 104 | sigDescriptor.setCurrentSignature(sig); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | /* (non-Javadoc) |
| 111 | * @see de.uka.sdq.pcm.transformations.builder.seff.ISeffBuilder#getSeff(de.uka.ipd.sdq.pcm.repository.Signature) |
| 112 | */ |
| 113 | public List<ResourceDemandingSEFF> getSeffs() { |
| 114 | return Collections.unmodifiableList(this.createdSeffs); |
| 115 | } |
| 116 | } |