1 package org.andromda.cartridges.ejb3.metafacades;
2
3 import java.text.MessageFormat;
4 import org.andromda.cartridges.ejb3.EJB3Globals;
5 import org.andromda.cartridges.ejb3.EJB3Profile;
6 import org.andromda.cartridges.ejb3.EJB3ScriptHelper;
7 import org.andromda.metafacades.uml.OperationFacade;
8 import org.andromda.metafacades.uml.UMLProfile;
9 import org.apache.commons.collections.CollectionUtils;
10 import org.apache.commons.collections.Predicate;
11 import org.apache.commons.lang.StringUtils;
12
13
14
15
16
17
18 public class EJB3WebServiceFacadeLogicImpl
19 extends EJB3WebServiceFacadeLogic
20 {
21 private static final long serialVersionUID = 34L;
22
23
24
25 private static final String WEB_SERVICE_INTERFACE_NAME_PATTERN = "webServiceInterfaceNamePattern";
26
27
28
29
30 private static final String PROPERTY_DEFAULT_STYLE = "webServiceDefaultStyle";
31
32
33
34
35 private static final String STYLE_DOCUMENT = "document";
36
37
38
39
40 private static final String STYLE_RPC = "rpc";
41
42
43
44
45 private static final String PROPERTY_DEFAULT_USE = "webServiceDefaultUse";
46
47
48
49
50 private static final String USE_LITERAL = "literal";
51
52
53
54
55 private static final String USE_ENCODED = "encoded";
56
57
58
59
60 private static final String PROPERTY_DEFAULT_PARAMETER_STYLE = "webServiceDefaultParameterStyle";
61
62
63
64
65 private static final String PARAMETER_STYLE_WRAPPED = "wrapped";
66
67
68
69
70 private static final String PARAMETER_STYLE_BARE = "bare";
71
72
73
74
75 private static final String QNAME_LOCAL_PART_PATTERN = "webServiceQualifiedNameLocalPartPattern";
76
77
78
79
80 private static final String REVERSE_NAMESPACE = "webServiceReverseNamespace";
81
82
83
84
85 private static final String NAMESPACE_PATTERN = "webServiceNamespacePattern";
86
87
88
89
90
91
92 public EJB3WebServiceFacadeLogicImpl(final Object metaObject, final String context)
93 {
94 super (metaObject, context);
95 }
96
97
98
99
100 @Override
101 protected String handleGetFullyQualifiedWebServiceInterfaceName()
102 {
103 return EJB3MetafacadeUtils.getFullyQualifiedName(
104 this.getPackageName(),
105 this.getWebServiceInterfaceName(),
106 null);
107 }
108
109
110
111
112 @Override
113 protected String handleGetWebServiceInterfaceName()
114 {
115 String webServiceInterfaceNamePattern =
116 String.valueOf(this.getConfiguredProperty(WEB_SERVICE_INTERFACE_NAME_PATTERN));
117
118 return MessageFormat.format(
119 webServiceInterfaceNamePattern,
120 StringUtils.trimToEmpty(this.getName()));
121 }
122
123
124
125
126 @Override
127 protected String handleGetStyle()
128 {
129 String style = (String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_WEBSERVICE_STYLE);
130 if (StringUtils.isBlank(style))
131 {
132 style = String.valueOf(this.getConfiguredProperty(PROPERTY_DEFAULT_STYLE));
133 }
134 return style;
135 }
136
137
138
139
140 @Override
141 protected String handleGetUse()
142 {
143 String use = (String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_WEBSERVICE_USE);
144 if (StringUtils.isBlank(use))
145 {
146 use = String.valueOf(this.getConfiguredProperty(PROPERTY_DEFAULT_USE));
147 }
148 return use;
149 }
150
151
152
153
154 @Override
155 protected boolean handleIsRpcStyle()
156 {
157 return STYLE_RPC.equalsIgnoreCase(this.getStyle());
158 }
159
160
161
162
163 @Override
164 protected boolean handleIsDocumentStyle()
165 {
166 return STYLE_DOCUMENT.equalsIgnoreCase(this.getStyle());
167 }
168
169
170
171
172 @Override
173 protected boolean handleIsEncodedUse()
174 {
175 return USE_ENCODED.equalsIgnoreCase(this.getStyle());
176 }
177
178
179
180
181 @Override
182 protected boolean handleIsLiteralUse()
183 {
184 return USE_LITERAL.equalsIgnoreCase(this.getStyle());
185 }
186
187
188
189
190 @Override
191 protected boolean handleIsWebServiceOperationsExist()
192 {
193 return CollectionUtils.find(
194 this.getOperations(),
195 new Predicate()
196 {
197 public boolean evaluate(final Object object)
198 {
199 boolean isWebService = false;
200 final OperationFacade operation = (OperationFacade)object;
201 if (operation.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE_OPERATION))
202 {
203 isWebService = true;
204 }
205 return isWebService;
206 }
207 }) != null;
208 }
209
210
211
212
213 @Override
214 protected String handleGetParameterStyle()
215 {
216 String parameterStyle = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_WEBSERVICE_PARAMETER_STYLE);
217 if (StringUtils.isBlank(parameterStyle))
218 {
219 parameterStyle = String.valueOf(this.getConfiguredProperty(PROPERTY_DEFAULT_PARAMETER_STYLE));
220 }
221 return parameterStyle;
222 }
223
224
225
226
227 @Override
228 protected boolean handleIsWrappedParameterStyle()
229 {
230 return PARAMETER_STYLE_WRAPPED.equalsIgnoreCase(this.getParameterStyle());
231 }
232
233
234
235
236 @Override
237 protected boolean handleIsBareParameterStyle()
238 {
239 return PARAMETER_STYLE_BARE.equalsIgnoreCase(this.getParameterStyle());
240 }
241
242
243
244
245 @Override
246 protected String handleGetQName()
247 {
248 String qnameLocalPartPattern = String.valueOf(this.getConfiguredProperty(QNAME_LOCAL_PART_PATTERN));
249 return MessageFormat.format(
250 qnameLocalPartPattern,
251 StringUtils.trimToEmpty(this.getName()));
252 }
253
254
255
256
257 @Override
258 protected String handleGetNamespace()
259 {
260 String packageName = this.getPackageName();
261 if (this.isReverseNamespace())
262 {
263 packageName = EJB3ScriptHelper.reversePackage(packageName);
264 }
265 String namespacePattern = String.valueOf(this.getConfiguredProperty(NAMESPACE_PATTERN));
266 return MessageFormat.format(
267 namespacePattern,
268 StringUtils.trimToEmpty(
269 StringUtils.substringBeforeLast(packageName, String.valueOf(EJB3Globals.NAMESPACE_DELIMITER))),
270 StringUtils.trimToEmpty(
271 StringUtils.substringAfterLast(packageName, String.valueOf(EJB3Globals.NAMESPACE_DELIMITER))));
272 }
273
274
275
276
277
278
279 protected boolean isReverseNamespace()
280 {
281 return Boolean.valueOf(String.valueOf(this.getConfiguredProperty(REVERSE_NAMESPACE))).booleanValue();
282 }
283 }