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

COVERAGE SUMMARY FOR SOURCE FILE [VariableUsageSensitivity.java]

nameclass, %method, %block, %line, %
VariableUsageSensitivity.java0%   (0/1)0%   (0/10)0%   (0/415)0%   (0/105)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VariableUsageSensitivity0%   (0/1)0%   (0/10)0%   (0/415)0%   (0/105)
$SWITCH_TABLE$de$uka$ipd$sdq$sensitivity$VariableUsageType (): int [] 0%   (0/1)0%   (0/27)0%   (0/1)
VariableUsageSensitivity (String, String, String, VariableCharacterisationTyp... 0%   (0/1)0%   (0/20)0%   (0/7)
alterModel (): boolean 0%   (0/1)0%   (0/17)0%   (0/5)
checkParameterName (AbstractNamedReference, String [], int): boolean 0%   (0/1)0%   (0/32)0%   (0/6)
extractComponentParameter (): void 0%   (0/1)0%   (0/83)0%   (0/23)
extractSensitivityInformation (): void 0%   (0/1)0%   (0/13)0%   (0/6)
extractSystemCallInput (): void 0%   (0/1)0%   (0/68)0%   (0/19)
extractVariable (EList): void 0%   (0/1)0%   (0/65)0%   (0/13)
getLogHeadingsMulti (): List 0%   (0/1)0%   (0/53)0%   (0/17)
getLogSingleResultsMulti (): List 0%   (0/1)0%   (0/37)0%   (0/8)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.reliability.solver.sensitivity;
5 
6import java.util.ArrayList;
7import java.util.List;
8 
9import org.eclipse.emf.common.util.EList;
10import org.eclipse.emf.ecore.EObject;
11 
12import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
13import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation;
14import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisationType;
15import de.uka.ipd.sdq.pcm.parameter.VariableUsage;
16import de.uka.ipd.sdq.pcm.repository.BasicComponent;
17import de.uka.ipd.sdq.pcm.repository.Repository;
18import de.uka.ipd.sdq.pcm.repository.RepositoryFactory;
19import de.uka.ipd.sdq.pcm.usagemodel.EntryLevelSystemCall;
20import de.uka.ipd.sdq.pcm.usagemodel.UsagemodelFactory;
21import de.uka.ipd.sdq.sensitivity.StringParameterSequence;
22import de.uka.ipd.sdq.sensitivity.VariableUsageType;
23import de.uka.ipd.sdq.stoex.AbstractNamedReference;
24import de.uka.ipd.sdq.stoex.NamespaceReference;
25import de.uka.ipd.sdq.stoex.VariableReference;
26 
27/**
28 * This class provides rudimentary support for sensitivity analysis of a system
29 * call variable usage.
30 * 
31 * Further refactorings required.
32 * 
33 * @author brosch
34 * 
35 */
36public class VariableUsageSensitivity extends MarkovSensitivity {
37 
38        /**
39         * Property of the parameter to alter.
40         */
41        private VariableCharacterisationType characterisationType;
42 
43        /**
44         * ID of the EntryLevelSystemCall or BasicComponent to alter.
45         */
46        private String elementId;
47 
48        /**
49         * Name of the EntryLevelSystemCall or BasicComponent to alter.
50         */
51        private String elementName;
52 
53        /**
54         * Qualified name of the modelled PCM parameter.
55         */
56        private String parameterName;
57 
58        /**
59         * Type of parameter usage (input parameter for EntryLevelSystemCall or
60         * component parameter).
61         */
62        private VariableUsageType parameterType;
63 
64        /**
65         * The affected random variable.
66         */
67        private PCMRandomVariable variable = null;
68 
69        /**
70         * The constructor.
71         * 
72         * @param name
73         *            the name of the sensitivity analysis
74         * @param elementId
75         *            the ID of the EntryLevelSystemCall or BasicComponent to alter
76         * @param parameterName
77         *            the qualified name of the modelled PCM parameter
78         * @param characterisationType
79         *            the property of the parameter to alter
80         * @param parameterType
81         *            the type of parameter usage (input parameter for
82         *            EntryLevelSystemCall or component parameter)
83         * @param sequence
84         *            the sequence of parameter value specifications
85         */
86        public VariableUsageSensitivity(final String name, final String elementId,
87                        final String parameterName,
88                        final VariableCharacterisationType characterisationType,
89                        VariableUsageType parameterType,
90                        final StringParameterSequence sequence) {
91 
92                // Initialize basic variables:
93                super(name, sequence);
94 
95                // Further initializations:
96                this.elementId = elementId;
97                this.parameterName = parameterName;
98                this.characterisationType = characterisationType;
99                this.parameterType = parameterType;
100        }
101 
102        /**
103         * Alters the model according to the next sensitivity analysis step.
104         * 
105         * @return indicates if the model could be successfully altered
106         */
107        protected boolean alterModel() {
108 
109                // Check validity:
110                if (variable == null) {
111                        return false;
112                }
113 
114                // Set the failure probability:
115                variable.setSpecification(calculator.calculateCurrentStringValue(
116                                getStringSequence(), getCurrentStepNumber()));
117 
118                // Everything ok:
119                return true;
120        }
121 
122        /**
123         * Checks if a given parameter name is compliant with a given named
124         * reference.
125         * 
126         * @param reference
127         *            the named reference
128         * @param paramName
129         *            the parameter name
130         * @return TRUE if the parameter is compliant with the named reference
131         */
132        private boolean checkParameterName(final AbstractNamedReference reference,
133                        final String[] paramName, int index) {
134                if (!reference.getReferenceName().equals(paramName[index])) {
135                        return false;
136                }
137                if (reference instanceof VariableReference) {
138                        return (paramName.length == index + 1);
139                }
140                return checkParameterName(((NamespaceReference) reference)
141                                .getInnerReference_NamespaceReference(), paramName, index + 1);
142        }
143 
144        /**
145         * Model information extraction for BasicComponent configuration parameters.
146         */
147        private void extractComponentParameter() {
148 
149                // Retrieve all FailureOccurrenceDescriptions in the PCM Repository:
150                List<Repository> repositories = getModel().getRepositories();
151                if (repositories.size() == 0) {
152                        // No repository found!
153                        logger.error("No PCM Repositories found.");
154                        return;
155                }
156 
157                // Search for the relevant internal action:
158                BasicComponent component = null;
159                for (Repository repository : repositories) {
160                        EList<EObject> components = helper
161                                        .getElements(repository, RepositoryFactory.eINSTANCE
162                                                        .createBasicComponent().eClass());
163                        for (EObject object : components) {
164                                if (((BasicComponent) object).getId().equals(elementId)) {
165                                        component = (BasicComponent) object;
166                                        break;
167                                }
168                        }
169                        if (component != null) {
170                                break;
171                        }
172                }
173                if (component == null) {
174                        // No corresponding component found!
175                        logger.error("No BasicComponent with ID \"" + elementId
176                                        + "\" found.");
177                        return;
178                }
179                elementName = component.getEntityName();
180 
181                // Search for the relevant parameter specification:
182                extractVariable(component
183                                .getComponentParameterUsage_ImplementationComponentType());
184        }
185 
186        /**
187         * Extracts the relevant sensitivity information from the given model.
188         */
189        protected void extractSensitivityInformation() {
190 
191                // Distinguish between input parameters for EntryLevelSystemCalls and
192                // BasicComponent configuration parameters:
193                switch (parameterType) {
194                case SYSTEM_CALL_INPUT:
195                        extractSystemCallInput();
196                        return;
197                case COMPONENT_CONFIGURATION:
198                        extractComponentParameter();
199                        return;
200                }
201        }
202 
203        /**
204         * Model information extraction for EntryLevelSystemCall input parameters.
205         */
206        private void extractSystemCallInput() {
207 
208                // Retrieve the PCM usage model:
209                if (getModel().getUsageModel() == null) {
210                        // No usage model found!
211                        logger.error("No PCM UsageModel found.");
212                        return;
213                }
214 
215                // Search for the relevant system call:
216                EntryLevelSystemCall systemCall = null;
217                EList<EObject> systemCalls = helper.getElements(getModel()
218                                .getUsageModel(), UsagemodelFactory.eINSTANCE
219                                .createEntryLevelSystemCall().eClass());
220                for (EObject object : systemCalls) {
221                        if (((EntryLevelSystemCall) object).getId().equals(elementId)) {
222                                systemCall = (EntryLevelSystemCall) object;
223                                break;
224                        }
225                }
226                if (systemCall == null) {
227                        // No corresponding system call found!
228                        logger.error("No EntryLevelSystemCall with ID \"" + elementId
229                                        + "\" found.");
230                        return;
231                }
232                elementName = systemCall.getEntityName();
233 
234                // Search for the relevant parameter specification:
235                extractVariable(systemCall
236                                .getInputParameterUsages_EntryLevelSystemCall());
237        }
238 
239        /**
240         * Extracts the relevant random variable from a list of variable usages.
241         * 
242         * @param parameterUsages
243         *            the variable usages
244         */
245        private void extractVariable(final EList<VariableUsage> parameterUsages) {
246                for (VariableUsage usage : parameterUsages) {
247                        if (checkParameterName(usage.getNamedReference__VariableUsage(),
248                                        parameterName.split("\\."), 0)) {
249                                for (VariableCharacterisation characterisation : usage
250                                                .getVariableCharacterisation_VariableUsage()) {
251                                        if (characterisation.getType().equals(characterisationType)) {
252                                                variable = characterisation
253                                                                .getSpecification_VariableCharacterisation();
254                                                return;
255                                        }
256                                }
257                        }
258                }
259                if (variable == null) {
260                        logger.error("Did not find any PCMRandomVariable for parameter \""
261                                        + parameterName + "." + characterisationType.getName());
262                }
263        }
264 
265        /**
266         * Builds the headings strings for logging.
267         * 
268         * @return the log headings strings
269         */
270        protected List<List<String>> getLogHeadingsMulti() {
271 
272                // Create a result list:
273                List<List<String>> resultList = new ArrayList<List<String>>();
274 
275                // Determine element Name and ID headings:
276                String elementNameHeader = null;
277                String elementIDHeader = null;
278                switch (parameterType) {
279                case SYSTEM_CALL_INPUT:
280                        elementNameHeader = "System Call Name";
281                        elementIDHeader = "System Call ID";
282                        break;
283                case COMPONENT_CONFIGURATION:
284                        elementNameHeader = "Component Name";
285                        elementIDHeader = "Component ID";
286                        break;
287                }
288 
289                // Create the headings:
290                ArrayList<String> headings = new ArrayList<String>();
291                headings.add(elementNameHeader);
292                headings.add(elementIDHeader);
293                headings.add("Parameter Name");
294                headings.add("Parameter Characterisation");
295                headings.add("Parameter Specification");
296                resultList.add(headings);
297 
298                // Return the result:
299                return resultList;
300        }
301 
302        /**
303         * Builds the results strings for sensitivity logging.
304         * 
305         * @return the results strings
306         */
307        protected List<String> getLogSingleResultsMulti() {
308 
309                // Create a result list:
310                List<String> resultList = new ArrayList<String>();
311 
312                // Create the result strings:
313                resultList.add(elementName);
314                resultList.add(elementId);
315                resultList.add(parameterName);
316                resultList.add(characterisationType.getName());
317                resultList.add(calculator.getCurrentLogEntry(getStringSequence(),
318                                getCurrentStepNumber()));
319 
320                // Return the result:
321                return resultList;
322        }
323}

[all classes][de.uka.ipd.sdq.reliability.solver.sensitivity]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov