1 | package de.uka.ipd.sdq.cip.completions; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.core.runtime.IConfigurationElement; |
6 | import org.eclipse.emf.common.util.URI; |
7 | |
8 | import de.uka.ipd.sdq.cip.ConstantsContainer; |
9 | |
10 | |
11 | public class RegisteredCompletion { |
12 | |
13 | protected final String id; |
14 | protected final String name; |
15 | protected final String image; |
16 | protected final String description; |
17 | protected final String featuremodel; |
18 | protected String metamodel; |
19 | protected final String qvtscript; |
20 | protected final ArrayList<String> categories; |
21 | |
22 | public RegisteredCompletion(String id, String name, String image, |
23 | String description, String featuremodel, String metamodel, String qvtscript, |
24 | ArrayList<String> categories) { |
25 | this.id = id; |
26 | this.name = name; |
27 | this.image = image; |
28 | this.description = description; |
29 | this.featuremodel = featuremodel; |
30 | this.metamodel = metamodel; |
31 | this.qvtscript = qvtscript; |
32 | this.categories = categories; |
33 | } |
34 | |
35 | public static RegisteredCompletion parseCompletion( |
36 | IConfigurationElement element, String contributor) { |
37 | String featuremodel = null; |
38 | String metamodel = null; |
39 | String qvtscript = null; |
40 | String image = null; |
41 | |
42 | String id = element.getAttribute(ConstantsContainer.ATT_COMPLETION_ID); |
43 | String name = element.getAttribute(ConstantsContainer.ATT_COMPLETION_NAME); |
44 | |
45 | if((image = element.getAttribute(ConstantsContainer.ATT_COMPLETION_IMAGE)) != null) |
46 | image = URI.createPlatformPluginURI("/" + contributor + "/" + image,false).toString(); |
47 | |
48 | if((featuremodel = element.getAttribute(ConstantsContainer.ATT_COMPLETION_FEATUREMODEL)) != null) |
49 | featuremodel = URI.createPlatformPluginURI("/" + contributor + "/" + featuremodel,false).toString(); |
50 | |
51 | if((metamodel = element.getAttribute(ConstantsContainer.ATT_COMPLETION_METAMODEL)) != null) |
52 | metamodel = URI.createPlatformPluginURI("/" + contributor + "/" + metamodel,false).toString(); |
53 | |
54 | if((qvtscript = element.getAttribute(ConstantsContainer.ATT_COMPLETION_QVTSCRIPT)) != null) |
55 | qvtscript = URI.createPlatformPluginURI("/" + contributor + "/" + qvtscript,false).toString(); |
56 | |
57 | IConfigurationElement[] description_node = element.getChildren(ConstantsContainer.NODE_DESCRIPTION); |
58 | String description = description_node[0].getValue(); |
59 | |
60 | IConfigurationElement[] categorie_node = element.getChildren(ConstantsContainer.NODE_CATEGORY); |
61 | ArrayList<String> categories = new ArrayList<String>(); |
62 | for(int i = 0; i < categorie_node.length; ++i) { |
63 | IConfigurationElement category = categorie_node[i]; |
64 | categories.add(category.getAttribute(ConstantsContainer.ATT_COMPLETION_NAME)); |
65 | } |
66 | |
67 | |
68 | if(id == null || name == null || description == null || !(featuremodel == null ^ qvtscript == null) || categories.size() < 1) |
69 | return null; |
70 | RegisteredCompletion rc = new RegisteredCompletion(id, name, image, description, featuremodel, metamodel, qvtscript, categories); |
71 | return rc; |
72 | } |
73 | |
74 | public String getImage() { |
75 | return image; |
76 | } |
77 | |
78 | public String getId() { |
79 | return id; |
80 | } |
81 | |
82 | public String getName() { |
83 | return name; |
84 | } |
85 | |
86 | public String getDescription() { |
87 | return description; |
88 | } |
89 | |
90 | public String getFeaturemodel() { |
91 | return featuremodel; |
92 | } |
93 | |
94 | public String getMetamodel() { |
95 | return metamodel; |
96 | } |
97 | |
98 | public String getQvtscript() { |
99 | return qvtscript; |
100 | } |
101 | |
102 | public ArrayList<String> getCategories() { |
103 | return categories; |
104 | } |
105 | |
106 | public boolean containsCategory(String category) { |
107 | for(String search_category : categories) { |
108 | if(search_category.equals(category)) |
109 | return true; |
110 | } |
111 | return false; |
112 | } |
113 | |
114 | } |