| 1 | package de.uka.ipd.sdq.pcm.transformations.builder.infrastructure; |
| 2 | |
| 3 | import de.uka.ipd.sdq.pcm.core.CoreFactory; |
| 4 | import de.uka.ipd.sdq.pcm.parameter.ParameterFactory; |
| 5 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
| 6 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisationType; |
| 7 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
| 8 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
| 9 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
| 10 | import de.uka.ipd.sdq.pcm.repository.Signature; |
| 11 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
| 12 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.DelegatorComponentSeffBuilder; |
| 13 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.MiddlewareComponentSeffBuilder; |
| 14 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.SetVariableActionDescriptor; |
| 15 | import de.uka.ipd.sdq.pcm.transformations.builder.util.PCMAndCompletionModelHolder; |
| 16 | import de.uka.ipd.sdq.stoex.StoexFactory; |
| 17 | import de.uka.ipd.sdq.stoex.VariableReference; |
| 18 | |
| 19 | public class MiddlewareCallingComponentBuilder extends |
| 20 | BasicMiddlewareComponentBuilder { |
| 21 | |
| 22 | private OperationSignature preSignature; |
| 23 | private OperationSignature postSignature; |
| 24 | |
| 25 | public MiddlewareCallingComponentBuilder( |
| 26 | PCMAndCompletionModelHolder models, |
| 27 | OperationInterface providedIf, |
| 28 | OperationInterface requiredIf, |
| 29 | OperationInterface middlewareInterface, |
| 30 | ResourceContainer container, |
| 31 | String preServiceName, |
| 32 | String postServiceName) { |
| 33 | super(models, providedIf, requiredIf, middlewareInterface, container, "MiddlewareCallingComponent"); |
| 34 | this.preSignature = preServiceName == null ? null : findService(middlewareInterface,preServiceName); |
| 35 | this.postSignature = postServiceName == null ? null : findService(middlewareInterface,postServiceName); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | protected DelegatorComponentSeffBuilder getSeffBuilder() { |
| 40 | MiddlewareComponentSeffBuilder builder = (MiddlewareComponentSeffBuilder) super.getSeffBuilder(); |
| 41 | if (preSignature != null) |
| 42 | builder.appendPreMiddlewareCall( |
| 43 | preSignature); |
| 44 | if (postSignature != null) |
| 45 | builder.appendPostMiddlewareCall( |
| 46 | postSignature); |
| 47 | builder.appendPostAction(new SetVariableActionDescriptor( |
| 48 | createVariableUsage("stream", VariableCharacterisationType.BYTESIZE, "stream.BYTESIZE"))); |
| 49 | |
| 50 | return builder; |
| 51 | } |
| 52 | |
| 53 | private OperationSignature findService(OperationInterface middlewareInterface, |
| 54 | String preServiceName) { |
| 55 | for (OperationSignature sig : middlewareInterface.getSignatures__OperationInterface()){ |
| 56 | if (sig.getEntityName().equals(preServiceName)) |
| 57 | return sig; |
| 58 | } |
| 59 | throw new RuntimeException("Required middleware service not found in middleware interface"); |
| 60 | } |
| 61 | |
| 62 | protected VariableUsage createVariableUsage(String variableName, VariableCharacterisationType type, String spec) { |
| 63 | VariableUsage usage = ParameterFactory.eINSTANCE.createVariableUsage(); |
| 64 | VariableCharacterisation characterisation = ParameterFactory.eINSTANCE.createVariableCharacterisation(); |
| 65 | VariableReference name = StoexFactory.eINSTANCE.createVariableReference(); |
| 66 | name.setReferenceName(variableName); |
| 67 | characterisation.setSpecification_VariableCharacterisation(CoreFactory.eINSTANCE.createPCMRandomVariable()); |
| 68 | characterisation.getSpecification_VariableCharacterisation().setSpecification(spec); |
| 69 | characterisation.setType(type); |
| 70 | usage.setNamedReference__VariableUsage(name); |
| 71 | usage.getVariableCharacterisation_VariableUsage().add(characterisation); |
| 72 | |
| 73 | return usage; |
| 74 | } |
| 75 | } |