KickJava   Java API By Example, From Geeks To Geeks.

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


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

24 package com.geinuke.bizlogic;
25
26 import java.sql.SQLException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 import com.geinuke.common.UserI;
30 import com.geinuke.dao.BlockDAO;
31 import com.geinuke.middle.IBlockBL;
32 import com.geinuke.middle.IBlogBL;
33 import com.geinuke.middle.IUserBL;
34 import com.geinuke.middle.MiddleFactory;
35 import com.geinuke.util.NukeResource;
36 import com.geinuke.vo.BlockDBVO;
37 import com.geinuke.vo.RoleVO;
38
39
40
41 public class BlockBL implements IBlockBL{
42     
43     
44     
45     public BlockBL(){
46         
47     }
48     
49     private void addMockBlock(ArrayList JavaDoc l){
50         BlockDBVO b=new BlockDBVO();
51         b.setActive(true);
52         b.setDbStored(true);
53         b.setId(876);
54         b.setIdRole(1);
55         b.setContent("<b>prova</b>");
56         b.setTitle("La Prova");
57         b.setName("Prova la");
58         b.setPos(1);
59         b.setRoleLevel(10);
60         b.setSkin(0);
61         b.setWeight(1);
62         l.add(b);
63         
64     }
65     
66     public ArrayList JavaDoc getBlocksForUser(UserI user) throws BLException{
67         ArrayList JavaDoc list=null;
68         try{
69             BlockDAO dao=new BlockDAO();
70             list=dao.getBlocksForUser(user);
71             //this.addMockBlock(list);
72
}catch(SQLException JavaDoc sqle){
73             sqle.printStackTrace(System.out);
74             throw new DBException(sqle.getMessage());
75         }catch(Throwable JavaDoc t){
76             throw new BLException(t.getMessage());
77         }
78         return list;
79     }
80     
81     public BlockDBVO getBlock(int id) throws BLException{
82         BlockDBVO mod=null;
83         try{
84             BlockDAO dao=new BlockDAO();
85             mod=dao.getBlockById(id);
86         }catch(SQLException JavaDoc sqle){
87             throw new DBException(sqle.getMessage());
88         }catch(Throwable JavaDoc t){
89             throw new BLException(t.getMessage());
90         }
91         return mod;
92     }
93     
94     public BlockDBVO getBlockByName(String JavaDoc name) throws BLException{
95         BlockDBVO mod=null;
96         try{
97             BlockDAO dao=new BlockDAO();
98             mod=dao.getBlockByName(name);
99         }catch(SQLException JavaDoc sqle){
100             throw new DBException(sqle.getMessage());
101         }catch(Throwable JavaDoc t){
102             throw new BLException(t.getMessage());
103         }
104         return mod;
105     }
106     
107     
108     
109     public void insertDBStoredBlock(BlockDBVO blo)throws BLException{
110         try{
111             BlockDAO dao=new BlockDAO();
112             dao.insertDBStoredBlock(blo);
113         }catch(SQLException JavaDoc sqle){
114             throw new DBException(sqle.getMessage());
115         }catch(Throwable JavaDoc t){
116             throw new BLException(t.getMessage());
117         }
118     }
119     
120     public void updateDBBlock(BlockDBVO blo)throws BLException{
121         try{
122             BlockDAO dao=new BlockDAO();
123             dao.updateDBBlock(blo);
124         }catch(SQLException JavaDoc sqle){
125             throw new DBException(sqle.getMessage());
126         }catch(Throwable JavaDoc t){
127             throw new BLException(t.getMessage());
128         }
129     }
130     
131     public void updateSingleBlock(int id,String JavaDoc action)throws BLException {
132         BlockDBVO blo=null;
133         ArrayList JavaDoc roles=null;
134         RoleVO role=null;
135         
136         blo=this.getBlock(id);
137         IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL");
138         roles=ubl.getAllRoles();
139         
140         if(action.equalsIgnoreCase("active")){
141             blo.setActive(! blo.isActive() );
142         }else if(action.equalsIgnoreCase("pos")){
143             int pos=blo.getPos();
144             pos=(pos+1)%2;
145             blo.setPos(pos);
146         }else if(action.equalsIgnoreCase("Aweight")){
147             int weight=blo.getWeight();
148             weight=(weight+1)%50;
149             blo.setWeight(weight);
150         } else if(action.equalsIgnoreCase("Mweight")){
151             int weight=blo.getWeight();
152             weight--;
153             if(weight<0)
154                 weight=0;
155             blo.setWeight(weight);
156         }else if(action.equalsIgnoreCase("skin")){
157             int skin=blo.getSkin();
158             skin++;
159             if(skin>3)
160                 skin=0;
161             blo.setSkin(skin);
162         } else if(action.equalsIgnoreCase("rolel")){
163             int level=blo.getRoleLevel();
164             int pos=NukeResource.getRolePositionByRoleLevel(level,roles);
165             
166             if(pos>=0){
167                 pos=(pos+1)%roles.size();
168                 role=(RoleVO)roles.get(pos);
169                 blo.setRoleLevel(role.getLevela());
170             }
171         }
172         this.updateDBBlock(blo);
173     }
174     
175     
176     
177     
178     public ArrayList JavaDoc getAllStoredBlocks() throws BLException{
179         ArrayList JavaDoc list=null;
180         try{
181             BlockDAO dao=new BlockDAO();
182             list=dao.getAllStoredBlocks();
183             
184         }catch(SQLException JavaDoc sqle){
185             throw new DBException(sqle.getMessage());
186         }catch(Throwable JavaDoc t){
187             throw new BLException(t.getMessage());
188         }
189         return list;
190     }
191     
192     public ArrayList JavaDoc getAllBlocks() throws BLException{
193         ArrayList JavaDoc list=null;
194         try{
195             BlockDAO dao=new BlockDAO();
196             list=dao.getAllBlocks();
197             
198         }catch(SQLException JavaDoc sqle){
199             throw new DBException(sqle.getMessage());
200         }catch(Throwable JavaDoc t){
201             throw new BLException(t.getMessage());
202         }
203         return list;
204     }
205
206     
207     public void delDBBlock(int id) throws BLException {
208         try{
209             BlockDAO dao=new BlockDAO();
210             dao.delDBBlock(id);
211             
212         }catch(SQLException JavaDoc sqle){
213             throw new DBException(sqle.getMessage());
214         }catch(Throwable JavaDoc t){
215             throw new BLException(t.getMessage());
216         }
217     }
218
219 }
220
Popular Tags