KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > admin > Menu


1 /*
2  * Menu.java
3  *
4  * Created on 14. August 2003, 23:40
5  */

6 package org.contineo.admin;
7
8 import java.util.ArrayList JavaDoc;
9 import java.util.Collection JavaDoc;
10 import org.contineo.admin.dao.MenuDAO;
11
12 /**
13  * This class represents menus.
14  * @author Michael Scholz
15  * @version 1.0
16  */

17 public class Menu {
18     /** menu is a directory */
19     public static final int MENUTYPE_DIRECTORY = 3;
20
21     /** menu is a file */
22     public static final int MENUTYPE_FILE = 5;
23     
24     /**
25      * @uml.property name="menuId"
26      */

27     protected int menuId;
28     /**
29      * @uml.property name="menuText"
30      */

31     protected String JavaDoc menuText;
32     /**
33      * @uml.property name="menuParent"
34      */

35     protected int menuParent;
36     /**
37      * @uml.property name="menuSort"
38      */

39     protected int menuSort;
40     /**
41      * @uml.property name="menuIcon"
42      */

43     protected String JavaDoc menuIcon;
44     /**
45      * @uml.property name="menuPath"
46      */

47     protected String JavaDoc menuPath;
48     /**
49      * @uml.property name="menuType"
50      */

51     protected int menuType;
52     /**
53      * @uml.property name="menuHier"
54      */

55     protected int menuHier;
56     /**
57      * @uml.property name="menuRef"
58      */

59     protected String JavaDoc menuRef;
60
61     /**
62      * @uml.property name="menuGroup"
63      * @uml.associationEnd
64      */

65     protected Collection JavaDoc<MenuGroup> menuGroup;
66
67     
68     /** Creates a new instance of Menu */
69     public Menu() {
70         menuId = 0;
71         menuText = "";
72         menuParent = 0;
73         menuSort = 0;
74         menuIcon = "";
75         menuPath = "";
76         menuType = 2;
77         menuHier = 0;
78         menuRef = "";
79         menuGroup = new ArrayList JavaDoc<MenuGroup>();
80     }
81
82     /**
83      *
84      * @uml.property name="menuId"
85      */

86     public int getMenuId() {
87         return menuId;
88     }
89
90     /**
91      *
92      * @uml.property name="menuText"
93      */

94     public String JavaDoc getMenuText() {
95         return menuText;
96     }
97
98     /**
99      *
100      * @uml.property name="menuParent"
101      */

102     public int getMenuParent() {
103         return menuParent;
104     }
105
106     /**
107      *
108      * @uml.property name="menuSort"
109      */

110     public int getMenuSort() {
111         return menuSort;
112     }
113
114     /**
115      *
116      * @uml.property name="menuIcon"
117      */

118     public String JavaDoc getMenuIcon() {
119         return menuIcon;
120     }
121
122     /**
123      *
124      * @uml.property name="menuPath"
125      */

126     public String JavaDoc getMenuPath() {
127         return menuPath;
128     }
129
130     /**
131      *
132      * @uml.property name="menuType"
133      */

134     public int getMenuType() {
135         return menuType;
136     }
137
138     /**
139      *
140      * @uml.property name="menuHier"
141      */

142     public int getMenuHier() {
143         return menuHier;
144     }
145
146     /**
147      *
148      * @uml.property name="menuRef"
149      */

150     public String JavaDoc getMenuRef() {
151         return menuRef;
152     }
153
154     /**
155      *
156      * @uml.property name="menuGroup"
157      */

158     public Collection JavaDoc<MenuGroup> getMenuGroup() {
159         return menuGroup;
160     }
161
162     /**
163      *
164      * @uml.property name="menuId"
165      */

166     protected void setMenuId(int id) {
167         menuId = id;
168     }
169
170     /**
171      *
172      * @uml.property name="menuText"
173      */

174     public void setMenuText(String JavaDoc text) {
175         menuText = text;
176     }
177
178     /**
179      *
180      * @uml.property name="menuParent"
181      */

182     public void setMenuParent(int parent) {
183         menuParent = parent;
184     }
185
186     /**
187      *
188      * @uml.property name="menuSort"
189      */

190     public void setMenuSort(int sort) {
191         menuSort = sort;
192     }
193
194     /**
195      *
196      * @uml.property name="menuIcon"
197      */

198     public void setMenuIcon(String JavaDoc icon) {
199         menuIcon = icon;
200     }
201
202     /**
203      *
204      * @uml.property name="menuPath"
205      */

206     public void setMenuPath(String JavaDoc path) {
207         menuPath = path;
208     }
209
210     /**
211      *
212      * @uml.property name="menuType"
213      */

214     public void setMenuType(int type) {
215         menuType = type;
216     }
217
218     /**
219      *
220      * @uml.property name="menuHier"
221      */

222     public void setMenuHier(int hier) {
223         menuHier = hier;
224     }
225
226     /**
227      *
228      * @uml.property name="menuRef"
229      */

230     public void setMenuRef(String JavaDoc ref) {
231         menuRef = ref;
232     }
233
234     /**
235      *
236      * @uml.property name="menuGroup"
237      */

238     public void setMenuGroup(Collection JavaDoc<MenuGroup> mgroup) {
239         menuGroup = mgroup;
240     }
241
242     /**
243      * Adds MenuGroup object given in a String array to the ArrayList of MenuGroups.
244      * @param groups
245      */

246     public void setMenuGroup(String JavaDoc[] groups) {
247         for (int i=0; i<groups.length; i++) {
248             MenuGroup mg = new MenuGroup();
249             mg.setMenuId(menuId);
250             mg.setGroupName(groups[i]);
251             mg.setWriteEnable(1);
252             menuGroup.add(mg);
253         }
254     }
255     
256     /**
257      * This method makes a deep copy of a menu object.
258      * @return Copy of this menu.
259      */

260     public Menu copy() {
261         Menu menu = new Menu();
262         menu.setMenuId(this.getMenuId());
263         menu.setMenuText(this.getMenuText());
264         menu.setMenuParent(this.getMenuParent());
265         menu.setMenuSort(this.getMenuSort());
266         menu.setMenuIcon(this.getMenuIcon());
267         menu.setMenuPath(this.getMenuPath());
268         menu.setMenuType(this.getMenuType());
269         menu.setMenuHier(this.getMenuHier());
270         menu.setMenuRef(this.getMenuRef());
271         menu.setMenuGroup(this.getMenuGroup());
272         return menu;
273     }
274     
275     /**
276      * Returns a Collection of menus being a parent of the given menu.
277      * The collection is sorted by the hierarchy level (menuHier) of the menus.
278      * @return
279      */

280     public Collection JavaDoc getParents() {
281         Collection JavaDoc<Menu> coll = new ArrayList JavaDoc<Menu>();
282         try {
283             String JavaDoc menus[] = menuPath.split("/");
284             if (menus.length > 0) {
285                 if (menus[0].length() > 0) {
286                     MenuDAO menuDao = new MenuDAO();
287                     Menu home = menuDao.findByPrimaryKey(1);
288                     coll.add(home);
289                     for (int i=1; i<menus.length; i++) {
290                         try {
291                             Menu menu = menuDao.findByPrimaryKey(Integer.parseInt(menus[i]));
292                             coll.add(menu);
293                         } catch (NumberFormatException JavaDoc nfe) {
294                             
295                         }
296                     }
297                 }
298             }
299         } catch (Exception JavaDoc e) {
300             
301         }
302         return coll;
303     }
304 }
305
Popular Tags