Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CrOCL |
|
| 4.25;4.25 |
1 | /* $Id: CrOCL.java 17836 2010-01-12 19:06:55Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2008 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.profile.internal.ocl; | |
40 | ||
41 | import java.util.List; | |
42 | import java.util.Set; | |
43 | ||
44 | import org.argouml.cognitive.Decision; | |
45 | import org.argouml.cognitive.Designer; | |
46 | import org.argouml.cognitive.ToDoItem; | |
47 | import org.argouml.profile.internal.ocl.uml14.Uml14ModelInterpreter; | |
48 | import org.argouml.uml.cognitive.UMLDecision; | |
49 | import org.argouml.uml.cognitive.critics.CrUML; | |
50 | ||
51 | /** | |
52 | * Represents an critics defined as an OCL expression in a profile | |
53 | * | |
54 | * @author maurelio1234 | |
55 | */ | |
56 | public class CrOCL extends CrUML { | |
57 | ||
58 | /** | |
59 | * the OCL Interpreter | |
60 | */ | |
61 | 16200 | private OclInterpreter interpreter = null; |
62 | ||
63 | /** | |
64 | * the OCL string | |
65 | */ | |
66 | 16200 | private String ocl = null; |
67 | ||
68 | /** | |
69 | * the design materials to be criticized | |
70 | */ | |
71 | private Set<Object> designMaterials; | |
72 | ||
73 | /** | |
74 | * Creates a new OCL critic | |
75 | * | |
76 | * @param oclConstraint ocl expression | |
77 | * @param headline headline | |
78 | * @param description description | |
79 | * @param moreInfoURL the info url | |
80 | * @param knowledgeTypes the knowledge types | |
81 | * @param supportedDecisions the decisions | |
82 | * @param priority the priority | |
83 | * @throws InvalidOclException if the ocl is not valid | |
84 | * | |
85 | * TODO: Do these need to be Lists or can they be simple Collections? | |
86 | */ | |
87 | public CrOCL(String oclConstraint, String headline, String description, | |
88 | Integer priority, List<Decision> supportedDecisions, | |
89 | List<String> knowledgeTypes, String moreInfoURL) | |
90 | 16200 | throws InvalidOclException { |
91 | 16200 | interpreter = |
92 | new OclInterpreter(oclConstraint, new Uml14ModelInterpreter()); | |
93 | 16200 | this.ocl = oclConstraint; |
94 | ||
95 | 16200 | addSupportedDecision(UMLDecision.PLANNED_EXTENSIONS); |
96 | 16200 | setPriority(ToDoItem.HIGH_PRIORITY); |
97 | ||
98 | 16200 | List<String> triggers = interpreter.getTriggers(); |
99 | 16200 | designMaterials = interpreter.getCriticizedDesignMaterials(); |
100 | ||
101 | 16200 | for (String string : triggers) { |
102 | 16200 | addTrigger(string); |
103 | } | |
104 | ||
105 | 16200 | if (headline == null) { |
106 | 0 | super.setHeadline("OCL Expression"); |
107 | } else { | |
108 | 16200 | super.setHeadline(headline); |
109 | } | |
110 | ||
111 | 16200 | if (description == null) { |
112 | 900 | super.setDescription(""); |
113 | } else { | |
114 | 15300 | super.setDescription(description); |
115 | } | |
116 | ||
117 | 16200 | if (priority == null) { |
118 | 0 | setPriority(ToDoItem.HIGH_PRIORITY); |
119 | } else { | |
120 | 16200 | setPriority(priority); |
121 | } | |
122 | ||
123 | 16200 | if (supportedDecisions != null) { |
124 | 0 | for (Decision d : supportedDecisions) { |
125 | 0 | addSupportedDecision(d); |
126 | } | |
127 | } | |
128 | ||
129 | 16200 | if (knowledgeTypes != null) { |
130 | 0 | for (String k : knowledgeTypes) { |
131 | 0 | addKnowledgeType(k); |
132 | } | |
133 | } | |
134 | ||
135 | 16200 | if (moreInfoURL != null) { |
136 | 16200 | setMoreInfoURL(moreInfoURL); |
137 | } | |
138 | 16200 | } |
139 | ||
140 | ||
141 | /* | |
142 | * @see org.argouml.cognitive.Critic#getCriticizedDesignMaterials() | |
143 | */ | |
144 | @Override | |
145 | public Set<Object> getCriticizedDesignMaterials() { | |
146 | 16200 | return designMaterials; |
147 | } | |
148 | ||
149 | /* | |
150 | * @see org.argouml.uml.cognitive.critics.CrUML#predicate2(java.lang.Object, | |
151 | * org.argouml.cognitive.Designer) | |
152 | */ | |
153 | @Override | |
154 | public boolean predicate2(Object dm, Designer dsgr) { | |
155 | 106875 | if (!interpreter.applicable(dm)) { |
156 | 106875 | return NO_PROBLEM; |
157 | } else { | |
158 | 0 | if (interpreter.check(dm)) { |
159 | 0 | return NO_PROBLEM; |
160 | } else { | |
161 | 0 | return PROBLEM_FOUND; |
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | /** | |
167 | * @return the ocl constraint | |
168 | */ | |
169 | public String getOCL() { | |
170 | 0 | return ocl; |
171 | } | |
172 | ||
173 | } |