| 1 | package de.uka.ipd.sdq.cip.configuration; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.Map; |
| 5 | |
| 6 | import de.uka.ipd.sdq.cip.ConstantsContainer; |
| 7 | import de.uka.ipd.sdq.cip.completions.RegisteredCompletion; |
| 8 | import de.uka.ipd.sdq.cip.completions.RegisteredCompletions; |
| 9 | |
| 10 | /** |
| 11 | * Transformation contains the configuration |
| 12 | * for a single Completion. |
| 13 | * |
| 14 | * @author Thomas Schuischel |
| 15 | * |
| 16 | */ |
| 17 | public class Transformation { |
| 18 | |
| 19 | public enum TransformationQVTType { |
| 20 | NONE, |
| 21 | QVTR, |
| 22 | QVTO; |
| 23 | |
| 24 | public String toString(){ |
| 25 | if(this == QVTR) |
| 26 | return "QVTR"; |
| 27 | else if(this == QVTO) |
| 28 | return "QVTO"; |
| 29 | |
| 30 | return "QVTR"; |
| 31 | } |
| 32 | |
| 33 | public static TransformationQVTType fromString(String value){ |
| 34 | if(value == null) |
| 35 | return QVTR; |
| 36 | |
| 37 | if(value.equalsIgnoreCase ("QVTR")) |
| 38 | return QVTR; |
| 39 | else if(value.equalsIgnoreCase ("QVTO")) |
| 40 | return QVTO; |
| 41 | |
| 42 | return QVTR; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Map<String, String> keyValueMap = null; |
| 47 | |
| 48 | public Transformation() { |
| 49 | keyValueMap = new HashMap<String, String>(); |
| 50 | } |
| 51 | |
| 52 | public String toDataString() { |
| 53 | |
| 54 | String data = ""; |
| 55 | |
| 56 | // write key-value combinations back to string |
| 57 | for ( String key : keyValueMap.keySet() ) |
| 58 | { |
| 59 | data += key + "="+keyValueMap.get(key) + ";"; |
| 60 | } |
| 61 | |
| 62 | // remove last semikolon |
| 63 | data = data.replaceFirst(";$",""); |
| 64 | |
| 65 | return data; |
| 66 | } |
| 67 | |
| 68 | public void readFromDataString(String data) { |
| 69 | String[] dataStrings = data.split(";", -1); |
| 70 | |
| 71 | // read key-value combinations from string |
| 72 | for(int i= 0; i< dataStrings.length; i++) |
| 73 | { |
| 74 | String[] keyValueData = dataStrings[i].split("="); |
| 75 | keyValueMap.put(keyValueData[0], keyValueData[1]); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | public static Transformation fromDataString(String data) { |
| 80 | Transformation transformation = new Transformation(); |
| 81 | transformation.readFromDataString(data); |
| 82 | return transformation; |
| 83 | } |
| 84 | |
| 85 | public Boolean isEnabled() { |
| 86 | return Boolean.parseBoolean(keyValueMap.get("enabled")); |
| 87 | } |
| 88 | |
| 89 | public void setEnabled(Boolean enabled) { |
| 90 | keyValueMap.put("enabled", enabled.toString()); |
| 91 | } |
| 92 | |
| 93 | public TransformationType getType() { |
| 94 | return TransformationType.fromString(keyValueMap.get("type")); |
| 95 | } |
| 96 | |
| 97 | public void setType(TransformationType type) { |
| 98 | keyValueMap.put("type", type.toString()); |
| 99 | } |
| 100 | |
| 101 | public TransformationQVTType getQVTType() { |
| 102 | if(getType() == TransformationType.REGISTERED){ |
| 103 | RegisteredCompletion completion = getCompletion(); |
| 104 | |
| 105 | if(completion == null) |
| 106 | return TransformationQVTType.NONE; |
| 107 | |
| 108 | if(completion.containsCategory(ConstantsContainer.QVTO_Category)) |
| 109 | return TransformationQVTType.QVTO; |
| 110 | } |
| 111 | |
| 112 | return TransformationQVTType.fromString(keyValueMap.get("qvtrType")); |
| 113 | } |
| 114 | |
| 115 | public void setQVTType(TransformationQVTType qvtType) { |
| 116 | keyValueMap.put("qvtrType", qvtType.toString()); |
| 117 | } |
| 118 | |
| 119 | public RegisteredCompletion getCompletion() { |
| 120 | String ID = keyValueMap.get("id"); |
| 121 | |
| 122 | if(ID == null) |
| 123 | return null; |
| 124 | |
| 125 | return RegisteredCompletions.findCompletion(ID); |
| 126 | } |
| 127 | |
| 128 | public void setCompletion(String ID) { |
| 129 | keyValueMap.put("id",ID); |
| 130 | } |
| 131 | |
| 132 | public void setFeatureFileURI(String featureFileURI) { |
| 133 | keyValueMap.put("featureFileURI", featureFileURI); |
| 134 | } |
| 135 | |
| 136 | public String getFeatureFileURI() { |
| 137 | return keyValueMap.get("featureFileURI"); |
| 138 | } |
| 139 | |
| 140 | public void setConfigFileURI(String configFileURI) { |
| 141 | keyValueMap.put("configFileURI", configFileURI); |
| 142 | } |
| 143 | |
| 144 | public String getConfigFileURI() { |
| 145 | return keyValueMap.get("configFileURI"); |
| 146 | } |
| 147 | |
| 148 | public void setMetamodelFileURI(String metamodelFileURI) { |
| 149 | keyValueMap.put("metamodelFileURI", metamodelFileURI); |
| 150 | } |
| 151 | |
| 152 | public String getMetamodelFileURI() { |
| 153 | if(getType() == TransformationType.REGISTERED){ |
| 154 | RegisteredCompletion completion = getCompletion(); |
| 155 | return completion.getMetamodel(); |
| 156 | } |
| 157 | |
| 158 | return keyValueMap.get("metamodelFileURI"); |
| 159 | } |
| 160 | |
| 161 | public void setQVTFileURI(String qvtFileURI) { |
| 162 | keyValueMap.put("qvtFileURI", qvtFileURI); |
| 163 | } |
| 164 | |
| 165 | public String getQVTFileURI() { |
| 166 | if(getType() == TransformationType.REGISTERED){ |
| 167 | RegisteredCompletion completion = getCompletion(); |
| 168 | return completion.getQvtscript(); |
| 169 | } |
| 170 | |
| 171 | return keyValueMap.get("qvtFileURI"); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Set an optional additional model to be used in the transformation. |
| 176 | * |
| 177 | * @param optionalModelFileURI The URI to the model. |
| 178 | */ |
| 179 | public void setOptionalModelFileURI(String optionalModelFileURI) { |
| 180 | keyValueMap.put("optionalModelFileURI", optionalModelFileURI); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Get an optional additional model to be used in the transformation. |
| 185 | * |
| 186 | * @return The URI to the model. |
| 187 | */ |
| 188 | public String getOptionalModelFileURI() { |
| 189 | return keyValueMap.get("optionalModelFileURI"); |
| 190 | } |
| 191 | } |