1 package org.andromda.cartridges.ejb3.metafacades;
2
3 import java.text.MessageFormat;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.LinkedHashSet;
7 import java.util.List;
8 import org.andromda.cartridges.ejb3.EJB3Globals;
9 import org.andromda.cartridges.ejb3.EJB3Profile;
10 import org.andromda.metafacades.uml.DependencyFacade;
11 import org.andromda.metafacades.uml.ModelElementFacade;
12 import org.andromda.metafacades.uml.OperationFacade;
13 import org.andromda.metafacades.uml.Role;
14 import org.andromda.metafacades.uml.UMLProfile;
15 import org.apache.commons.collections.Closure;
16 import org.apache.commons.collections.CollectionUtils;
17 import org.apache.commons.collections.Predicate;
18 import org.apache.commons.collections.Transformer;
19 import org.apache.commons.lang.BooleanUtils;
20 import org.apache.commons.lang.ObjectUtils;
21 import org.apache.commons.lang.StringUtils;
22
23
24
25
26
27
28 public class EJB3SessionFacadeLogicImpl
29 extends EJB3SessionFacadeLogic
30 {
31 private static final long serialVersionUID = 34L;
32
33
34
35 public static final String SERVICE_NAME_PATTERN = "serviceNamePattern";
36
37
38
39
40 public static final String SERVICE_INTERFACE_NAME_PATTERN = "serviceInterfaceNamePattern";
41
42
43
44
45 public static final String SERVICE_LOCAL_INTERFACE_NAME_PATTERN = "serviceLocalInterfaceNamePattern";
46
47
48
49
50 private static final String SERVICE_REMOTE_INTERFACE_NAME_PATTERN = "serviceRemoteInterfaceNamePattern";
51
52
53
54
55 private static final String SERVICE_LISTENER_NAME_PATTERN = "serviceListenerNamePattern";
56
57
58
59
60 private static final String SERVICE_IMPLEMENTATION_NAME_PATTERN = "serviceImplementationNamePattern";
61
62
63
64
65 private static final String SERVICE_DELEGATE_NAME_PATTERN = "serviceDelegateNamePattern";
66
67
68
69
70 private static final String SERVICE_BASE_NAME_PATTERN = "serviceBaseNamePattern";
71
72
73
74
75 private static final String SERVICE_TEST_NAME_PATTERN = "serviceTestNamePattern";
76
77
78
79
80 private static final String SERVICE_TEST_PACKAGE_NAME_PATTERN = "serviceTestPackageNamePattern";
81
82
83
84
85
86 private static final String SERVICE_DEFAULT_EXCEPTION_NAME_PATTERN = "defaultServiceExceptionNamePattern";
87
88
89
90
91 public static final String PERSISTENCE_CONTAINER = "persistenceContainerName";
92
93
94
95 public static final String DEPLOYMENT_PLATFORM = "deploymentPlatform";
96
97
98
99
100
101 private static final String PERSISTENCE_CONTEXT_UNIT_NAME = "persistenceContextUnitName";
102
103
104
105
106 public static final String SERVICE_DEFAULT_VIEW_TYPE = "serviceViewType";
107
108
109
110
111 public static final String ALLOW_DEFAULT_SERVICE_EXCEPTION = "allowDefaultServiceException";
112
113
114
115
116 public static final String SERVICE_JNDI_NAME_PREFIX = "jndiNamePrefix";
117
118
119
120
121 public static final String SERVICE_ENABLE_CLUSTERING = "enableClustering";
122
123
124
125
126 private static final String PROPERTY_WEBSERVICE_ENABLED = "webServiceEnabled";
127
128
129
130
131
132
133
134 public EJB3SessionFacadeLogicImpl(final Object metaObject, final String context)
135 {
136 super (metaObject, context);
137 }
138
139
140
141
142
143
144 @Override
145 protected boolean handleIsSyntheticCreateMethodAllowed()
146 {
147 return EJB3MetafacadeUtils.allowSyntheticCreateMethod(this);
148 }
149
150
151
152
153
154 protected Collection handleGetBusinessOperations()
155 {
156 Collection operations = super.getOperations();
157 CollectionUtils.filter(
158 operations,
159 new Predicate()
160 {
161 public boolean evaluate(Object object)
162 {
163 boolean businessOperation = false;
164 if (EJB3SessionOperationFacade.class.isAssignableFrom(object.getClass()))
165 {
166 businessOperation = ((EJB3SessionOperationFacade)object).isBusinessOperation();
167 }
168 return businessOperation;
169 }
170 });
171 return operations;
172 }
173
174
175
176
177
178 protected List handleGetAllInstanceAttributes()
179 {
180 return EJB3MetafacadeUtils.getAllInstanceAttributes(this);
181
182
183
184
185
186
187
188 }
189
190
191
192
193
194 protected List handleGetInheritedInstanceAttributes()
195 {
196 return EJB3MetafacadeUtils.getInheritedInstanceAttributes(this);
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 }
214
215
216
217
218 protected Collection handleFilterSeamAttributes(Collection attributes)
219 {
220 CollectionUtils.filter(
221 attributes,
222 new Predicate()
223 {
224 public boolean evaluate(Object object)
225 {
226 boolean isSeamAttribute = false;
227 if (((EJB3SessionAttributeFacade)object).isSeamAttribute())
228 {
229 isSeamAttribute = true;
230 }
231 return !isSeamAttribute;
232 }
233 });
234 return attributes;
235 }
236
237
238
239
240 @Override
241 protected String handleGetJndiNameRemote()
242 {
243 String jndiName = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SESSION_JNDI_NAME_REMOTE);
244 if (StringUtils.isNotBlank(jndiName))
245 {
246 jndiName = this.getJndiNamePrefix() + "/" + jndiName;
247 }
248 return jndiName;
249 }
250
251
252
253
254 @Override
255 protected String handleGetJndiNameLocal()
256 {
257 String jndiName = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SESSION_JNDI_NAME_Local);
258 if (StringUtils.isNotBlank(jndiName))
259 {
260 jndiName = this.getJndiNamePrefix() + "/" + jndiName;
261 }
262 return jndiName;
263 }
264
265
266
267
268 @Override
269 protected String handleGetJndiNamePrefix()
270 {
271 return this.isConfiguredProperty(SERVICE_JNDI_NAME_PREFIX) ?
272 ObjectUtils.toString(this.getConfiguredProperty(SERVICE_JNDI_NAME_PREFIX)) : null;
273 }
274
275
276
277
278 @Override
279 protected boolean handleIsStateful()
280 {
281 boolean isStateful = false;
282 String sessionType = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SESSION_TYPE);
283 if (StringUtils.isBlank(sessionType))
284 {
285 isStateful = !isStateless();
286 }
287 else
288 {
289 isStateful = sessionType.equalsIgnoreCase(EJB3Globals.SERVICE_TYPE_STATEFUL);
290 }
291 return isStateful;
292 }
293
294
295
296
297 @Override
298 protected boolean handleIsStateless()
299 {
300 boolean isStateless = false;
301 String sessionType = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SESSION_TYPE);
302 if (StringUtils.isBlank(sessionType))
303 {
304 isStateless =
305 this.getAllInstanceAttributes() == null ||
306 this.filterSeamAttributes(this.getAllInstanceAttributes()).isEmpty();
307 }
308 else
309 {
310 isStateless = sessionType.equalsIgnoreCase(EJB3Globals.SERVICE_TYPE_STATELESS);
311 }
312 return isStateless;
313 }
314
315
316
317
318 @Override
319 protected String handleGetType()
320 {
321 String sessionType = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SESSION_TYPE);
322 if (StringUtils.isBlank(sessionType))
323 {
324 sessionType = "Stateful";
325 if (this.isStateless())
326 {
327 sessionType = "Stateless";
328 }
329 }
330 return sessionType;
331 }
332
333
334
335
336 @Override
337 protected String handleGetViewType()
338 {
339 String viewType = EJB3MetafacadeUtils.getViewType(this,
340 String.valueOf(this.getConfiguredProperty(SERVICE_DEFAULT_VIEW_TYPE)));
341
342
343
344
345
346
347
348
349
350
351 if (viewType.equalsIgnoreCase(EJB3Globals.VIEW_TYPE_LOCAL))
352 {
353 boolean operationWithRemoteViewExists =
354 CollectionUtils.exists(
355 this.getBusinessOperations(),
356 new Predicate()
357 {
358 public boolean evaluate(Object object)
359 {
360 EJB3SessionOperationFacade operation = (EJB3SessionOperationFacade)object;
361 String operationViewType =
362 String.valueOf(operation.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_VIEWTYPE));
363 if (operationViewType.equalsIgnoreCase(EJB3Globals.VIEW_TYPE_REMOTE) ||
364 operationViewType.equalsIgnoreCase(EJB3Globals.VIEW_TYPE_BOTH))
365 {
366 return true;
367 }
368 else
369 {
370 return false;
371 }
372 }
373 });
374 viewType = (operationWithRemoteViewExists ? EJB3Globals.VIEW_TYPE_BOTH : viewType);
375 }
376 else if (viewType.equalsIgnoreCase(EJB3Globals.VIEW_TYPE_REMOTE))
377 {
378 boolean operationWithLocalViewExists =
379 CollectionUtils.exists(
380 this.getBusinessOperations(),
381 new Predicate()
382 {
383 public boolean evaluate(Object object)
384 {
385 EJB3SessionOperationFacade operation = (EJB3SessionOperationFacade)object;
386 String operationViewType =
387 String.valueOf(operation.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_VIEWTYPE));
388 if (operationViewType.equalsIgnoreCase(EJB3Globals.VIEW_TYPE_LOCAL) ||
389 operationViewType.equalsIgnoreCase(EJB3Globals.VIEW_TYPE_BOTH))
390 {
391 return true;
392 }
393 else
394 {
395 return false;
396 }
397 }
398 });
399 viewType = (operationWithLocalViewExists ? EJB3Globals.VIEW_TYPE_BOTH : viewType);
400 }
401 return viewType;
402 }
403
404
405
406
407 @Override
408 protected boolean handleIsViewTypeLocal()
409 {
410 boolean isLocal = false;
411 if (this.getViewType().equalsIgnoreCase(EJB3Globals.VIEW_TYPE_LOCAL) || this.isViewTypeBoth() ||
412 this.isSeamComponent())
413 {
414 isLocal = true;
415 }
416 return isLocal;
417 }
418
419
420
421
422 @Override
423 protected boolean handleIsViewTypeRemote()
424 {
425 boolean isRemote = false;
426 if (this.getViewType().equalsIgnoreCase(EJB3Globals.VIEW_TYPE_REMOTE) || this.isViewTypeBoth())
427 {
428 isRemote = true;
429 }
430 return isRemote;
431 }
432
433
434
435
436 @Override
437 protected boolean handleIsViewTypeBoth()
438 {
439 boolean isBoth = false;
440 if (this.getViewType().equalsIgnoreCase(EJB3Globals.VIEW_TYPE_BOTH))
441 {
442 isBoth = true;
443 }
444 return isBoth;
445 }
446
447
448
449
450 @Override
451 protected boolean handleIsViewTypeStrictlyLocal()
452 {
453
454 boolean isViewTypeStrictlyLocal = false;
455 String viewType = EJB3MetafacadeUtils.getViewType(this,
456 String.valueOf(this.getConfiguredProperty(SERVICE_DEFAULT_VIEW_TYPE)));
457 if (StringUtils.equalsIgnoreCase(viewType, EJB3Globals.VIEW_TYPE_LOCAL) ||
458 StringUtils.equalsIgnoreCase(viewType, EJB3Globals.VIEW_TYPE_BOTH))
459 {
460 isViewTypeStrictlyLocal = true;
461 }
462 return isViewTypeStrictlyLocal;
463 }
464
465
466
467
468 @Override
469 protected boolean handleIsViewTypeStrictlyRemote()
470 {
471 boolean isViewTypeStrictlyRemote = false;
472 String viewType = EJB3MetafacadeUtils.getViewType(this,
473 String.valueOf(this.getConfiguredProperty(SERVICE_DEFAULT_VIEW_TYPE)));
474 if (StringUtils.equalsIgnoreCase(viewType, EJB3Globals.VIEW_TYPE_REMOTE) ||
475 StringUtils.equalsIgnoreCase(viewType, EJB3Globals.VIEW_TYPE_BOTH))
476 {
477 isViewTypeStrictlyRemote = true;
478 }
479 return isViewTypeStrictlyRemote;
480 }
481
482
483
484
485 @Override
486 protected boolean handleIsViewTypeStrictlyBoth()
487 {
488 boolean isViewTypeStrictlyBoth = false;
489 String viewType = EJB3MetafacadeUtils.getViewType(this,
490 String.valueOf(this.getConfiguredProperty(SERVICE_DEFAULT_VIEW_TYPE)));
491 if (StringUtils.equalsIgnoreCase(viewType, EJB3Globals.VIEW_TYPE_BOTH))
492 {
493 isViewTypeStrictlyBoth = true;
494 }
495 return isViewTypeStrictlyBoth;
496 }
497
498
499
500
501 @Override
502 protected String handleGetHomeInterfaceName()
503 {
504 return EJB3MetafacadeUtils.getHomeInterfaceName(this);
505 }
506
507
508
509
510 @Override
511 protected String handleGetTransactionType()
512 {
513 return EJB3MetafacadeUtils.getTransactionType(this, null);
514 }
515
516
517
518
519
520
521 protected Collection handleGetCreateMethods(boolean follow)
522 {
523 return EJB3MetafacadeUtils.getCreateMethods(this, follow);
524 }
525
526
527
528
529
530
531 protected Collection handleGetEnvironmentEntries(boolean follow)
532 {
533 return EJB3MetafacadeUtils.getEnvironmentEntries(this, follow);
534 }
535
536
537
538
539
540
541 protected Collection handleGetConstants(boolean follow)
542 {
543 return EJB3MetafacadeUtils.getConstants(this, follow);
544 }
545
546
547
548
549 @Override
550 protected String handleGetTestPackageName()
551 {
552 String namespacePattern = String.valueOf(this.getConfiguredProperty(SERVICE_TEST_PACKAGE_NAME_PATTERN));
553 return MessageFormat.format(
554 namespacePattern,
555 this.getPackageName());
556 }
557
558
559
560
561 @Override
562 protected String handleGetServiceName()
563 {
564 String serviceNamePattern = (String)this.getConfiguredProperty(SERVICE_NAME_PATTERN);
565
566 return MessageFormat.format(
567 serviceNamePattern,
568 StringUtils.trimToEmpty(this.getName()));
569 }
570
571
572
573
574 @Override
575 protected String handleGetServiceInterfaceName()
576 {
577 String serviceInterfaceNamePattern =
578 (String)this.getConfiguredProperty(SERVICE_INTERFACE_NAME_PATTERN);
579
580 return MessageFormat.format(
581 serviceInterfaceNamePattern,
582 StringUtils.trimToEmpty(this.getName()));
583 }
584
585
586
587
588 @Override
589 protected String handleGetServiceLocalInterfaceName()
590 {
591 String serviceLocalInterfaceNamePattern =
592 (String)this.getConfiguredProperty(SERVICE_LOCAL_INTERFACE_NAME_PATTERN);
593
594 return MessageFormat.format(
595 serviceLocalInterfaceNamePattern,
596 StringUtils.trimToEmpty(this.getName()));
597 }
598
599
600
601
602 @Override
603 protected String handleGetServiceRemoteInterfaceName()
604 {
605 String serviceRemoteInterfaceNamePattern =
606 (String)this.getConfiguredProperty(SERVICE_REMOTE_INTERFACE_NAME_PATTERN);
607
608 return MessageFormat.format(
609 serviceRemoteInterfaceNamePattern,
610 StringUtils.trimToEmpty(this.getName()));
611 }
612
613
614
615
616 @Override
617 protected String handleGetServiceImplementationName()
618 {
619 String serviceImplementationNamePattern =
620 (String)this.getConfiguredProperty(SERVICE_IMPLEMENTATION_NAME_PATTERN);
621
622 return MessageFormat.format(
623 serviceImplementationNamePattern,
624 StringUtils.trimToEmpty(this.getName()));
625 }
626
627
628
629
630 @Override
631 protected String handleGetServiceListenerName()
632 {
633 String serviceListenerNamePattern =
634 (String)this.getConfiguredProperty(SERVICE_LISTENER_NAME_PATTERN);
635
636 return MessageFormat.format(
637 serviceListenerNamePattern,
638 StringUtils.trimToEmpty(this.getName()));
639 }
640
641
642
643
644
645 @Override
646 protected String handleGetServiceDelegateName()
647 {
648 String serviceDelegateNamePattern =
649 (String)this.getConfiguredProperty(SERVICE_DELEGATE_NAME_PATTERN);
650
651 return MessageFormat.format(
652 serviceDelegateNamePattern,
653 StringUtils.trimToEmpty(this.getName()));
654 }
655
656
657
658
659 @Override
660 protected String handleGetServiceBaseName()
661 {
662 String serviceBaseNamePattern =
663 (String)this.getConfiguredProperty(SERVICE_BASE_NAME_PATTERN);
664
665 return MessageFormat.format(
666 serviceBaseNamePattern,
667 StringUtils.trimToEmpty(this.getName()));
668 }
669
670
671
672
673 @Override
674 protected String handleGetServiceTestName()
675 {
676 String serviceTestNamePattern =
677 (String)this.getConfiguredProperty(SERVICE_TEST_NAME_PATTERN);
678
679 return MessageFormat.format(
680 serviceTestNamePattern,
681 StringUtils.trimToEmpty(this.getName()));
682 }
683
684
685
686
687 @Override
688 protected String handleGetFullyQualifiedServiceName()
689 {
690 return EJB3MetafacadeUtils.getFullyQualifiedName(
691 this.getPackageName(),
692 this.getServiceName(),
693 null);
694 }
695
696
697
698
699 @Override
700 protected String handleGetFullyQualifiedServiceImplementationName()
701 {
702 return EJB3MetafacadeUtils.getFullyQualifiedName(
703 this.getPackageName(),
704 this.getServiceImplementationName(),
705 null);
706 }
707
708
709
710
711 @Override
712 protected String handleGetFullyQualifiedServiceListenerName()
713 {
714 return EJB3MetafacadeUtils.getFullyQualifiedName(
715 this.getPackageName(),
716 this.getServiceListenerName(),
717 null);
718 }
719
720
721
722
723 @Override
724 protected String handleGetFullyQualifiedServiceInterfaceName()
725 {
726 return EJB3MetafacadeUtils.getFullyQualifiedName(
727 this.getPackageName(),
728 this.getServiceInterfaceName(),
729 null);
730 }
731
732
733
734
735 @Override
736 protected String handleGetFullyQualifiedServiceLocalInterfaceName()
737 {
738 return EJB3MetafacadeUtils.getFullyQualifiedName(
739 this.getPackageName(),
740 this.getServiceLocalInterfaceName(),
741 null);
742 }
743
744
745
746
747 @Override
748 protected String handleGetFullyQualifiedServiceRemoteInterfaceName()
749 {
750 return EJB3MetafacadeUtils.getFullyQualifiedName(
751 this.getPackageName(),
752 this.getServiceRemoteInterfaceName(),
753 null);
754 }
755
756
757
758
759
760 @Override
761 protected String handleGetFullyQualifiedServiceDelegateName()
762 {
763 return EJB3MetafacadeUtils.getFullyQualifiedName(
764 this.getPackageName(),
765 this.getServiceDelegateName(),
766 null);
767 }
768
769
770
771
772 @Override
773 protected String handleGetFullyQualifiedServiceBaseName()
774 {
775 return EJB3MetafacadeUtils.getFullyQualifiedName(
776 this.getPackageName(),
777 this.getServiceBaseName(),
778 null);
779 }
780
781
782
783
784 @Override
785 protected String handleGetFullyQualifiedServiceTestName()
786 {
787 return EJB3MetafacadeUtils.getFullyQualifiedName(
788 this.getTestPackageName(),
789 this.getServiceTestName(),
790 null);
791 }
792
793
794
795
796 @Override
797 protected String handleGetPersistenceContextUnitName()
798 {
799 String unitName = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_PERSISTENCE_CONTEXT_UNIT_NAME);
800 if (StringUtils.isBlank(unitName))
801 {
802 unitName = StringUtils.trimToEmpty(
803 ObjectUtils.toString(this.getConfiguredProperty(PERSISTENCE_CONTEXT_UNIT_NAME)));
804 }
805 return unitName;
806 }
807
808
809
810
811 @Override
812 protected String handleGetPersistenceContextType()
813 {
814 return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_PERSISTENCE_CONTEXT_TYPE);
815 }
816
817
818
819
820 protected Collection handleGetPersistenceContextReferences()
821 {
822 Collection<DependencyFacade> references = this.getSourceDependencies();
823 CollectionUtils.filter(
824 references,
825 new Predicate()
826 {
827 public boolean evaluate(Object object)
828 {
829 ModelElementFacade targetElement = ((DependencyFacade)object).getTargetElement();
830 return (targetElement != null
831 && targetElement.hasStereotype(EJB3Profile.STEREOTYPE_PERSISTENCE_CONTEXT));
832 }
833 });
834 CollectionUtils.transform(
835 references,
836 new Transformer()
837 {
838 public Object transform(final Object object)
839 {
840 return ((DependencyFacade)object).getTargetElement();
841 }
842 });
843 return references;
844 }
845
846
847
848
849
850
851 public Collection<DependencyFacade> getServiceReferences()
852 {
853 Collection<DependencyFacade> references = super.getServiceReferences();
854 CollectionUtils.filter(
855 references,
856 new Predicate()
857 {
858 public boolean evaluate(Object object)
859 {
860 ModelElementFacade targetElement = ((DependencyFacade)object).getTargetElement();
861 return targetElement.hasStereotype(EJB3Profile.STEREOTYPE_SERVICE);
862 }
863 });
864 return references;
865 }
866
867
868
869
870 @Override
871 protected String handleGetAttributesAsList(
872 Collection attributes,
873 boolean includeTypes,
874 boolean includeNames)
875 {
876 if (!includeNames && !includeTypes || attributes == null)
877 {
878 return "";
879 }
880
881 StringBuilder sb = new StringBuilder();
882 String separator = "";
883
884 for (final Iterator it = attributes.iterator(); it.hasNext();)
885 {
886 EJB3SessionAttributeFacade attr = (EJB3SessionAttributeFacade)it.next();
887 sb.append(separator);
888 separator = ", ";
889 if (includeTypes)
890 {
891 sb.append(attr.getGetterSetterTypeName());
892 sb.append(" ");
893 }
894 if (includeNames)
895 {
896 sb.append(attr.getName());
897 }
898 }
899 return sb.toString();
900 }
901
902
903
904
905 @Override
906 protected String handleGetPersistenceContainer()
907 {
908 return StringUtils.trimToEmpty(
909 ObjectUtils.toString(this.getConfiguredProperty(DEPLOYMENT_PLATFORM)));
910 }
911
912
913
914
915 @Override
916 protected boolean handleIsPersistenceContainerJboss()
917 {
918 return getPersistenceContainer().equalsIgnoreCase(EJB3Globals.PERSISTENCE_CONTAINER_JBOSS);
919 }
920
921
922
923
924 @Override
925 protected boolean handleIsPersistenceContainerWeblogic()
926 {
927 return getPersistenceContainer().equalsIgnoreCase(EJB3Globals.PERSISTENCE_CONTAINER_WEBLOGIC);
928 }
929
930
931
932
933 @Override
934 protected String handleGetRolesAllowed()
935 {
936 StringBuilder rolesAllowed = null;
937 String separator = "";
938
939 for (final Iterator iter = this.getNonRunAsRoles().iterator(); iter.hasNext(); )
940 {
941 if (rolesAllowed == null)
942 {
943 rolesAllowed = new StringBuilder();
944 }
945 rolesAllowed.append(separator);
946 Role role = (Role)iter.next();
947 rolesAllowed.append('"');
948 rolesAllowed.append(role.getName());
949 rolesAllowed.append('"');
950 separator = ", ";
951 }
952 return rolesAllowed != null ? rolesAllowed.toString() : null;
953 }
954
955
956
957
958 @Override
959 protected boolean handleIsPermitAll()
960 {
961 boolean permitAll = false;
962 String permitAllStr = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SECURITY_PERMIT_ALL);
963 if (StringUtils.isNotBlank(permitAllStr))
964 {
965 permitAll = BooleanUtils.toBoolean(permitAllStr);
966 }
967 return permitAll;
968 }
969
970
971
972
973 @Override
974 protected boolean handleIsDenyAll()
975 {
976 boolean denyAll = false;
977 String denyAllStr = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SECURITY_DENY_ALL);
978 if (StringUtils.isNotBlank(denyAllStr))
979 {
980 denyAll = BooleanUtils.toBoolean(denyAllStr);
981 }
982 return denyAll;
983 }
984
985
986
987
988 @Override
989 protected String handleGetSecurityRealm()
990 {
991 String securityRealm = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_SECURITY_REALM);
992 if (StringUtils.isBlank(securityRealm))
993 {
994 securityRealm = StringUtils.trimToEmpty(
995 ObjectUtils.toString(this.getConfiguredProperty(EJB3Globals.SECURITY_REALM)));
996 }
997 return securityRealm;
998 }
999
1000
1001
1002
1003 @Override
1004 protected boolean handleIsSecurityEnabled()
1005 {
1006 return StringUtils.isNotBlank(this.getSecurityRealm());
1007 }
1008
1009
1010
1011
1012 @Override
1013 protected String handleGetRunAs()
1014 {
1015 String runAsRole = null;
1016 DependencyFacade dependency = (DependencyFacade)CollectionUtils.find(
1017 this.getTargetDependencies(),
1018 new Predicate()
1019 {
1020 public boolean evaluate(final Object object)
1021 {
1022 DependencyFacade dependency = (DependencyFacade)object;
1023 return dependency != null
1024 && dependency.getSourceElement() != null
1025 && dependency.getSourceElement() instanceof Role
1026 && dependency.hasStereotype(EJB3Profile.STEREOTYPE_SECURITY_RUNAS);
1027 }
1028 });
1029 if (dependency != null)
1030 {
1031 Role role = (Role)dependency.getSourceElement();
1032 runAsRole = role.getName();
1033 }
1034 return runAsRole;
1035 }
1036
1037
1038
1039
1040 @Override
1041 protected String handleGetTransactionManagement()
1042 {
1043 return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_TRANSACTION_MANAGEMENT);
1044 }
1045
1046
1047
1048
1049 @Override
1050 protected boolean handleIsTransactionManagementBean()
1051 {
1052 return StringUtils.equalsIgnoreCase(getTransactionManagement(), EJB3Globals.TRANSACTION_MANAGEMENT_BEAN);
1053 }
1054
1055
1056
1057
1058 protected Collection handleGetResourceUserTransactionReferences()
1059 {
1060 Collection references = this.getSourceDependencies();
1061 CollectionUtils.filter(
1062 references,
1063 new Predicate()
1064 {
1065 public boolean evaluate(Object object)
1066 {
1067 DependencyFacade dependency = (DependencyFacade)object;
1068 ModelElementFacade targetElement = dependency.getTargetElement();
1069 return (targetElement != null
1070 && EJB3SessionFacade.class.isAssignableFrom(targetElement.getClass())
1071 && dependency.hasStereotype(EJB3Profile.STEREOTYPE_RESOURCE_REF)
1072 && targetElement.hasStereotype(EJB3Profile.STEREOTYPE_USER_TRANSACTION));
1073 }
1074 });
1075 return references;
1076 }
1077
1078
1079
1080
1081 protected Collection<DependencyFacade> handleGetResourceDataSourceReferences()
1082 {
1083 Collection<DependencyFacade> references = this.getSourceDependencies();
1084 CollectionUtils.filter(
1085 references,
1086 new Predicate()
1087 {
1088 public boolean evaluate(Object object)
1089 {
1090 DependencyFacade dependency = (DependencyFacade)object;
1091 ModelElementFacade targetElement = dependency.getTargetElement();
1092 return (targetElement != null
1093 && EJB3SessionFacade.class.isAssignableFrom(targetElement.getClass())
1094 && dependency.hasStereotype(EJB3Profile.STEREOTYPE_RESOURCE_REF)
1095 && targetElement.hasStereotype(EJB3Profile.STEREOTYPE_DATA_SOURCE));
1096 }
1097 });
1098 return references;
1099 }
1100
1101
1102
1103
1104 protected Collection handleGetMessageDrivenReferences()
1105 {
1106 Collection references = this.getSourceDependencies();
1107 CollectionUtils.filter(references, new Predicate()
1108 {
1109 public boolean evaluate(Object object)
1110 {
1111 DependencyFacade dependency = (DependencyFacade)object;
1112 ModelElementFacade targetElement = dependency.getTargetElement();
1113 return (targetElement != null
1114 && targetElement.hasStereotype(EJB3Profile.STEREOTYPE_MESSAGE_DRIVEN));
1115 }
1116 });
1117 return references;
1118 }
1119
1120
1121
1122
1123 protected Collection<DependencyFacade> handleGetInterceptorReferences()
1124 {
1125 Collection<DependencyFacade> references = this.getSourceDependencies();
1126 CollectionUtils.filter(
1127 references,
1128 new Predicate()
1129 {
1130 public boolean evaluate(Object object)
1131 {
1132 DependencyFacade dependency = (DependencyFacade)object;
1133 ModelElementFacade targetElement = dependency.getTargetElement();
1134 return (targetElement != null &&
1135 targetElement.hasStereotype(EJB3Profile.STEREOTYPE_INTERCEPTOR));
1136 }
1137 });
1138 CollectionUtils.transform(
1139 references,
1140 new Transformer()
1141 {
1142 public Object transform(final Object object)
1143 {
1144 return ((DependencyFacade)object).getTargetElement();
1145 }
1146 });
1147 final Collection<DependencyFacade> interceptors = new LinkedHashSet<DependencyFacade>(references);
1148 CollectionUtils.forAllDo(
1149 references,
1150 new Closure()
1151 {
1152 public void execute(Object object)
1153 {
1154 if (object instanceof EJB3InterceptorFacade)
1155 {
1156 interceptors.addAll(((EJB3InterceptorFacade)object).getInterceptorReferences());
1157 }
1158 }
1159 });
1160 return interceptors;
1161 }
1162
1163
1164
1165
1166 protected Collection handleGetNonRunAsRoles()
1167 {
1168 Collection roles = this.getTargetDependencies();
1169 CollectionUtils.filter(
1170 roles,
1171 new Predicate()
1172 {
1173 public boolean evaluate(final Object object)
1174 {
1175 DependencyFacade dependency = (DependencyFacade)object;
1176 return dependency != null
1177 && dependency.getSourceElement() != null
1178 && dependency.getSourceElement() instanceof Role
1179 && !dependency.hasStereotype(EJB3Profile.STEREOTYPE_SECURITY_RUNAS);
1180 }
1181 });
1182 CollectionUtils.transform(
1183 roles,
1184 new Transformer()
1185 {
1186 public Object transform(final Object object)
1187 {
1188 return ((DependencyFacade)object).getSourceElement();
1189 }
1190 });
1191 final Collection allRoles = new LinkedHashSet(roles);
1192
1193 CollectionUtils.forAllDo(
1194 roles,
1195 new Closure()
1196 {
1197 public void execute(final Object object)
1198 {
1199 allRoles.addAll(((Role)object).getAllSpecializations());
1200 }
1201 });
1202 return allRoles;
1203 }
1204
1205
1206
1207
1208 @Override
1209 protected String handleGetDefaultExceptionName()
1210 {
1211 String defaultExceptionNamePattern =
1212 (String)this.getConfiguredProperty(SERVICE_DEFAULT_EXCEPTION_NAME_PATTERN);
1213
1214 return MessageFormat.format(
1215 defaultExceptionNamePattern,
1216 StringUtils.trimToEmpty(this.getName()));
1217 }
1218
1219
1220
1221
1222 @Override
1223 protected String handleGetFullyQualifiedDefaultExceptionName()
1224 {
1225 StringBuilder fullyQualifiedName = new StringBuilder("RuntimeException");
1226 if (this.isAllowDefaultServiceException())
1227 {
1228 fullyQualifiedName = new StringBuilder();
1229 if (StringUtils.isNotBlank(this.getPackageName()))
1230 {
1231 fullyQualifiedName.append(this.getPackageName());
1232 fullyQualifiedName.append('.');
1233 }
1234 fullyQualifiedName.append(this.getDefaultExceptionName());
1235 }
1236 return fullyQualifiedName.toString();
1237 }
1238
1239
1240
1241
1242 @Override
1243 protected boolean handleIsAllowDefaultServiceException()
1244 {
1245 return Boolean.valueOf(
1246 String.valueOf(this.getConfiguredProperty(ALLOW_DEFAULT_SERVICE_EXCEPTION))).booleanValue();
1247 }
1248
1249
1250
1251
1252 @Override
1253 protected boolean handleIsListenerEnabled()
1254 {
1255 return this.hasStereotype(EJB3Profile.STEREOTYPE_LISTENER);
1256 }
1257
1258
1259
1260
1261 @Override
1262 protected boolean handleIsExcludeDefaultInterceptors()
1263 {
1264 boolean excludeDefault = false;
1265 String excludeDefaultStr =
1266 (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_SERVICE_INTERCEPTOR_EXCLUDE_DEFAULT);
1267 if (excludeDefaultStr != null)
1268 {
1269 excludeDefault = BooleanUtils.toBoolean(excludeDefaultStr);
1270 }
1271 return excludeDefault;
1272 }
1273
1274
1275
1276
1277 @Override
1278 protected boolean handleIsClusteringEnabled()
1279 {
1280 return BooleanUtils.toBoolean(String.valueOf(this.getConfiguredProperty(SERVICE_ENABLE_CLUSTERING)));
1281 }
1282
1283
1284
1285
1286 @Override
1287 protected boolean handleIsWebServiceEnabled()
1288 {
1289 return (this.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE) || this.isWebServiceOperationExists()) &&
1290 BooleanUtils.toBoolean(String.valueOf(this.getConfiguredProperty(PROPERTY_WEBSERVICE_ENABLED)));
1291 }
1292
1293
1294
1295
1296 @Override
1297 protected boolean handleIsWebServiceOperationExists()
1298 {
1299 return CollectionUtils.find(
1300 this.getOperations(),
1301 new Predicate()
1302 {
1303 public boolean evaluate(final Object object)
1304 {
1305 boolean isWebService = false;
1306 final OperationFacade operation = (OperationFacade)object;
1307 if (operation.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE_OPERATION))
1308 {
1309 isWebService = true;
1310 }
1311 return isWebService;
1312 }
1313 }) != null;
1314 }
1315
1316
1317
1318
1319 @Override
1320 protected boolean handleIsSeamComponent()
1321 {
1322 return EJB3MetafacadeUtils.isSeamComponent(this);
1323 }
1324
1325
1326
1327
1328 @Override
1329 protected String handleGetSeamComponentScopeType()
1330 {
1331 return EJB3MetafacadeUtils.getSeamComponentScopeType(this, this.isStateless());
1332 }
1333
1334
1335
1336
1337 @Override
1338 protected String handleGetSeamComponentName()
1339 {
1340 return EJB3MetafacadeUtils.getSeamComponentName(this);
1341 }
1342
1343
1344
1345
1346 @Override
1347 protected String handleGetSeamComponentConversionalIfNotBegunOutcome()
1348 {
1349 return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_CONVERSIONAL_IFNOTBEGUNOUTCOME);
1350 }
1351
1352
1353
1354
1355 @Override
1356 protected String handleGetSeamComponentIntercept()
1357 {
1358 return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_INTERCEPT);
1359 }
1360
1361
1362
1363
1364 @Override
1365 protected String handleGetSeamComponentJndiName()
1366 {
1367 return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_JNDI_NAME);
1368 }
1369
1370
1371
1372
1373 protected Collection handleGetSeamComponentRoleNames()
1374 {
1375 return this.findTaggedValues(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_ROLE_NAME);
1376 }
1377
1378
1379
1380
1381 protected Collection handleGetSeamComponentRoleScopeTypes()
1382 {
1383 return this.findTaggedValues(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_ROLE_SCOPE_TYPE);
1384 }
1385
1386
1387
1388
1389 @Override
1390 protected String handleGetSeamComponentStartupParameters()
1391 {
1392 Collection depends = this.findTaggedValues(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_STARTUP_DEPENDS);
1393 if(depends.isEmpty())
1394 {
1395 return null;
1396 }
1397 else
1398 {
1399 StringBuilder buf = new StringBuilder();
1400 buf.append("(depends = {");
1401 Iterator it = depends.iterator();
1402 while(it.hasNext())
1403 {
1404 String dependency = (String) it.next();
1405 buf.append("\"");
1406 buf.append(dependency);
1407 buf.append("\"");
1408 if(it.hasNext())
1409 {
1410 buf.append(", ");
1411 }
1412 }
1413 buf.append("})");
1414 return buf.toString();
1415 }
1416 }
1417
1418
1419
1420
1421 @Override
1422 protected String handleGetSeamComponentSynchronizedTimeout()
1423 {
1424 return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_SYNCHRONIZED_TIMEOUT);
1425 }
1426
1427
1428
1429
1430 @Override
1431 protected boolean handleIsSeamComponentReadonly()
1432 {
1433 return BooleanUtils.toBoolean((String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_SEAM_COMPONENT_READONLY));
1434 }
1435
1436
1437
1438
1439 @Override
1440 protected boolean handleIsSeamComponentStartup()
1441 {
1442 return this.hasStereotype(EJB3Profile.STEREOTYPE_SEAM_COMPONENT_STARTUP);
1443 }
1444
1445
1446
1447
1448 @Override
1449 protected boolean handleIsSeamComponentTransactional()
1450 {
1451 return this.hasStereotype(EJB3Profile.STEREOTYPE_SEAM_TRANSACTION_TRANSACTIONAL);
1452 }
1453 }