1 package org.andromda.metafacades.emf.uml22;
2
3 import java.util.List;
4 import org.andromda.core.translation.Expression;
5 import org.andromda.core.translation.ExpressionTranslator;
6 import org.andromda.metafacades.uml.UMLMetafacadeUtils;
7 import org.andromda.translation.ocl.ExpressionKinds;
8 import org.eclipse.uml2.uml.Constraint;
9 import org.eclipse.uml2.uml.Element;
10
11
12
13
14
15
16
17 public class ConstraintFacadeLogicImpl
18 extends ConstraintFacadeLogic
19 {
20 private static final long serialVersionUID = -8431289709042079686L;
21
22
23
24
25
26 public ConstraintFacadeLogicImpl(
27 final Constraint metaObject,
28 final String context)
29 {
30 super(metaObject, context);
31 }
32
33
34
35
36 @Override
37 protected String handleGetBody()
38 {
39 String body = null;
40 if (this.metaObject.getSpecification() != null)
41 {
42 body = this.metaObject.getSpecification().stringValue();
43 }
44 return body;
45 }
46
47
48
49
50 @Override
51 protected boolean handleIsInvariant()
52 {
53 return UMLMetafacadeUtils.isConstraintKind(
54 this.getBody(),
55 ExpressionKinds.INV);
56 }
57
58
59
60
61 @Override
62 protected boolean handleIsPreCondition()
63 {
64 return UMLMetafacadeUtils.isConstraintKind(
65 this.getBody(),
66 ExpressionKinds.PRE);
67 }
68
69
70
71
72 @Override
73 protected boolean handleIsPostCondition()
74 {
75 return UMLMetafacadeUtils.isConstraintKind(
76 this.getBody(),
77 ExpressionKinds.POST);
78 }
79
80
81
82
83 @Override
84 protected boolean handleIsDefinition()
85 {
86 return UMLMetafacadeUtils.isConstraintKind(
87 this.getBody(),
88 ExpressionKinds.DEF);
89 }
90
91
92
93
94 @Override
95 protected boolean handleIsBodyExpression()
96 {
97 return UMLMetafacadeUtils.isConstraintKind(
98 this.getBody(),
99 ExpressionKinds.BODY);
100 }
101
102
103
104
105 @Override
106 protected String handleGetTranslation(final String language)
107 {
108 final Expression expression =
109 ExpressionTranslator.instance().translate(
110 language,
111 this.getBody(),
112 this.getContextElement());
113 return expression == null ? null : expression.getTranslatedExpression();
114 }
115
116
117
118
119 @Override
120 protected Element handleGetContextElement()
121 {
122 Element element = null;
123 final List<Element> elements = this.metaObject.getConstrainedElements();
124 if (elements != null && !elements.isEmpty())
125 {
126 element = elements.get(0);
127 }
128 return element;
129 }
130 }