1 package org.andromda.cartridges.jsf.metafacades;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.Iterator;
6 import java.util.LinkedHashMap;
7 import java.util.Map;
8 import org.andromda.cartridges.jsf.JSFGlobals;
9 import org.andromda.cartridges.jsf.JSFProfile;
10 import org.andromda.cartridges.jsf.JSFUtils;
11 import org.andromda.metafacades.uml.StateVertexFacade;
12 import org.andromda.utils.StringUtilsHelper;
13
14
15
16
17
18
19 public class JSFForwardLogicImpl
20 extends JSFForwardLogic
21 {
22 private static final long serialVersionUID = 34L;
23
24
25
26
27 public JSFForwardLogicImpl(Object metaObject, String context)
28 {
29 super(metaObject, context);
30 }
31
32
33
34
35 public String getName()
36 {
37 StringBuilder name = new StringBuilder(super.getName());
38 final Object target = this.getTarget();
39 if (target instanceof JSFFinalState)
40 {
41 name.append(JSFGlobals.USECASE_FORWARD_NAME_SUFFIX);
42 }
43 else
44 {
45 name.insert(0, this.getUseCase().getName() + "-");
46 }
47 return JSFUtils.toWebResourceName(name.toString());
48 }
49
50
51
52
53
54 protected String handleGetPath()
55 {
56 String forwardPath = null;
57 final StateVertexFacade target = getTarget();
58 if (this.isEnteringView())
59 {
60 forwardPath = ((JSFView)target).getPath();
61 }
62 else if (this.isEnteringFinalState())
63 {
64 forwardPath = ((JSFFinalState)target).getPath();
65 }
66
67 return forwardPath;
68 }
69
70
71
72
73 protected boolean handleIsSuccessMessagesPresent()
74 {
75 return !this.getSuccessMessages().isEmpty();
76 }
77
78
79
80
81 protected boolean handleIsWarningMessagesPresent()
82 {
83 return !this.getWarningMessages().isEmpty();
84 }
85
86
87
88
89
90
91
92
93 @SuppressWarnings("unchecked")
94 private Map<String, String> getMessages(String taggedValue)
95 {
96 Map<String, String> messages;
97
98 final Collection taggedValues = this.findTaggedValues(taggedValue);
99 if (taggedValues.isEmpty())
100 {
101 messages = Collections.EMPTY_MAP;
102 }
103 else
104 {
105 messages = new LinkedHashMap<String, String>();
106
107 for (final Iterator iterator = taggedValues.iterator(); iterator.hasNext();)
108 {
109 final String value = (String)iterator.next();
110 messages.put(StringUtilsHelper.toResourceMessageKey(value), value);
111 }
112 }
113
114 return messages;
115 }
116
117
118
119
120 protected Map handleGetSuccessMessages()
121 {
122 return this.getMessages(JSFProfile.TAGGEDVALUE_ACTION_SUCCESS_MESSAGE);
123 }
124
125
126
127
128 protected Map handleGetWarningMessages()
129 {
130 return this.getMessages(JSFProfile.TAGGEDVALUE_ACTION_WARNING_MESSAGE);
131 }
132
133
134
135
136
137 protected boolean handleIsFinalStateTarget()
138 {
139 return this.getTarget() instanceof JSFFinalState;
140 }
141
142
143
144
145
146 protected String handleGetFromOutcome()
147 {
148 return this.getName();
149 }
150 }