1 package org.andromda.cartridges.spring.metafacades;
2
3 import java.util.Arrays;
4 import java.util.Collection;
5 import org.andromda.cartridges.spring.SpringProfile;
6 import org.andromda.core.common.ExceptionUtils;
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.UMLProfile;
11 import org.apache.commons.collections.CollectionUtils;
12 import org.apache.commons.collections.Predicate;
13 import org.apache.commons.lang.StringUtils;
14
15
16
17
18
19
20
21 class SpringMetafacadeUtils
22 {
23
24
25
26
27
28
29
30
31
32 static String getFullyQualifiedName(String packageName, String name, String suffix)
33 {
34 StringBuilder fullyQualifiedName = new StringBuilder(StringUtils.trimToEmpty(packageName));
35 if (StringUtils.isNotBlank(packageName))
36 {
37 fullyQualifiedName.append('.');
38 }
39 fullyQualifiedName.append(StringUtils.trimToEmpty(name));
40 if (StringUtils.isNotBlank(suffix))
41 {
42 fullyQualifiedName.append(StringUtils.trimToEmpty(suffix));
43 }
44 return fullyQualifiedName.toString();
45 }
46
47
48
49
50
51
52
53
54
55 static String getFullyQualifiedName(String packageName, String name)
56 {
57 return getFullyQualifiedName(packageName, name, null);
58 }
59
60
61
62
63
64
65
66
67 static String getServiceRemotingType(ClassifierFacade classifier, String defaultServiceRemotingType)
68 {
69 ExceptionUtils.checkNull("classifer", classifier);
70 String remotingType = null;
71 if (classifier.hasStereotype(UMLProfile.STEREOTYPE_SERVICE))
72 {
73 String remotingTypeValue = (String)classifier.findTaggedValue(
74 SpringProfile.TAGGEDVALUE_SPRING_SERVICE_REMOTING_TYPE);
75
76 if (StringUtils.isBlank(remotingTypeValue))
77 {
78 remotingType = (String)CollectionUtils.find(classifier.getAllGeneralizations(), new Predicate()
79 {
80 public boolean evaluate(Object object)
81 {
82 return ((ModelElementFacade)object).findTaggedValue(
83 SpringProfile.TAGGEDVALUE_SPRING_SERVICE_REMOTING_TYPE) != null;
84 }
85 });
86 }
87 if (StringUtils.isNotBlank(remotingTypeValue))
88 {
89 remotingType = remotingTypeValue;
90 }
91 }
92 if (StringUtils.isBlank(remotingType) || remotingType == null)
93 {
94 remotingType = defaultServiceRemotingType;
95 }
96 return remotingType.toLowerCase().trim();
97 }
98
99
100
101
102
103
104
105
106
107
108
109 static Collection<String> getServiceInterceptors(ClassifierFacade classifier,
110 Collection<String> defaultInterceptors)
111 {
112 ExceptionUtils.checkNull("classifier", classifier);
113 Collection<String> interceptors = null;
114 if (classifier.hasStereotype(UMLProfile.STEREOTYPE_SERVICE))
115 {
116 String interceptorsValue = (String)classifier.findTaggedValue(
117 SpringProfile.TAGGEDVALUE_SPRING_SERVICE_INTERCEPTORS);
118
119 if (StringUtils.isBlank(interceptorsValue))
120 {
121 interceptorsValue = (String)CollectionUtils.find(classifier.getAllGeneralizations(), new Predicate()
122 {
123 public boolean evaluate(Object object)
124 {
125 return ((ModelElementFacade)object).findTaggedValue(
126 SpringProfile.TAGGEDVALUE_SPRING_SERVICE_INTERCEPTORS) != null;
127 }
128 });
129 }
130
131 if (StringUtils.isNotBlank(interceptorsValue))
132 {
133 interceptors = Arrays.asList(interceptorsValue.split(","));
134 }
135 }
136 if (interceptors == null || interceptors.isEmpty())
137 {
138 interceptors = defaultInterceptors;
139 }
140 return interceptors;
141 }
142
143
144
145
146
147
148
149
150
151 static String getServiceRemotePort(ClassifierFacade classifier, String defaultRemoteServicePort)
152 {
153 ExceptionUtils.checkNull("classifer", classifier);
154 String remoteServicePort = null;
155 if (classifier.hasStereotype(UMLProfile.STEREOTYPE_SERVICE))
156 {
157 String remoteServicePortValue = (String)classifier.findTaggedValue(
158 SpringProfile.TAGGEDVALUE_SPRING_SERVICE_REMOTE_PORT);
159
160 if (StringUtils.isBlank(remoteServicePortValue))
161 {
162 remoteServicePort = (String)CollectionUtils.find(classifier.getAllGeneralizations(), new Predicate()
163 {
164 public boolean evaluate(Object object)
165 {
166 return ((ModelElementFacade)object).findTaggedValue(
167 SpringProfile.TAGGEDVALUE_SPRING_SERVICE_REMOTE_PORT) != null;
168 }
169 });
170 }
171 if (StringUtils.isNotBlank(remoteServicePortValue))
172 {
173 remoteServicePort = remoteServicePortValue;
174 }
175 }
176 if (StringUtils.isBlank(remoteServicePort) || remoteServicePort == null)
177 {
178 remoteServicePort = defaultRemoteServicePort;
179 }
180 return remoteServicePort.toLowerCase().trim();
181 }
182
183
184
185
186
187
188
189
190 static boolean getUseNamedParameters(OperationFacade operation,
191 boolean defaultUseNamedParameters)
192 {
193 ExceptionUtils.checkNull("operation", operation);
194 boolean useNamedParameters = defaultUseNamedParameters;
195 if (operation.isQuery())
196 {
197 String useNamedParametersValue = StringUtils.trimToEmpty((String)operation
198 .findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_USE_NAMED_PARAMETERS));
199 if (StringUtils.isNotBlank(useNamedParametersValue))
200 {
201 useNamedParameters = Boolean.valueOf(useNamedParametersValue).booleanValue();
202 }
203 }
204 return useNamedParameters;
205 }
206 }