| 1 | package de.uka.ipd.sdq.pcmbench.tabs.operations; |
| 2 | |
| 3 | import java.util.Iterator; |
| 4 | |
| 5 | import org.eclipse.emf.common.util.EList; |
| 6 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
| 7 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 8 | |
| 9 | import de.uka.ipd.sdq.pcm.repository.DataType; |
| 10 | import de.uka.ipd.sdq.pcm.repository.ExceptionType; |
| 11 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
| 12 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
| 13 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
| 14 | |
| 15 | /** |
| 16 | * @author roman |
| 17 | * Responsibly for representation different Signature propertys (ReturnType, Parameters, Exceptions), as string |
| 18 | */ |
| 19 | public class ParameterRepresentation { |
| 20 | |
| 21 | /** |
| 22 | * @param DataType |
| 23 | * @param AdapterFactory |
| 24 | * @return String |
| 25 | */ |
| 26 | public String setDataTypeToString(DataType returnType) { |
| 27 | |
| 28 | String result = ""; |
| 29 | |
| 30 | // RepositoryItemProviderAdapterFactory |
| 31 | ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(); |
| 32 | adapterFactory |
| 33 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
| 34 | |
| 35 | PalladioItemProviderAdapterFactory decoratedFactory = new PalladioItemProviderAdapterFactory( |
| 36 | adapterFactory); |
| 37 | |
| 38 | |
| 39 | if (returnType != null) { |
| 40 | IItemLabelProvider datatypeProvider = (IItemLabelProvider) decoratedFactory |
| 41 | .adapt((Object) returnType, IItemLabelProvider.class); |
| 42 | result = datatypeProvider.getText(returnType); |
| 43 | } |
| 44 | |
| 45 | return result; |
| 46 | } |
| 47 | |
| 48 | public String setParametersToString(EList<Parameter> parameters) { |
| 49 | |
| 50 | String result = ""; |
| 51 | |
| 52 | for (Iterator<Parameter> it = parameters.iterator(); it.hasNext();) { |
| 53 | result += it.next().getParameterName() + ", "; |
| 54 | } |
| 55 | return deleteComma(result); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Comma of the sentence deletes ends |
| 60 | */ |
| 61 | public String deleteComma(String result) { |
| 62 | if (!result.equals("")) { |
| 63 | result = result.substring(0, result.length() - 2); |
| 64 | } |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | public String setExceptionsToString(EList<ExceptionType> exceptions) { |
| 69 | |
| 70 | String result = ""; |
| 71 | ExceptionType exceptionType; |
| 72 | |
| 73 | for (Iterator<ExceptionType> it = exceptions.iterator(); it.hasNext();) { |
| 74 | exceptionType = it.next(); |
| 75 | result += exceptionType.getExceptionName() + ", "; |
| 76 | } |
| 77 | return deleteComma(result); |
| 78 | |
| 79 | } |
| 80 | |
| 81 | |
| 82 | public String isNotNull(String string) { |
| 83 | return string == null ? "" : string; |
| 84 | } |
| 85 | } |