KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > bizlogic > ModuleBL


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.bizlogic;
24
25 import java.sql.SQLException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import com.geinuke.common.UserI;
30 import com.geinuke.dao.ModuleDAO;
31 import com.geinuke.middle.IModuleBL;
32 import com.geinuke.middle.IUserBL;
33 import com.geinuke.middle.MiddleFactory;
34 import com.geinuke.util.NukeResource;
35 import com.geinuke.vo.ModuleDBVO;
36 import com.geinuke.vo.RoleVO;
37
38
39 public class ModuleBL implements IModuleBL {
40
41     protected static IModuleBL instance=null;
42     
43     public ModuleBL(){
44         
45     }
46     
47
48     
49     public ModuleDBVO getDefModule()throws BLException {
50         ModuleDBVO mod=null;
51         try{
52             ModuleDAO dao=new ModuleDAO();
53             mod=dao.getDefModule();
54         }catch(SQLException JavaDoc sqle){
55             throw new DBException(sqle.getMessage());
56         }catch(Throwable JavaDoc t){
57             throw new BLException(t.getMessage());
58         }
59         return mod;
60     }
61
62     private ModuleDBVO getStaticModule(){
63         ModuleDBVO mod=null;
64         mod=new ModuleDBVO();
65         mod.setActive(true);
66         String JavaDoc cont="<table width=100% bgcolor=\"#FFFFFF\"><tr><td> "+
67                 "<br/>Questa e+ una prova" +
68                 "</td></tr></table>";
69         mod.setContent(cont);
70         mod.setDbStored(true);
71         mod.setHomePosition(-10);
72         mod.setId(356);
73         mod.setInMenu(false);
74         mod.setName("Prova");
75         mod.setPos(0);
76         mod.setRoleLevel(10);
77         mod.setSkin(0);
78         mod.setTitle("La prova");
79         mod.setWeight(1);
80         return mod;
81     }
82     
83     public ModuleDBVO getModule(String JavaDoc modd)throws BLException {
84         //if(modd.equals("Prova"))
85
// return this.getStaticModule();
86
ModuleDBVO mod=null;
87         try{
88             ModuleDAO dao=new ModuleDAO();
89             mod=dao.getModuleByName(modd);
90         }catch(SQLException JavaDoc sqle){
91             sqle.printStackTrace(System.out);
92             throw new DBException(sqle.getMessage());
93         }catch(Throwable JavaDoc t){
94             throw new BLException(t.getMessage());
95         }
96         return mod;
97     }
98     
99     public ModuleDBVO getModuleByID(int id)throws BLException {
100         ModuleDBVO mod=null;
101         try{
102             ModuleDAO dao=new ModuleDAO();
103             mod=dao.getModuleById(id);
104         }catch(SQLException JavaDoc sqle){
105             sqle.printStackTrace(System.out);
106             throw new DBException(sqle.getMessage());
107         }catch(Throwable JavaDoc t){
108             throw new BLException(t.getMessage());
109         }
110         return mod;
111     }
112     
113     public void updateSingleModule(int id,String JavaDoc action)throws BLException {
114         ModuleDBVO mod=null;
115         ArrayList JavaDoc roles=null;
116         IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL");
117         roles=ubl.getAllRoles();
118         RoleVO role=null;
119         mod=this.getModuleByID(id);
120         if(action.equalsIgnoreCase("skin")){
121             int skin=mod.getSkin();
122             mod.setSkin( (skin+1)%4 );
123         }else if(action.equalsIgnoreCase("width")){
124             int width=mod.getWidth();
125             mod.setWidth( (width+1)%3 );
126         }else if(action.equalsIgnoreCase("inmenu")){
127             mod.setInMenu(! mod.isInMenu() );
128         }else if(action.equalsIgnoreCase("active")){
129             mod.setActive(! mod.isActive() );
130         }else if(action.equalsIgnoreCase("inHome")){
131             int hp=mod.getHomePosition();
132             hp=hp+1;
133             if(hp==4)
134                 hp=-1;
135             mod.setHomePosition(hp );
136         }else if(action.equalsIgnoreCase("rolel")){
137             int level=mod.getRoleLevel();
138             int pos=NukeResource.getRolePositionByRoleLevel(level,roles);
139             if(pos>=0){
140                 pos=(pos+1)%roles.size();
141                 role=(RoleVO)roles.get(pos);
142                 mod.setRoleLevel(role.getLevela());
143             }
144         }
145         this.updateDBModule(mod);
146     }
147
148
149     
150     /**
151      *
152      * @return all modules to put in "Modules" block using ModuleLinkInfo objects
153      * @throws BLException
154      */

155     public ArrayList JavaDoc getAllModulesInMainBlock(UserI user) throws BLException {
156         ArrayList JavaDoc ll=null;
157         try{
158             ModuleDAO dao=new ModuleDAO();
159             List JavaDoc list=dao.getAllModuleInMainBlock(user);
160             
161             ll=new ArrayList JavaDoc(list);
162         }catch(SQLException JavaDoc sqle){
163             sqle.printStackTrace(System.out);
164             throw new DBException(sqle.getMessage());
165         }catch(Throwable JavaDoc t){
166             throw new BLException(t.getMessage());
167         }
168         
169         return ll;
170     }
171     
172     public ArrayList JavaDoc getModulesInHomePage(UserI user) throws BLException {
173         ArrayList JavaDoc ll=null;
174         try{
175             ModuleDAO dao=new ModuleDAO();
176             List JavaDoc list=dao.getModulesInHomePage(user);
177             
178             ll=new ArrayList JavaDoc(list);
179         }catch(SQLException JavaDoc sqle){
180             sqle.printStackTrace(System.out);
181             throw new DBException(sqle.getMessage());
182         }catch(Throwable JavaDoc t){
183             throw new BLException(t.getMessage());
184         }
185         
186         return ll;
187     }
188     
189     public void updateDBModule(ModuleDBVO mod)throws BLException{
190         try{
191             ModuleDAO dao=new ModuleDAO();
192             dao.updateDBModule(mod);
193         }catch(SQLException JavaDoc sqle){
194             throw new DBException(sqle.getMessage());
195         }catch(Throwable JavaDoc t){
196             throw new BLException(t.getMessage());
197         }
198     }
199     
200     public void insertDBStoredModule(ModuleDBVO mod)throws BLException{
201         try{
202             ModuleDAO dao=new ModuleDAO();
203             dao.insertDBStoredModule(mod);
204         }catch(SQLException JavaDoc sqle){
205             throw new DBException(sqle.getMessage());
206         }catch(Throwable JavaDoc t){
207             throw new BLException(t.getMessage());
208         }
209     }
210     
211     public ArrayList JavaDoc getAllDBModules() throws BLException {
212         ArrayList JavaDoc ll=null;
213         try{
214             ModuleDAO dao=new ModuleDAO();
215             List JavaDoc list=dao.getAllDBModules();
216             
217             ll=new ArrayList JavaDoc(list);
218         }catch(SQLException JavaDoc sqle){
219             throw new DBException(sqle.getMessage());
220         }catch(Throwable JavaDoc t){
221             throw new BLException(t.getMessage());
222         }
223         
224         return ll;
225     }
226     
227     public ArrayList JavaDoc getAllDBStoredModules() throws BLException {
228         ArrayList JavaDoc ll=null;
229         try{
230             ModuleDAO dao=new ModuleDAO();
231             List JavaDoc list=dao.getAllDBStoredModules();
232             
233             ll=new ArrayList JavaDoc(list);
234         }catch(SQLException JavaDoc sqle){
235             throw new DBException(sqle.getMessage());
236         }catch(Throwable JavaDoc t){
237             throw new BLException(t.getMessage());
238         }
239         
240         return ll;
241     }
242
243
244
245     
246     public void delDBModule(int id) throws BLException {
247         
248         try{
249             ModuleDAO dao=new ModuleDAO();
250             dao.delDBModule(id);
251         }catch(SQLException JavaDoc sqle){
252             throw new DBException(sqle.getMessage());
253         }catch(Throwable JavaDoc t){
254             throw new BLException(t.getMessage());
255         }
256         
257         
258     }
259     
260     
261
262 }
263
Popular Tags