1 package org.andromda.cartridges.jsf.metafacades;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6 import org.andromda.cartridges.jsf.JSFGlobals;
7 import org.andromda.cartridges.jsf.JSFUtils;
8 import org.andromda.metafacades.uml.DependencyFacade;
9 import org.andromda.metafacades.uml.FrontEndAction;
10 import org.andromda.metafacades.uml.ModelElementFacade;
11 import org.andromda.utils.StringUtilsHelper;
12 import org.apache.commons.lang.ObjectUtils;
13 import org.apache.commons.lang.StringUtils;
14
15
16
17
18
19
20 public class JSFControllerLogicImpl
21 extends JSFControllerLogic
22 {
23 private static final long serialVersionUID = 34L;
24
25
26
27
28 public JSFControllerLogicImpl(Object metaObject, String context)
29 {
30 super(metaObject, context);
31 }
32
33
34
35
36
37 protected String handleGetImplementationName()
38 {
39 final String pattern = ObjectUtils.toString(
40 this.getConfiguredProperty(JSFGlobals.CONTROLLER_IMPLEMENTATION_PATTERN));
41 return pattern.replaceFirst("\\{0\\}", StringUtils.capitalize(this.getName()));
42 }
43
44
45
46
47
48 protected String handleGetFullyQualifiedImplementationName()
49 {
50 final StringBuilder fullyQualifiedName = new StringBuilder();
51 final String packageName = this.getPackageName();
52 if (StringUtils.isNotBlank(packageName))
53 {
54 fullyQualifiedName.append(packageName + '.');
55 }
56 return fullyQualifiedName.append(this.getImplementationName()).toString();
57 }
58
59
60
61
62
63 protected String handleGetFullyQualifiedImplementationPath()
64 {
65 return this.getFullyQualifiedImplementationName().replace('.', '/');
66 }
67
68
69
70
71
72 protected String handleGetBeanName()
73 {
74 return StringUtilsHelper.lowerCamelCaseName(this.getName());
75 }
76
77
78
79
80
81 protected List<DependencyFacade> handleGetSessionObjectReferences()
82 {
83 final List<DependencyFacade> references = new ArrayList<DependencyFacade>(this.getSourceDependencies());
84 for (final Iterator<DependencyFacade> iterator = references.iterator(); iterator.hasNext();)
85 {
86 final ModelElementFacade targetElement = (iterator.next()).getTargetElement();
87 if (!(targetElement instanceof JSFSessionObject))
88 {
89 iterator.remove();
90 }
91 }
92 return references;
93 }
94
95
96
97
98
99 protected String handleGetControllerSerialVersionUID()
100 {
101 final StringBuilder buffer = new StringBuilder();
102 buffer.append(this.getFullyQualifiedImplementationName());
103 addSerialUIDData(buffer);
104 return JSFUtils.calcSerialVersionUID(buffer);
105 }
106
107 private void addSerialUIDData(StringBuilder buffer)
108 {
109 for (final FrontEndAction action : this.getUseCase().getActions())
110 {
111 buffer.append(action.getName());
112 }
113 }
114 }