| 1 | package de.uka.ipd.sdq.workflow.pcm.configurations; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import de.uka.ipd.sdq.workflow.pcm.runconfig.SensitivityAnalysisConfiguration; |
| 7 | |
| 8 | /** |
| 9 | * Base class of workflow configuration objects where the corresponding workflow |
| 10 | * transforms PCM models into some kind of code |
| 11 | * |
| 12 | * @author Steffen Becker |
| 13 | * |
| 14 | */ |
| 15 | public abstract class AbstractCodeGenerationWorkflowRunConfiguration extends |
| 16 | AbstractPCMWorkflowRunConfiguration implements Cloneable { |
| 17 | |
| 18 | public enum CodeGenerationAdvice { |
| 19 | SIMULATION("simulation_template_methods"), POJO("pojo_template_methods"), EJB3( |
| 20 | "ejb3_template_methods"), PROTO("prototype_template_methods"); |
| 21 | |
| 22 | private String templateFile; |
| 23 | |
| 24 | CodeGenerationAdvice(String templateFile) { |
| 25 | this.templateFile = templateFile; |
| 26 | } |
| 27 | |
| 28 | public String getTemplateFile() { |
| 29 | return templateFile; |
| 30 | } |
| 31 | |
| 32 | } |
| 33 | |
| 34 | protected boolean overwriteWithoutAsking = false; |
| 35 | protected boolean loadMiddlewareAndCompletionFiles = false; |
| 36 | protected CodeGenerationAdvice codeGenerationAdvice = CodeGenerationAdvice.SIMULATION; |
| 37 | |
| 38 | // The sensitivity analysis configurations have been moved here because the |
| 39 | // PCM2CodeJob |
| 40 | // requires the Sensitivity Analysis Config anyways. Also for other code |
| 41 | // generation purposes (e.g. Protocom), sensitivity analysis can make sense. |
| 42 | protected List<SensitivityAnalysisConfiguration> sensitivityAnalysisConfigurationList = new ArrayList<SensitivityAnalysisConfiguration>(); |
| 43 | protected boolean sensitivityAnalysisEnabled; |
| 44 | |
| 45 | /** |
| 46 | * @return Returns a string with information on the current sensitivity analysis run. |
| 47 | */ |
| 48 | private String getSensitivityAnalysisIdentifier() { |
| 49 | String result = ""; |
| 50 | for (SensitivityAnalysisConfiguration sac : sensitivityAnalysisConfigurationList) { |
| 51 | result += "." + sac.getRunNo(); |
| 52 | } |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return Returns the ID of the Eclipse plugin to be generated by the code |
| 58 | * transformation. This is the name of the Eclipse project which |
| 59 | * will contain the generated code |
| 60 | */ |
| 61 | public String getStoragePluginID() { |
| 62 | return sensitivityAnalysisEnabled ? super.getStoragePluginID() |
| 63 | + getSensitivityAnalysisIdentifier() : super.getStoragePluginID(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Set whether the code generation may overwrite any existing artifacts |
| 68 | * without asking the user. If set to false, the code generation has to ask |
| 69 | * the user first. |
| 70 | * |
| 71 | * @param overwriteWithoutAsking |
| 72 | */ |
| 73 | public void setOverwriteWithoutAsking(boolean overwriteWithoutAsking) { |
| 74 | this.overwriteWithoutAsking = overwriteWithoutAsking; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get whether the code generation may overwrite any existing artifacts |
| 79 | * without asking the user. If set to false, the code generation has to ask |
| 80 | * the user first. |
| 81 | * |
| 82 | * @return true if the code can be overwritten without asking, else false |
| 83 | */ |
| 84 | public boolean isOverwriteWithoutAsking() { |
| 85 | return overwriteWithoutAsking; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Set whether the middleware files and completion files should be loaded, |
| 90 | * too. This is for example required for the simulation of linking |
| 91 | * resources. |
| 92 | * |
| 93 | * @param loadMiddlewareAndCompletionFiles |
| 94 | * the loadMiddlewareAndCompletionFiles to set |
| 95 | */ |
| 96 | public void setLoadMiddlewareAndCompletionFiles( |
| 97 | boolean loadMiddlewareAndCompletionFiles) { |
| 98 | this.loadMiddlewareAndCompletionFiles = loadMiddlewareAndCompletionFiles; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns whether the middleware files and completion files should be |
| 103 | * loaded, too. This is for example required for the simulation of linking |
| 104 | * resources. |
| 105 | * |
| 106 | * @return the loadMiddlewareAndCompletionFiles |
| 107 | */ |
| 108 | public boolean isLoadMiddlewareAndCompletionFiles() { |
| 109 | return loadMiddlewareAndCompletionFiles; |
| 110 | } |
| 111 | |
| 112 | public boolean isSensitivityAnalysisEnabled() { |
| 113 | return sensitivityAnalysisEnabled; |
| 114 | } |
| 115 | |
| 116 | public List<SensitivityAnalysisConfiguration> getSensitivityAnalysisConfigurations() { |
| 117 | if (!isSensitivityAnalysisEnabled()) |
| 118 | throw new UnsupportedOperationException( |
| 119 | "GetSensitivityAnalysisConfiguration is only supported if isSensitivityAnaysisEnabled is true!"); |
| 120 | |
| 121 | return sensitivityAnalysisConfigurationList; |
| 122 | } |
| 123 | |
| 124 | public void setSensitivityAnalysisEnabled(boolean sensitivityAnalysisEnabled) { |
| 125 | checkFixed(); |
| 126 | this.sensitivityAnalysisEnabled = sensitivityAnalysisEnabled; |
| 127 | } |
| 128 | |
| 129 | public void setSensitivityAnalysisConfiguration( |
| 130 | SensitivityAnalysisConfiguration sensitivityConfig) { |
| 131 | checkFixed(); |
| 132 | this.sensitivityAnalysisConfigurationList = new ArrayList<SensitivityAnalysisConfiguration>(); |
| 133 | this.sensitivityAnalysisConfigurationList.add(sensitivityConfig); |
| 134 | } |
| 135 | |
| 136 | public void setSensitivityAnalysisConfigurationList( |
| 137 | List<SensitivityAnalysisConfiguration> sensitivityConfigList) { |
| 138 | checkFixed(); |
| 139 | this.sensitivityAnalysisConfigurationList = sensitivityConfigList; |
| 140 | |
| 141 | } |
| 142 | |
| 143 | public CodeGenerationAdvice getCodeGenerationAdvice() { |
| 144 | return codeGenerationAdvice; |
| 145 | } |
| 146 | |
| 147 | public String getCodeGenerationAdvicesFile() { |
| 148 | return this.codeGenerationAdvice.getTemplateFile(); |
| 149 | } |
| 150 | |
| 151 | public void setCodeGenerationAdvicesFile(CodeGenerationAdvice advice) { |
| 152 | this.codeGenerationAdvice = advice; |
| 153 | } |
| 154 | |
| 155 | /* (non-Javadoc) |
| 156 | * @see de.uka.ipd.sdq.workflow.pcm.configurations.AbstractPCMWorkflowRunConfiguration#clone() |
| 157 | */ |
| 158 | @Override |
| 159 | protected Object clone() throws CloneNotSupportedException { |
| 160 | AbstractCodeGenerationWorkflowRunConfiguration config = (AbstractCodeGenerationWorkflowRunConfiguration) super.clone(); |
| 161 | config.codeGenerationAdvice = this.codeGenerationAdvice; |
| 162 | config.loadMiddlewareAndCompletionFiles = this.loadMiddlewareAndCompletionFiles; |
| 163 | config.overwriteWithoutAsking = this.overwriteWithoutAsking; |
| 164 | List<SensitivityAnalysisConfiguration> newSensitivityAnalysisConfigurationList = new ArrayList<SensitivityAnalysisConfiguration>(this.sensitivityAnalysisConfigurationList.size()); |
| 165 | for(SensitivityAnalysisConfiguration saconfig : this.sensitivityAnalysisConfigurationList) { |
| 166 | newSensitivityAnalysisConfigurationList.add(saconfig.getClone()); |
| 167 | } |
| 168 | config.sensitivityAnalysisConfigurationList = newSensitivityAnalysisConfigurationList; |
| 169 | config.sensitivityAnalysisEnabled = this.sensitivityAnalysisEnabled; |
| 170 | return config; |
| 171 | } |
| 172 | } |