1 package org.andromda.cartridges.webservice.metafacades;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import org.andromda.cartridges.webservice.WebServiceGlobals;
6 import org.andromda.cartridges.webservice.WebServiceUtils;
7 import org.andromda.metafacades.uml.ClassifierFacade;
8 import org.andromda.metafacades.uml.ModelElementFacade;
9 import org.andromda.metafacades.uml.OperationFacade;
10 import org.andromda.metafacades.uml.TypeMappings;
11 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
12 import org.andromda.metafacades.uml.UMLProfile;
13 import org.apache.commons.lang.StringUtils;
14 import org.apache.log4j.Logger;
15
16
17
18
19
20
21
22 public class WSDLTypeLogicImpl
23 extends WSDLTypeLogic
24 {
25 private static final long serialVersionUID = 34L;
26
27
28
29
30
31
32 public WSDLTypeLogicImpl(Object metaObject, String context)
33 {
34 super(metaObject, context);
35 }
36
37
38
39
40 private static final Logger logger = Logger.getLogger(WSDLTypeLogicImpl.class);
41
42
43
44
45
46 public String handleGetSchemaType()
47 {
48 return this.getSchemaType(true, true);
49 }
50
51
52
53
54
55
56
57 public String handleGetSchemaType(boolean withPrefix, boolean preserveArray)
58 {
59 return WebServiceUtils.getSchemaType(this, this.getSchemaTypeMappings(), this.getNamespacePrefix(),
60 this.getName(), this.getWsdlArrayNamePrefix(), withPrefix, preserveArray);
61 }
62
63
64
65
66
67 protected String handleGetWsdlArrayName()
68 {
69 StringBuilder name = new StringBuilder(StringUtils.trimToEmpty(this.getName()).replaceAll("\\[\\]", ""));
70 name.insert(0, this.getWsdlArrayNamePrefix());
71 return name.toString();
72 }
73
74
75
76
77
78 protected String handleGetWsdlArrayNamePrefix()
79 {
80 return String.valueOf(this.getConfiguredProperty(WebServiceGlobals.ARRAY_NAME_PREFIX));
81 }
82
83
84
85
86
87 protected String handleGetQName()
88 {
89 return this.getQualfiedNameLocalPartPattern().replaceAll("\\{0\\}", StringUtils.trimToEmpty(this.getName()));
90 }
91
92
93
94
95
96 protected String handleGetNamespace()
97 {
98 String packageName = this.getPackageName();
99 if (this.isReverseNamespace())
100 {
101 packageName = WebServiceUtils.reversePackage(packageName);
102 }
103 return this.getNamespacePattern().replaceAll("\\{0\\}", StringUtils.trimToEmpty(packageName));
104 }
105
106
107
108
109
110
111 private String getArraySuffix()
112 {
113 return String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.ARRAY_NAME_SUFFIX));
114 }
115
116
117
118
119
120
121 private TypeMappings getSchemaTypeMappings()
122 {
123 final String propertyName = WebServiceGlobals.SCHEMA_TYPE_MAPPINGS_URI;
124 Object property = this.getConfiguredProperty(propertyName);
125 TypeMappings mappings = null;
126 String uri = null;
127 if (property instanceof String)
128 {
129 uri = (String)property;
130 try
131 {
132 mappings = TypeMappings.getInstance(uri);
133 mappings.setArraySuffix(this.getArraySuffix());
134 this.setProperty(propertyName, mappings);
135 }
136 catch (Throwable th)
137 {
138 String errMsg = "Error getting '" + propertyName + "' --> '" + uri + '\'';
139 logger.error(errMsg, th);
140
141 }
142 }
143 else
144 {
145 mappings = (TypeMappings)property;
146 }
147 return mappings;
148 }
149
150
151
152
153 protected String handleGetNamespacePrefix()
154 {
155 return (String)this.getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PREFIX);
156 }
157
158
159
160
161
162 protected String getQualfiedNameLocalPartPattern()
163 {
164 return (String)this.getConfiguredProperty(WebServiceLogicImpl.QNAME_LOCAL_PART_PATTERN);
165 }
166
167
168
169
170
171 protected String getNamespacePattern()
172 {
173 return (String)this.getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PATTERN);
174 }
175
176
177
178
179
180
181 private boolean isReverseNamespace()
182 {
183 return Boolean.valueOf(String.valueOf(this.getConfiguredProperty(WebServiceLogicImpl.REVERSE_NAMESPACE)))
184 .booleanValue();
185 }
186
187
188
189
190 @Override
191 protected boolean handleIsWebFaultAnException()
192 {
193 boolean result = true;
194 if (this.hasStereotype(UMLProfile.STEREOTYPE_WEB_FAULT))
195 {
196 if (!this.hasStereotype(UMLProfile.STEREOTYPE_APPLICATION_EXCEPTION) &&
197 !this.hasStereotype(UMLProfile.STEREOTYPE_UNEXPECTED_EXCEPTION) &&
198 !this.hasStereotype(UMLProfile.STEREOTYPE_EXCEPTION))
199 {
200 result = false;
201 }
202 }
203 return result;
204 }
205
206 private static final List<WebServiceOperation> weboperations = new ArrayList<WebServiceOperation>();
207
208
209
210 @Override
211 protected boolean handleIsWebFaultThrown()
212 {
213 boolean result = true;
214 if (this.hasStereotype(UMLProfile.STEREOTYPE_WEB_FAULT))
215 {
216 result = false;
217
218 if (weboperations.isEmpty())
219 {
220 for (ClassifierFacade classifier : this.getModel().getAllClasses())
221 {
222 boolean isService = classifier.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE);
223 for (OperationFacade operation : classifier.getOperations())
224 {
225 boolean visibility = operation.getVisibility().equals("public") || operation.getVisibility().equals("protected");
226 if (visibility && (isService || operation.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE)))
227 {
228 weboperations.add((WebServiceOperation)operation);
229 }
230 }
231 }
232 }
233 for (WebServiceOperation op : weboperations)
234 {
235 for (Object exception : op.getExceptions())
236 {
237 if (((ModelElementFacade)exception).getFullyQualifiedName().equals(this.getFullyQualifiedName()))
238 {
239
240 result = true;
241 break;
242 }
243 }
244 }
245 }
246 return result;
247 }
248 }