1 package org.andromda.metafacades.uml14;
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.apache.commons.lang.StringEscapeUtils;
9 import org.apache.commons.lang.StringUtils;
10 import org.omg.uml.foundation.core.Constraint;
11
12
13
14
15
16
17
18 public class ConstraintFacadeLogicImpl
19 extends ConstraintFacadeLogic
20 {
21 private static final long serialVersionUID = 34L;
22
23
24
25
26 public ConstraintFacadeLogicImpl(
27 Constraint metaObject,
28 String context)
29 {
30 super(metaObject, context);
31 }
32
33
34
35
36 @Override
37 public String handleGetBody()
38 {
39 String body = null;
40 if (this.metaObject.getBody() != null)
41 {
42 body = this.metaObject.getBody().getBody();
43 }
44 return body;
45 }
46
47
48
49
50 @Override
51 public Object handleGetContextElement()
52 {
53 Object element = null;
54 final List elements = this.metaObject.getConstrainedElement();
55 if (elements != null && !elements.isEmpty())
56 {
57 element = elements.get(0);
58 }
59 return element;
60 }
61
62
63
64
65 @Override
66 public boolean handleIsInvariant()
67 {
68 return UMLMetafacadeUtils.isConstraintKind(
69 this.getBody(),
70 ExpressionKinds.INV);
71 }
72
73
74
75
76 @Override
77 public boolean handleIsPreCondition()
78 {
79 return UMLMetafacadeUtils.isConstraintKind(
80 this.getBody(),
81 ExpressionKinds.PRE);
82 }
83
84
85
86
87 @Override
88 public boolean handleIsPostCondition()
89 {
90 return UMLMetafacadeUtils.isConstraintKind(
91 this.getBody(),
92 ExpressionKinds.POST);
93 }
94
95
96
97
98 @Override
99 public boolean handleIsDefinition()
100 {
101 return UMLMetafacadeUtils.isConstraintKind(
102 this.getBody(),
103 ExpressionKinds.DEF);
104 }
105
106
107
108
109 @Override
110 public boolean handleIsBodyExpression()
111 {
112 return UMLMetafacadeUtils.isConstraintKind(
113 this.getBody(),
114 ExpressionKinds.BODY);
115 }
116
117
118
119
120 @Override
121 public String handleGetTranslation(String language)
122 {
123 final Expression expression =
124 ExpressionTranslator.instance().translate(
125 language,
126 this.getBody(),
127 this.getContextElement());
128 return expression == null ? null : expression.getTranslatedExpression();
129 }
130
131
132
133
134 public String getDocumentation(
135 String indent,
136 int lineLength,
137 boolean htmlStyle)
138 {
139 String documentation = super.getDocumentation(indent, lineLength, htmlStyle);
140 boolean isBlank;
141
142 if (htmlStyle)
143 {
144 final String plainDocumentation = super.getDocumentation(indent, lineLength, false);
145 isBlank = StringUtils.isBlank(plainDocumentation);
146 }
147 else
148 {
149 isBlank = StringUtils.isBlank(documentation);
150 }
151
152 if (isBlank)
153 {
154 documentation = "An undocumented constraint has been violated: " + StringEscapeUtils.escapeJava(getBody());
155 }
156 return documentation;
157 }
158 }