1 package org.andromda.cartridges.hibernate.metafacades;
2
3 import java.util.Collection;
4 import org.andromda.cartridges.hibernate.HibernateProfile;
5 import org.andromda.core.common.ExceptionUtils;
6 import org.andromda.metafacades.uml.ClassifierFacade;
7 import org.andromda.metafacades.uml.FilteredCollection;
8 import org.andromda.metafacades.uml.ModelElementFacade;
9 import org.andromda.metafacades.uml.OperationFacade;
10 import org.apache.commons.collections.CollectionUtils;
11 import org.apache.commons.collections.Predicate;
12 import org.apache.commons.lang.StringUtils;
13
14
15
16
17
18
19 class HibernateMetafacadeUtils
20 {
21
22
23
24
25
26
27
28
29 static String getViewType(
30 ClassifierFacade classifier,
31 String defaultViewType)
32 {
33 ExceptionUtils.checkNull("classifer", classifier);
34 String viewType = null;
35 if (classifier.hasStereotype(HibernateProfile.STEREOTYPE_SERVICE))
36 {
37 String viewTypeValue = (String)classifier.findTaggedValue(HibernateProfile.TAGGEDVALUE_EJB_VIEWTYPE);
38
39
40 if (StringUtils.isEmpty(viewTypeValue))
41 {
42 viewType =
43 (String)CollectionUtils.find(
44 classifier.getAllGeneralizations(),
45 new Predicate()
46 {
47 public boolean evaluate(Object object)
48 {
49 return ((ModelElementFacade)object).findTaggedValue(
50 HibernateProfile.TAGGEDVALUE_EJB_VIEWTYPE) != null;
51 }
52 });
53 }
54 if (StringUtils.isNotBlank(viewTypeValue))
55 {
56 viewType = viewTypeValue;
57 }
58 }
59 if (StringUtils.isEmpty(viewType) || viewType==null)
60 {
61 viewType = defaultViewType;
62 }
63 return viewType.toLowerCase();
64 }
65
66
67
68
69
70
71
72
73
74
75
76 static String getFullyQualifiedName(
77 String packageName,
78 String name,
79 String suffix)
80 {
81 StringBuilder fullyQualifiedName = new StringBuilder(StringUtils.trimToEmpty(packageName));
82 if (StringUtils.isNotBlank(packageName))
83 {
84 fullyQualifiedName.append('.');
85 }
86 fullyQualifiedName.append(StringUtils.trimToEmpty(name));
87 fullyQualifiedName.append(StringUtils.trimToEmpty(suffix));
88 return fullyQualifiedName.toString();
89 }
90
91
92
93
94
95
96 static Collection<OperationFacade> filterBusinessOperations(Collection<OperationFacade> operations)
97 {
98 Collection<OperationFacade> businessOperations =
99 new FilteredCollection(operations)
100 {
101 private static final long serialVersionUID = 34L;
102 public boolean evaluate(Object object)
103 {
104 return !((OperationFacade)object).isStatic();
105 }
106 };
107 return businessOperations;
108 }
109
110
111
112
113
114
115
116
117 static boolean getUseNamedParameters(OperationFacade operation,
118 boolean defaultUseNamedParameters)
119 {
120 ExceptionUtils.checkNull("operation", operation);
121 boolean useNamedParameters = defaultUseNamedParameters;
122 if (operation.isQuery())
123 {
124 String useNamedParametersValue = StringUtils.trimToEmpty((String)operation
125 .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_USE_NAMED_PARAMETERS));
126 if (StringUtils.isNotBlank(useNamedParametersValue))
127 {
128 useNamedParameters = Boolean.valueOf(useNamedParametersValue).booleanValue();
129 }
130 }
131 return useNamedParameters;
132 }
133 }