1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.application.navigation; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public class NavigationContext { |
26 | |
|
27 | |
protected static final String WILDCARD = "*"; |
28 | |
|
29 | 19 | private String fromViewId_ = WILDCARD; |
30 | |
|
31 | 19 | private boolean isWildCardMatch_ = false; |
32 | |
|
33 | 19 | private List navigationCases_ = new ArrayList(); |
34 | |
|
35 | 19 | public NavigationContext() { |
36 | 19 | } |
37 | |
|
38 | |
public void setFromViewId(String fromViewId) { |
39 | 17 | fromViewId_ = fromViewId; |
40 | 17 | } |
41 | |
|
42 | |
public void addNavigationCaseContext( |
43 | |
NavigationCaseContext navigationCaseContext) { |
44 | 19 | if (navigationCaseContext != null) { |
45 | 18 | navigationCases_.add(navigationCaseContext); |
46 | |
} |
47 | 19 | if (fromViewId_ != null) { |
48 | 19 | isWildCardMatch_ = fromViewId_.endsWith(WILDCARD); |
49 | |
} |
50 | 19 | } |
51 | |
|
52 | |
public String getFromViewId() { |
53 | 24 | return fromViewId_; |
54 | |
} |
55 | |
|
56 | |
public List getNavigationCases() { |
57 | 20 | return navigationCases_; |
58 | |
} |
59 | |
|
60 | |
public NavigationCaseContext getNavigationCase(String fromAction, |
61 | |
String outCome) { |
62 | 15 | for (Iterator itr = getNavigationCases().iterator(); itr.hasNext();) { |
63 | 15 | NavigationCaseContext caseContext = (NavigationCaseContext) itr |
64 | |
.next(); |
65 | 15 | String from = caseContext.getFromAction(); |
66 | 15 | String out = caseContext.getFromOutcome(); |
67 | 15 | if ((from == null || from.equals(fromAction)) |
68 | |
&& (out == null || out.equals(outCome))) { |
69 | 15 | return caseContext; |
70 | |
} |
71 | |
} |
72 | 0 | return null; |
73 | |
} |
74 | |
|
75 | |
public boolean isWildCardMatch() { |
76 | 20 | return isWildCardMatch_; |
77 | |
} |
78 | |
|
79 | |
public String toString() { |
80 | 0 | StringBuffer buf = new StringBuffer(); |
81 | 0 | buf.append("navigation-rule = "); |
82 | 0 | buf.append("["); |
83 | 0 | buf.append("from-view-id = \"" + fromViewId_ + "\""); |
84 | 0 | buf.append(" "); |
85 | 0 | for (Iterator itr = navigationCases_.iterator(); itr.hasNext();) { |
86 | 0 | buf.append(itr.next()); |
87 | |
} |
88 | 0 | buf.append("]"); |
89 | 0 | return buf.toString(); |
90 | |
} |
91 | |
} |