1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
package org.argouml.profile.internal; |
41 | |
|
42 | |
import java.net.MalformedURLException; |
43 | |
import java.util.ArrayList; |
44 | |
import java.util.Collection; |
45 | |
import java.util.Collections; |
46 | |
import java.util.HashSet; |
47 | |
import java.util.Set; |
48 | |
|
49 | |
import org.apache.log4j.Logger; |
50 | |
import org.argouml.cognitive.Critic; |
51 | |
import org.argouml.cognitive.ToDoItem; |
52 | |
import org.argouml.model.Model; |
53 | |
import org.argouml.profile.CoreProfileReference; |
54 | |
import org.argouml.profile.Profile; |
55 | |
import org.argouml.profile.ProfileException; |
56 | |
import org.argouml.profile.ProfileModelLoader; |
57 | |
import org.argouml.profile.ProfileReference; |
58 | |
import org.argouml.profile.ResourceModelLoader; |
59 | |
import org.argouml.profile.internal.ocl.CrOCL; |
60 | |
import org.argouml.profile.internal.ocl.InvalidOclException; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public class ProfileMeta extends Profile { |
69 | |
|
70 | 900 | private static final Logger LOG = Logger.getLogger(ProfileMeta.class); |
71 | |
|
72 | |
private static final String PROFILE_FILE = "metaprofile.xmi"; |
73 | 900 | private ProfileReference profileReference = null; |
74 | |
|
75 | 900 | private Collection model = null; |
76 | |
|
77 | 900 | Set<Critic> critics = null; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
@SuppressWarnings("unchecked") |
85 | |
public ProfileMeta() throws ProfileException { |
86 | 900 | super(); |
87 | |
try { |
88 | 900 | profileReference = new CoreProfileReference(PROFILE_FILE); |
89 | 0 | } catch (MalformedURLException e) { |
90 | 0 | throw new ProfileException( |
91 | |
"Exception while creating profile reference.", e); |
92 | 900 | } |
93 | 900 | } |
94 | |
|
95 | |
private Collection getModel() { |
96 | 0 | if (model == null) { |
97 | 0 | ProfileModelLoader profileModelLoader = new ResourceModelLoader(); |
98 | |
try { |
99 | 0 | model = profileModelLoader.loadModel(profileReference); |
100 | 0 | } catch (ProfileException e) { |
101 | 0 | LOG.error("Exception loading metaprofile " + PROFILE_FILE, e); |
102 | 0 | } |
103 | |
|
104 | 0 | if (model == null) { |
105 | 0 | model = new ArrayList(); |
106 | 0 | model.add(Model.getModelManagementFactory().createModel()); |
107 | |
} |
108 | |
} |
109 | 0 | return model; |
110 | |
} |
111 | |
|
112 | |
private void loadWellFormednessRules() { |
113 | 900 | critics = new HashSet<Critic>(); |
114 | |
|
115 | |
try { |
116 | 900 | critics.add(new CrOCL("context ModelElement inv: " |
117 | |
+ "self.taggedValue->" |
118 | |
+ "exists(x|x.type.name='Dependency') implies " |
119 | |
+ "self.stereotype->exists(x|x.name = 'Profile')", |
120 | |
"The 'Dependency' tag definition should be applied" |
121 | |
+ " only to profiles.", null, |
122 | |
ToDoItem.MED_PRIORITY, null, null, |
123 | |
"http://argouml.tigris.org/")); |
124 | 0 | } catch (InvalidOclException e) { |
125 | 0 | e.printStackTrace(); |
126 | 900 | } |
127 | |
|
128 | |
try { |
129 | 900 | critics.add(new CrOCL("context ModelElement inv: " |
130 | |
+ "self.taggedValue->" |
131 | |
+ "exists(x|x.type.name='Figure') or " |
132 | |
+ "exists(x|x.type.name='Description') or " |
133 | |
+ "exists(x|x.type.name='i18n') or " |
134 | |
+ "exists(x|x.type.name='KnowledgeType') or " |
135 | |
+ "exists(x|x.type.name='MoreInfoURL') or " |
136 | |
+ "exists(x|x.type.name='Priority') or " |
137 | |
+ "exists(x|x.type.name='Description') or " |
138 | |
+ "exists(x|x.type.name='SupportedDecision') or " |
139 | |
+ "exists(x|x.type.name='Headline') " |
140 | |
+ "implies " |
141 | |
+ "self.stereotype->exists(x|x.name = 'Critic')", |
142 | |
|
143 | |
"Misuse of Metaprofile TaggedValues", |
144 | |
"The 'Figure', 'i18n', 'KnowledgeType', 'MoreInfoURL', " |
145 | |
+ "'Priority', 'SupportedDecision', 'Description' " |
146 | |
+ "and 'Headline' tag definitions " |
147 | |
+ "should be applied only to OCL critics.", |
148 | |
|
149 | |
ToDoItem.MED_PRIORITY, null, null, |
150 | |
"http://argouml.tigris.org/")); |
151 | 0 | } catch (InvalidOclException e) { |
152 | 0 | e.printStackTrace(); |
153 | 900 | } |
154 | |
|
155 | |
try { |
156 | 900 | critics.add(new CrOCL("context Stereotype inv: " |
157 | |
+ "self.namespace.stereotype->exists(x|x.name = 'Profile')", |
158 | |
"Stereotypes should be declared inside a Profile. ", |
159 | |
"Please add the <<Profile>> stereotype to " |
160 | |
+ "the containing Namespace", |
161 | |
ToDoItem.MED_PRIORITY, null, null, |
162 | |
"http://argouml.tigris.org/")); |
163 | 0 | } catch (InvalidOclException e) { |
164 | 0 | e.printStackTrace(); |
165 | 900 | } |
166 | |
|
167 | 900 | setCritics(critics); |
168 | 900 | } |
169 | |
|
170 | |
@Override |
171 | |
public String getDisplayName() { |
172 | 195 | return "MetaProfile"; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public Collection getProfilePackages() throws ProfileException { |
177 | 0 | return Collections.unmodifiableCollection(getModel()); |
178 | |
} |
179 | |
|
180 | |
|
181 | |
@Override |
182 | |
public Collection<Object> getLoadedPackages() { |
183 | 0 | if (model == null) { |
184 | 0 | return Collections.emptyList(); |
185 | |
} else { |
186 | 0 | return Collections.unmodifiableCollection(model); |
187 | |
} |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public Set<Critic> getCritics() { |
192 | 1880 | if (critics == null) { |
193 | 900 | loadWellFormednessRules(); |
194 | |
} |
195 | 1880 | return super.getCritics(); |
196 | |
} |
197 | |
|
198 | |
} |