KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > jsf > NavigationTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.jsf;
6
7 import java.util.*;
8
9 import xjavadoc.*;
10
11 import xdoclet.*;
12
13 /**
14  * @author <a HREF="mailto:markus.plattner at plattners.de">Markus Plattner</a>
15  * @created 28. Juni 2004
16  * @xdoclet.taghandler namespace="FacesNavigation"
17  */

18 public class NavigationTagsHandler extends XDocletTagSupport
19 {
20
21     private JsfNavigationRule currentRule = null;
22     private String JavaDoc fromViewId = null;
23     private HashMap rules = new HashMap();
24
25     /**
26      * @param template
27      * @exception XDocletException
28      * @doc.tag type="block"
29      */

30     public void forAllRules(String JavaDoc template) throws XDocletException
31     {
32         Collection viewRules = (Collection) rules.get(fromViewId);
33
34         for (Iterator itr = viewRules.iterator(); itr.hasNext(); ) {
35             currentRule = (JsfNavigationRule) itr.next();
36             generate(template);
37         }
38     }
39
40     /**
41      * @return
42      * @doc.tag type="content"
43      */

44     public String JavaDoc fromView()
45     {
46         return this.fromViewId;
47     }
48
49     /**
50      * @return
51      * @doc.tag type="content"
52      */

53     public String JavaDoc toView()
54     {
55         return this.currentRule.getToView();
56     }
57
58     /**
59      * @return
60      * @doc.tag type="content"
61      */

62     public String JavaDoc outcome()
63     {
64         return this.currentRule.getOutcome();
65     }
66
67
68     /**
69      * @param template
70      * @exception XDocletException
71      * @doc.tag type="block"
72      */

73     public void forAllViews(String JavaDoc template) throws XDocletException
74     {
75         Collection classes = getXJavaDoc().getSourceClasses();
76
77         for (Iterator i = classes.iterator(); i.hasNext(); ) {
78             XClass clazz = (XClass) i.next();
79
80             setCurrentClass(clazz);
81             if (DocletSupport.isDocletGenerated(getCurrentClass())) {
82                 continue;
83             }
84             if (hasRule(getCurrentClass())) {
85                 for (Iterator it = getCurrentClass().getDoc().getTags("jsf.navigation").iterator(); it.hasNext(); ) {
86                     XTag tag = (XTag) it.next();
87                     String JavaDoc fromView = tag.getAttributeValue("from");
88                     String JavaDoc toView = tag.getAttributeValue("to");
89                     String JavaDoc result = tag.getAttributeValue("result");
90                     JsfNavigationRule rule = new JsfNavigationRule(fromView, result, toView);
91                     Collection r = (Collection) rules.get(fromView);
92
93                     if (r == null) {
94                         r = new ArrayList();
95                     }
96                     r.add(rule);
97                     rules.put(fromView, r);
98                 }
99             }
100         }
101         for (Iterator it = rules.keySet().iterator(); it.hasNext(); ) {
102             fromViewId = it.next().toString();
103             generate(template);
104         }
105     }
106
107     private boolean hasRule(XClass clazz)
108     {
109         return clazz.getDoc().hasTag("jsf.navigation", false);
110     }
111
112     /**
113      * @created 28. Juni 2004
114      */

115     private class JsfNavigationRule
116     {
117
118         private String JavaDoc fromView = null;
119         private String JavaDoc outcome = null;
120         private String JavaDoc toView = null;
121
122         public JsfNavigationRule(String JavaDoc fromView, String JavaDoc outcome, String JavaDoc toView)
123         {
124             this.fromView = fromView;
125             this.outcome = outcome;
126             this.toView = toView;
127         }
128
129         public String JavaDoc getFromView()
130         {
131             return fromView;
132         }
133
134         public String JavaDoc getOutcome()
135         {
136             return outcome;
137         }
138
139         public String JavaDoc getToView()
140         {
141             return toView;
142         }
143
144     }
145 }
146
Popular Tags