| 1 | package de.uka.ipd.sdq.pcmsolver.visitors; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import org.apache.log4j.Logger; |
| 6 | import org.eclipse.emf.common.util.EList; |
| 7 | |
| 8 | import de.uka.ipd.sdq.context.computed_allocation.ComputedAllocationFactory; |
| 9 | import de.uka.ipd.sdq.context.computed_usage.ComputedUsageFactory; |
| 10 | import de.uka.ipd.sdq.pcm.parameter.ParameterFactory; |
| 11 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
| 12 | import de.uka.ipd.sdq.pcm.seff.ServiceEffectSpecification; |
| 13 | import de.uka.ipd.sdq.pcm.usagemodel.Branch; |
| 14 | import de.uka.ipd.sdq.pcm.usagemodel.BranchTransition; |
| 15 | import de.uka.ipd.sdq.pcm.usagemodel.Delay; |
| 16 | import de.uka.ipd.sdq.pcm.usagemodel.EntryLevelSystemCall; |
| 17 | import de.uka.ipd.sdq.pcm.usagemodel.Loop; |
| 18 | import de.uka.ipd.sdq.pcm.usagemodel.ScenarioBehaviour; |
| 19 | import de.uka.ipd.sdq.pcm.usagemodel.Start; |
| 20 | import de.uka.ipd.sdq.pcm.usagemodel.Stop; |
| 21 | import de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelSwitch; |
| 22 | import de.uka.ipd.sdq.pcmsolver.models.PCMInstance; |
| 23 | import de.uka.ipd.sdq.pcmsolver.transformations.ContextWrapper; |
| 24 | |
| 25 | /** |
| 26 | * Visitor that builds the computed usage and computed allocation contexts by calling |
| 27 | * {@link SeffVisitor} for each {@link EntryLevelSystemCall}. |
| 28 | * @author Koziolek, Martens |
| 29 | * |
| 30 | */ |
| 31 | public class UsageModelVisitor extends UsagemodelSwitch { |
| 32 | |
| 33 | protected static Logger logger = Logger.getLogger(UsageModelVisitor.class |
| 34 | .getName()); |
| 35 | |
| 36 | protected PCMInstance pcmInstance; |
| 37 | private ComputedUsageFactory compUsageFactory; |
| 38 | private ComputedAllocationFactory compAllocationFactory; |
| 39 | private ParameterFactory parameterFactory; |
| 40 | |
| 41 | protected ContextWrapper myContextWrapper = null; |
| 42 | |
| 43 | /** |
| 44 | * Solves dependencies for this {@link PCMInstance} and adds the results to the |
| 45 | * {@link PCMInstance}'s computed contexts (such as {@link PCMInstance#getComputedUsage()}). |
| 46 | * @param inst |
| 47 | * an instance of the Palladio Component Metamodel |
| 48 | */ |
| 49 | public UsageModelVisitor(PCMInstance inst) { |
| 50 | pcmInstance = inst; |
| 51 | compUsageFactory = ComputedUsageFactory.eINSTANCE; |
| 52 | compAllocationFactory = ComputedAllocationFactory.eINSTANCE; |
| 53 | parameterFactory = ParameterFactory.eINSTANCE; |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * (non-Javadoc) |
| 58 | * |
| 59 | * @see de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelSwitch#caseScenarioBehaviour(de.uka.ipd.sdq.pcm.usagemodel.ScenarioBehaviour) |
| 60 | */ |
| 61 | @Override |
| 62 | public Object caseScenarioBehaviour(ScenarioBehaviour object) { |
| 63 | logger.debug("VisitScenarioBehaviour"); |
| 64 | doSwitch(getStartAction(object)); |
| 65 | return object; |
| 66 | } |
| 67 | |
| 68 | /* (non-Javadoc) |
| 69 | * @see de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelSwitch#caseStart(de.uka.ipd.sdq.pcm.usagemodel.Start) |
| 70 | */ |
| 71 | @Override |
| 72 | public Object caseStart(Start object) { |
| 73 | logger.debug("VisitStart"); |
| 74 | doSwitch(object.getSuccessor()); |
| 75 | return object; |
| 76 | } |
| 77 | |
| 78 | /* (non-Javadoc) |
| 79 | * @see de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelSwitch#caseStop(de.uka.ipd.sdq.pcm.usagemodel.Stop) |
| 80 | */ |
| 81 | @Override |
| 82 | public Object caseStop(Stop object) { |
| 83 | logger.debug("VisitStop"); |
| 84 | return object; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | |
| 89 | @Override |
| 90 | public Object caseBranch(Branch object) { |
| 91 | logger.debug("VisitBranch"); |
| 92 | EList<BranchTransition> btList = object.getBranchTransitions_Branch(); |
| 93 | for(BranchTransition bt : btList){ |
| 94 | doSwitch(bt.getBranchedBehaviour_BranchTransition()); |
| 95 | } |
| 96 | doSwitch(object.getSuccessor()); |
| 97 | return object; |
| 98 | } |
| 99 | |
| 100 | /* (non-Javadoc) |
| 101 | * @see de.uka.ipd.sdq.pcm.usagemodel.util.UsagemodelSwitch#caseEntryLevelSystemCall(de.uka.ipd.sdq.pcm.usagemodel.EntryLevelSystemCall) |
| 102 | */ |
| 103 | @Override |
| 104 | public Object caseEntryLevelSystemCall(EntryLevelSystemCall elsc) { |
| 105 | logger.debug("VisitEntryLevelSystemCall"); |
| 106 | logger.debug("Called System Method " |
| 107 | + elsc.getOperationSignature__EntryLevelSystemCall().getEntityName()); |
| 108 | |
| 109 | // Get List of ContextWrappers, one for each called component instance |
| 110 | List<ContextWrapper> contextWrapperList; |
| 111 | if (myContextWrapper == null) |
| 112 | contextWrapperList = ContextWrapper.getContextWrapperFor(elsc, pcmInstance); |
| 113 | else |
| 114 | contextWrapperList = myContextWrapper.getContextWrapperFor(elsc); |
| 115 | |
| 116 | for (ContextWrapper contextWrapper : contextWrapperList) { |
| 117 | ServiceEffectSpecification seff = contextWrapper.getNextSEFF(elsc); |
| 118 | SeffVisitor visitor = new SeffVisitor(contextWrapper); |
| 119 | //try { |
| 120 | visitor.doSwitch((ResourceDemandingSEFF) seff); |
| 121 | /*} catch (Exception e) { |
| 122 | logger.error("Error while visiting RDSEFF"); |
| 123 | e.printStackTrace(); |
| 124 | }*/ |
| 125 | } |
| 126 | |
| 127 | //XXX: The internal myContextWrapper is not affected by the handling of the |
| 128 | // EntryLevelSystem call because the copies of it handle it. This was different |
| 129 | // before allowing replication, when only one ContextWrapper instance was used. |
| 130 | doSwitch(elsc.getSuccessor()); |
| 131 | return elsc; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | |
| 136 | @Override |
| 137 | public Object caseDelay(Delay object) { |
| 138 | logger.debug("VisitDelay"); |
| 139 | doSwitch(object.getSuccessor()); |
| 140 | return object; |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public Object caseLoop(Loop object) { |
| 145 | logger.debug("VisitLoop"); |
| 146 | doSwitch(object.getBodyBehaviour_Loop()); |
| 147 | doSwitch(object.getSuccessor()); |
| 148 | return object; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @param object |
| 153 | * @return |
| 154 | */ |
| 155 | private Start getStartAction(ScenarioBehaviour object) { |
| 156 | Start startAction = (Start) EMFQueryHelper.getObjectByType(object |
| 157 | .getActions_ScenarioBehaviour(), Start.class); |
| 158 | return startAction; |
| 159 | } |
| 160 | |
| 161 | } |