EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcmsolver.transformations.pcm2regex]

COVERAGE SUMMARY FOR SOURCE FILE [TransformUsageModelVisitor.java]

nameclass, %method, %block, %line, %
TransformUsageModelVisitor.java0%   (0/1)0%   (0/12)0%   (0/314)0%   (0/88)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TransformUsageModelVisitor0%   (0/1)0%   (0/12)0%   (0/314)0%   (0/88)
<static initializer> 0%   (0/1)0%   (0/5)0%   (0/2)
TransformUsageModelVisitor (PCMInstance): void 0%   (0/1)0%   (0/15)0%   (0/6)
caseBranch (Branch): Object 0%   (0/1)0%   (0/56)0%   (0/12)
caseEntryLevelSystemCall (EntryLevelSystemCall): Object 0%   (0/1)0%   (0/84)0%   (0/18)
caseLoop (Loop): Object 0%   (0/1)0%   (0/34)0%   (0/8)
caseScenarioBehaviour (ScenarioBehaviour): Object 0%   (0/1)0%   (0/6)0%   (0/1)
caseStart (Start): Object 0%   (0/1)0%   (0/23)0%   (0/6)
caseStop (Stop): Object 0%   (0/1)0%   (0/9)0%   (0/3)
getDelegationConnector (OperationProvidedRole): ProvidedDelegationConnector 0%   (0/1)0%   (0/19)0%   (0/9)
getEntryExpression (EntryLevelSystemCall): Expression 0%   (0/1)0%   (0/39)0%   (0/13)
getSeff (Signature, BasicComponent): ServiceEffectSpecification 0%   (0/1)0%   (0/16)0%   (0/7)
getStartAction (ScenarioBehaviour): Start 0%   (0/1)0%   (0/8)0%   (0/3)

1package de.uka.ipd.sdq.pcmsolver.transformations.pcm2regex;
2 
3import java.util.ArrayList;
4import java.util.LinkedList;
5import java.util.List;
6 
7import org.apache.log4j.Logger;
8 
9import de.uka.ipd.sdq.pcm.core.composition.ProvidedDelegationConnector;
10import de.uka.ipd.sdq.pcm.repository.BasicComponent;
11import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole;
12import de.uka.ipd.sdq.pcm.repository.RepositoryComponent;
13import de.uka.ipd.sdq.pcm.repository.Signature;
14import de.uka.ipd.sdq.pcm.seff.AbstractBranchTransition;
15import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF;
16import de.uka.ipd.sdq.pcm.seff.ServiceEffectSpecification;
17import de.uka.ipd.sdq.pcm.usagemodel.Branch;
18import de.uka.ipd.sdq.pcm.usagemodel.BranchTransition;
19import de.uka.ipd.sdq.pcm.usagemodel.EntryLevelSystemCall;
20import de.uka.ipd.sdq.pcm.usagemodel.Loop;
21import de.uka.ipd.sdq.pcm.usagemodel.ScenarioBehaviour;
22import de.uka.ipd.sdq.pcm.usagemodel.Start;
23import de.uka.ipd.sdq.pcm.usagemodel.Stop;
24import de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelSwitch;
25import de.uka.ipd.sdq.pcmsolver.models.PCMInstance;
26import de.uka.ipd.sdq.pcmsolver.transformations.ContextWrapper;
27import de.uka.ipd.sdq.pcmsolver.visitors.EMFQueryHelper;
28import de.uka.ipd.sdq.probfunction.math.IProbabilityFunctionFactory;
29import de.uka.ipd.sdq.spa.expression.Alternative;
30import de.uka.ipd.sdq.spa.expression.Expression;
31import de.uka.ipd.sdq.spa.expression.ExpressionFactory;
32import de.uka.ipd.sdq.spa.expression.Option;
33import de.uka.ipd.sdq.spa.expression.Sequence;
34import de.uka.ipd.sdq.spa.expression.Symbol;
35import de.uka.ipd.sdq.stoex.RandomVariable;
36 
37public class TransformUsageModelVisitor extends UsagemodelSwitch {
38        
39        private static Logger logger = Logger.getLogger(TransformUsageModelVisitor.class.getName());
40        
41        private ExpressionFactory expFactory = ExpressionFactory.eINSTANCE;
42        private IProbabilityFunctionFactory pfFactory = IProbabilityFunctionFactory.eINSTANCE;
43        
44        private PCMInstance pcmInstance;
45        private ContextWrapper myContextWrapper = null;
46        
47        public TransformUsageModelVisitor(PCMInstance pcm){
48                pcmInstance = pcm;
49        }
50 
51        @Override
52        public Object caseStart(Start object) {
53                Symbol sym = expFactory.createSymbol();
54                sym.setName("Start");
55        
56                Sequence seq = expFactory.createSequence();
57                seq.setLeftRegExp(sym);
58                seq.setRightRegExp((Expression)doSwitch(object.getSuccessor()));
59        
60                return seq;
61        }
62 
63        @Override
64        public Object caseStop(Stop object) {
65                Symbol sym = expFactory.createSymbol();
66                sym.setName("Stop");
67                return sym;
68        }
69 
70        @Override
71        public Object caseEntryLevelSystemCall(EntryLevelSystemCall object) {
72                // Get List of ContextWrappers, one for each called component instance
73                List<ContextWrapper> contextWrapperList;
74                if (myContextWrapper == null)
75                        contextWrapperList = ContextWrapper.getContextWrapperFor(object, pcmInstance);
76                else
77                        contextWrapperList = myContextWrapper.getContextWrapperFor(object);
78 
79                List<Option> optionsPerContextWrapperList = new LinkedList<Option>();
80                for (ContextWrapper contextWrapper : contextWrapperList) {
81                        
82                        // calculate the expression for the contextWrapper in the list iteration
83                        myContextWrapper = contextWrapper;
84                        
85                        Option option = expFactory.createOption();
86                        option.setRegexp(getEntryExpression(object));
87                        option.setProbability(1/contextWrapperList.size());
88                        optionsPerContextWrapperList.add(option);
89                }
90                Expression exp = null;
91                if (optionsPerContextWrapperList.size() == 1){
92                        exp =  optionsPerContextWrapperList.get(0).getRegexp();
93                } else {
94                        exp =  Pcm2RegexHelper.createAlternativesForExpressions(optionsPerContextWrapperList);
95                }
96                Sequence seq = expFactory.createSequence();
97                seq.setLeftRegExp(exp);
98                seq.setRightRegExp((Expression)doSwitch(object.getSuccessor()));
99 
100                return seq;
101                
102        }
103 
104        
105 
106        private Expression getEntryExpression(EntryLevelSystemCall object) {
107                OperationProvidedRole role = object.getProvidedRole_EntryLevelSystemCall();
108                ProvidedDelegationConnector delegationConnector = getDelegationConnector(role);
109                RepositoryComponent offeringComponent = delegationConnector
110                                .getAssemblyContext_ProvidedDelegationConnector()
111                                .getEncapsulatedComponent__AssemblyContext();
112        
113                Expression expr = null;
114                ServiceEffectSpecification seff = myContextWrapper.getNextSEFF(object);
115                TransformSeffVisitor seffVisitor = new TransformSeffVisitor(myContextWrapper);
116                try {
117                        expr = (Expression)seffVisitor.doSwitch((ResourceDemandingSEFF) seff);
118                } catch (Exception e) {
119                        logger.error("Error while visiting RDSEFF");
120                        e.printStackTrace();
121                }
122                
123                return expr;
124        }
125 
126        @Override
127        public Object caseBranch(Branch object) {
128                
129                List<Option> optionsForBranches = new LinkedList<Option>();
130                
131                for (BranchTransition branch : object.getBranchTransitions_Branch()) {
132                        Option option = expFactory.createOption();
133                        option.setProbability(branch.getBranchProbability());
134                        Expression branchExpression = (Expression)doSwitch(branch.getBranchedBehaviour_BranchTransition());
135                        option.setRegexp(branchExpression);
136                        
137                        optionsForBranches.add(option);
138                }
139                Expression alt = Pcm2RegexHelper.createAlternativesForExpressions(optionsForBranches);
140                
141                Sequence seq = expFactory.createSequence();
142                seq.setLeftRegExp(alt);
143                seq.setRightRegExp((Expression)doSwitch(object.getSuccessor()));
144                
145                return seq;
146        }
147 
148        @Override
149        public Object caseLoop(Loop object) {
150                de.uka.ipd.sdq.spa.expression.Loop loop = expFactory.createLoop();
151                RandomVariable iterations = (RandomVariable)object.getLoopIteration_Loop();
152                loop.setIterationsString(iterations.getSpecification());
153                loop.setRegExp((Expression)doSwitch(object.getBodyBehaviour_Loop()));
154                
155                Sequence seq = expFactory.createSequence();                
156                seq.setLeftRegExp(loop);
157                seq.setRightRegExp((Expression)doSwitch(object.getSuccessor()));
158                
159                return seq;
160        }
161 
162        @Override
163        public Object caseScenarioBehaviour(ScenarioBehaviour object) {
164                return doSwitch(getStartAction(object));
165        }
166 
167        private Start getStartAction(ScenarioBehaviour object) {
168                Start startAction = (Start) EMFQueryHelper.getObjectByType(object
169                                .getActions_ScenarioBehaviour(), Start.class);
170                return startAction;
171        }
172 
173        private ProvidedDelegationConnector getDelegationConnector(
174                        OperationProvidedRole role) {
175                ProvidedDelegationConnector delegationConnector = 
176                        (ProvidedDelegationConnector) EMFQueryHelper
177                                .executeOCLQuery(
178                                                pcmInstance.getSystem(),
179                                                "self.connectors__ComposedStructure->select(dc|dc.oclIsTypeOf(composition::ProvidedDelegationConnector) and dc.oclAsType(composition::ProvidedDelegationConnector).outerProvidedRole_ProvidedDelegationConnector.providedInterface__OperationProvidedRole.id = '"
180                                                                + role.getProvidedInterface__OperationProvidedRole()
181                                                                                .getId()
182                                                                + "')->asOrderedSet()->first()");
183                return delegationConnector;
184                
185        }
186        
187        /**
188         * @param method
189         * @param basicComponent
190         * @return
191         */
192        private ServiceEffectSpecification getSeff(Signature method,
193                        BasicComponent basicComponent) {
194                ServiceEffectSpecification seff = (ServiceEffectSpecification) EMFQueryHelper
195                                .executeOCLQuery(
196                                                basicComponent,
197                                                "self.serviceEffectSpecifications__BasicComponent->select(seff|seff.describedService__SEFF.serviceName = '"
198                                                                + method.getEntityName()
199                                                                + "')->asOrderedSet()->first()");
200                return seff;
201        }
202}

[all classes][de.uka.ipd.sdq.pcmsolver.transformations.pcm2regex]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov