1 package org.andromda.core.translation;
2
3 import org.andromda.core.common.ExceptionUtils;
4 import org.apache.commons.lang.StringUtils;
5 import org.apache.commons.lang.builder.ToStringBuilder;
6
7
8
9
10
11
12 public class Expression
13 {
14
15
16
17 private StringBuffer translatedExpression;
18
19
20
21
22
23
24 public Expression(final String originalExpression)
25 {
26 ExceptionUtils.checkEmpty("originalExpression", originalExpression);
27 this.originalExpression = StringUtils.trimToEmpty(originalExpression);
28 this.translatedExpression = new StringBuffer();
29 }
30
31
32
33
34
35
36
37 public void appendToTranslatedExpression(final Object object)
38 {
39 this.translatedExpression.append(object);
40 }
41
42
43
44
45 public void appendSpaceToTranslatedExpression()
46 {
47 this.translatedExpression.append(' ');
48 }
49
50
51
52
53
54
55
56
57 public void replaceInTranslatedExpression(
58 final String pattern,
59 final String replacement)
60 {
61 this.translatedExpression =
62 new StringBuffer(this.getTranslatedExpression().replaceAll(pattern, replacement));
63 }
64
65
66
67
68
69
70
71
72
73 public void insertInTranslatedExpression(
74 final int position,
75 final Object object)
76 {
77 this.translatedExpression.insert(position, object);
78 }
79
80
81
82
83
84
85 public String getTranslatedExpression()
86 {
87 return TranslationUtils.removeExtraWhitespace(this.translatedExpression.toString());
88 }
89
90
91
92
93 private String originalExpression;
94
95
96
97
98
99
100 public String getOriginalExpression()
101 {
102 return TranslationUtils.removeExtraWhitespace(this.originalExpression);
103 }
104
105
106
107
108 private String contextElement;
109
110
111
112
113
114
115 public String getContextElement()
116 {
117 final String methodName = "Expression.getContextElement";
118 if (this.contextElement == null)
119 {
120 throw new ExpressionException(methodName + " - contextElement can not be null");
121 }
122 return this.contextElement;
123 }
124
125
126
127
128 private String kind;
129
130
131
132
133
134
135 public String getKind()
136 {
137 final String methodName = "Expression.getKind";
138 if (this.contextElement == null)
139 {
140 throw new ExpressionException(methodName + " - kind can not be null");
141 }
142 return this.kind;
143 }
144
145
146
147
148 private String name;
149
150
151
152
153
154
155 public String getName()
156 {
157 return name;
158 }
159
160
161
162
163
164
165 public void setName(final String name)
166 {
167 this.name = name;
168 }
169
170
171
172
173
174
175
176 public void setContextElement(final String contextElement)
177 {
178 this.contextElement = contextElement;
179 }
180
181
182
183
184
185
186 public void setKind(final String kind)
187 {
188 this.kind = kind;
189 }
190
191
192
193
194 public String toString()
195 {
196 return ToStringBuilder.reflectionToString(this);
197 }
198 }