1 | package de.uka.ipd.sdq.pcm.transformations.builder.seff; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Collection; |
5 | |
6 | import de.uka.ipd.sdq.pcm.core.CoreFactory; |
7 | import de.uka.ipd.sdq.pcm.parameter.ParameterFactory; |
8 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
9 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisationType; |
10 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
11 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
12 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
13 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
14 | import de.uka.ipd.sdq.stoex.StoexFactory; |
15 | import de.uka.ipd.sdq.stoex.VariableReference; |
16 | |
17 | public class MiddlewareComponentSeffBuilder extends DelegatorComponentSeffBuilder { |
18 | |
19 | protected OperationRequiredRole middlewareRole; |
20 | |
21 | public MiddlewareComponentSeffBuilder( |
22 | OperationProvidedRole domainProvRole, |
23 | OperationRequiredRole domainReqRole, |
24 | OperationRequiredRole middlewareReqRole) { |
25 | super(domainProvRole, domainReqRole); |
26 | this.middlewareRole = middlewareReqRole; |
27 | } |
28 | |
29 | public void appendPreMiddlewareCall(OperationSignature preSignature) { |
30 | this.appendPreAction( |
31 | new ExternalCallActionDescriptor( |
32 | preSignature, |
33 | this.middlewareRole, |
34 | createMiddlewareParameter(), |
35 | createOutParameter())); |
36 | } |
37 | |
38 | public void appendPostMiddlewareCall(OperationSignature postSignature) { |
39 | this.appendPostAction( |
40 | new ExternalCallActionDescriptor( |
41 | postSignature, |
42 | this.middlewareRole, |
43 | createMiddlewareParameter(), |
44 | createOutParameter())); |
45 | } |
46 | |
47 | protected Collection<VariableUsage> createMiddlewareParameter() { |
48 | Collection<VariableUsage> result = new ArrayList<VariableUsage>(); |
49 | result.add(createVariableUsage("stream", VariableCharacterisationType.BYTESIZE, "stream.BYTESIZE")); |
50 | return result; |
51 | } |
52 | |
53 | protected VariableUsage createVariableUsage(String variableName, VariableCharacterisationType type, String spec) { |
54 | VariableUsage usage = ParameterFactory.eINSTANCE.createVariableUsage(); |
55 | VariableCharacterisation characterisation = ParameterFactory.eINSTANCE.createVariableCharacterisation(); |
56 | VariableReference name = StoexFactory.eINSTANCE.createVariableReference(); |
57 | name.setReferenceName(variableName); |
58 | characterisation.setSpecification_VariableCharacterisation(CoreFactory.eINSTANCE.createPCMRandomVariable()); |
59 | characterisation.getSpecification_VariableCharacterisation().setSpecification(spec); |
60 | characterisation.setType(type); |
61 | usage.setNamedReference__VariableUsage(name); |
62 | usage.getVariableCharacterisation_VariableUsage().add(characterisation); |
63 | |
64 | return usage; |
65 | } |
66 | |
67 | private Collection<VariableUsage> createOutParameter() { |
68 | Collection<VariableUsage> result = new ArrayList<VariableUsage>(); |
69 | result.add(createVariableUsage("stream", VariableCharacterisationType.BYTESIZE, "RETURN.BYTESIZE")); |
70 | return result; |
71 | } |
72 | } |