KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > SiteNodeTypeDefinitionController


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.controllers.kernel.impl.simple;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.log4j.Logger;
31 import org.exolab.castor.jdo.Database;
32 import org.exolab.castor.jdo.OQLQuery;
33 import org.exolab.castor.jdo.QueryResults;
34 import org.infoglue.cms.entities.kernel.BaseEntityVO;
35 import org.infoglue.cms.entities.management.AvailableServiceBinding;
36 import org.infoglue.cms.entities.management.SiteNodeTypeDefinition;
37 import org.infoglue.cms.entities.management.SiteNodeTypeDefinitionVO;
38 import org.infoglue.cms.entities.management.impl.simple.SiteNodeTypeDefinitionImpl;
39 import org.infoglue.cms.exception.Bug;
40 import org.infoglue.cms.exception.ConstraintException;
41 import org.infoglue.cms.exception.SystemException;
42 import org.infoglue.cms.util.ConstraintExceptionBuffer;
43
44
45 public class SiteNodeTypeDefinitionController extends BaseController
46 {
47     private final static Logger logger = Logger.getLogger(SiteNodeTypeDefinitionController.class.getName());
48
49     /**
50      * Factory method
51      */

52
53     public static SiteNodeTypeDefinitionController getController()
54     {
55         return new SiteNodeTypeDefinitionController();
56     }
57     
58     public SiteNodeTypeDefinitionVO getSiteNodeTypeDefinitionVOWithId(Integer JavaDoc siteNodeTypeDefinitionId) throws SystemException, Bug
59     {
60         return (SiteNodeTypeDefinitionVO) getVOWithId(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId);
61     }
62
63     public SiteNodeTypeDefinitionVO getSiteNodeTypeDefinitionVOWithId(Integer JavaDoc siteNodeTypeDefinitionId, Database db) throws SystemException, Bug
64     {
65         return (SiteNodeTypeDefinitionVO) getVOWithId(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId, db);
66     }
67
68     public SiteNodeTypeDefinitionVO create(SiteNodeTypeDefinitionVO vo) throws ConstraintException, SystemException
69     {
70         SiteNodeTypeDefinition ent = new SiteNodeTypeDefinitionImpl();
71         ent.setValueObject(vo);
72         ent = (SiteNodeTypeDefinition) createEntity(ent);
73         return ent.getValueObject();
74     }
75
76     public void delete(SiteNodeTypeDefinitionVO vo) throws ConstraintException, SystemException
77     {
78         deleteEntity(SiteNodeTypeDefinitionImpl.class, vo.getSiteNodeTypeDefinitionId());
79     }
80
81     public SiteNodeTypeDefinition getSiteNodeTypeDefinitionWithId(Integer JavaDoc siteNodeTypeDefinitionId, Database db) throws SystemException, Bug
82     {
83         return (SiteNodeTypeDefinition) getObjectWithId(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId, db);
84     }
85
86     public SiteNodeTypeDefinition getSiteNodeTypeDefinitionWithIdAsReadOnly(Integer JavaDoc siteNodeTypeDefinitionId, Database db) throws SystemException, Bug
87     {
88         return (SiteNodeTypeDefinition) getObjectWithIdAsReadOnly(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId, db);
89     }
90
91     public List JavaDoc getSiteNodeTypeDefinitionVOList() throws SystemException, Bug
92     {
93         return getAllVOObjects(SiteNodeTypeDefinitionImpl.class, "siteNodeTypeDefinitionId");
94     }
95
96     
97     /**
98      * This method gets a SiteNodeTypeDefinition based on it's name.
99      * @param name
100      * @param db
101      * @return
102      * @throws SystemException
103      * @throws Bug
104      */

105
106     public SiteNodeTypeDefinition getSiteNodeTypeDefinitionWithName(String JavaDoc name, Database db, boolean readOnly) throws SystemException, Bug
107     {
108         SiteNodeTypeDefinition siteNodeTypeDefinition = null;
109         
110         try
111         {
112             OQLQuery oql = db.getOQLQuery("SELECT s FROM org.infoglue.cms.entities.management.impl.simple.SiteNodeTypeDefinitionImpl s WHERE s.name = $1");
113             oql.bind(name);
114             
115             QueryResults results = null;
116             if(readOnly)
117                 results = oql.execute(Database.ReadOnly);
118             else
119             {
120                 this.logger.info("Fetching entity in read/write mode" + name);
121                 results = oql.execute();
122             }
123             
124             if (results.hasMore())
125             {
126                 siteNodeTypeDefinition = (SiteNodeTypeDefinition)results.next();
127             }
128             
129             results.close();
130             oql.close();
131         }
132         catch(Exception JavaDoc e)
133         {
134             throw new SystemException("An error occurred when we tried to fetch a SiteNodeTypeDefinition based on name. Reason:" + e.getMessage(), e);
135         }
136     
137         return siteNodeTypeDefinition;
138     }
139
140     /**
141      * This method deletes the SiteNodeTypeDefinition sent in from the system.
142      */

143     
144     public void deleteSiteNodeTypeDefinition(Integer JavaDoc siteNodeTypeDefinitionId, Database db) throws SystemException, Bug
145     {
146         try
147         {
148             db.remove(getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionId, db));
149         }
150         catch(Exception JavaDoc e)
151         {
152             throw new SystemException("An error occurred when we tried to delete SiteNodeTypeDefinition in the database. Reason: " + e.getMessage(), e);
153         }
154     }
155
156     public SiteNodeTypeDefinitionVO update(SiteNodeTypeDefinitionVO siteNodeTypeDefinitionVO) throws ConstraintException, SystemException
157     {
158         Database db = CastorDatabaseService.getDatabase();
159         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
160
161         SiteNodeTypeDefinition siteNodeTypeDefinition = null;
162
163         beginTransaction(db);
164
165         try
166         {
167             //add validation here if needed
168
siteNodeTypeDefinition = getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionVO.getSiteNodeTypeDefinitionId(), db);
169             siteNodeTypeDefinition.setValueObject(siteNodeTypeDefinitionVO);
170
171             //If any of the validations or setMethods reported an error, we throw them up now before create.
172
ceb.throwIfNotEmpty();
173             
174             commitTransaction(db);
175         }
176         catch(ConstraintException ce)
177         {
178             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
179             rollbackTransaction(db);
180             throw ce;
181         }
182         catch(Exception JavaDoc e)
183         {
184             logger.error("An error occurred so we should not complete the transaction:" + e, e);
185             rollbackTransaction(db);
186             throw new SystemException(e.getMessage());
187         }
188
189         return siteNodeTypeDefinition.getValueObject();
190     }
191     
192     public SiteNodeTypeDefinitionVO update(SiteNodeTypeDefinitionVO siteNodeTypeDefinitionVO, String JavaDoc[] availableServiceBindingValues) throws ConstraintException, SystemException
193     {
194         Database db = CastorDatabaseService.getDatabase();
195         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
196
197         SiteNodeTypeDefinition siteNodeTypeDefinition = null;
198
199         beginTransaction(db);
200
201         try
202         {
203             //add validation here if needed
204
List JavaDoc availableServiceBindingList = new ArrayList JavaDoc();
205             if(availableServiceBindingValues != null)
206             {
207                 for (int i=0; i < availableServiceBindingValues.length; i++)
208                 {
209                     AvailableServiceBinding availableServiceBinding = AvailableServiceBindingController.getController().getAvailableServiceBindingWithId(new Integer JavaDoc(availableServiceBindingValues[i]), db);
210                     availableServiceBindingList.add(availableServiceBinding);
211                 }
212             }
213             
214             siteNodeTypeDefinition = SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionVO.getSiteNodeTypeDefinitionId(), db);
215             siteNodeTypeDefinition.setValueObject(siteNodeTypeDefinitionVO);
216             logger.info("availableServiceBindingList:" + availableServiceBindingList);
217             siteNodeTypeDefinition.setAvailableServiceBindings(availableServiceBindingList);
218             
219             //If any of the validations or setMethods reported an error, we throw them up now before create.
220
ceb.throwIfNotEmpty();
221             
222             commitTransaction(db);
223         }
224         catch(ConstraintException ce)
225         {
226             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
227             rollbackTransaction(db);
228             throw ce;
229         }
230         catch(Exception JavaDoc e)
231         {
232             logger.error("An error occurred so we should not complete the transaction:" + e, e);
233             rollbackTransaction(db);
234             throw new SystemException(e.getMessage());
235         }
236
237         return siteNodeTypeDefinition.getValueObject();
238     }
239
240     /**
241      * This method returns a list with AvailableServiceBidningVO-objects which are available for the
242      * siteNodeTypeDefinition sent in
243      */

244     
245     public List JavaDoc getAvailableServiceBindingVOList(Integer JavaDoc siteNodeTypeDefinitionId) throws ConstraintException, SystemException
246     {
247         Database db = CastorDatabaseService.getDatabase();
248         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
249
250         List JavaDoc availableServiceBindingVOList = null;
251
252         beginTransaction(db);
253
254         try
255         {
256             /*
257             OQLQuery oql = db.getOQLQuery( "SELECT asb FROM org.infoglue.cms.entities.management.impl.simple.AvailableServiceBindingImpl asb WHERE asb.siteNodeTypeDefinition.siteNodeTypeDefinitionId = $1");
258             oql.bind(siteNodeTypeDefinitionId);
259             
260             QueryResults results = oql.execute(Database.ReadOnly);
261             
262             while (results.hasMore())
263             {
264                 AvailableServiceBinding availableServiceBinding = (AvailableServiceBinding)results.next();
265                 availableServiceBindingVOList.add(availableServiceBinding.getValueObject());
266             }
267             */

268
269             SiteNodeTypeDefinition siteNodeTypeDefinition = getSiteNodeTypeDefinitionWithIdAsReadOnly(siteNodeTypeDefinitionId, db);
270             Collection JavaDoc availableServiceBindingList = siteNodeTypeDefinition.getAvailableServiceBindings();
271             availableServiceBindingVOList = toVOList(availableServiceBindingList);
272
273             
274             //If any of the validations or setMethods reported an error, we throw them up now before create.
275
ceb.throwIfNotEmpty();
276             
277             commitTransaction(db);
278         }
279         catch(ConstraintException ce)
280         {
281             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
282             rollbackTransaction(db);
283             throw ce;
284         }
285         catch(Exception JavaDoc e)
286         {
287             logger.error("An error occurred so we should not complete the transaction:" + e, e);
288             rollbackTransaction(db);
289             throw new SystemException(e.getMessage());
290         }
291
292         return availableServiceBindingVOList;
293     }
294
295     
296     /**
297      * This method returns a list with AvailableServiceBidningVO-objects which are available for the
298      * siteNodeTypeDefinition sent in
299      */

300     
301     public List JavaDoc getAvailableServiceBindingVOList(Integer JavaDoc siteNodeTypeDefinitionId, Database db) throws ConstraintException, SystemException
302     {
303         List JavaDoc availableServiceBindingVOList = null;
304         /*
305         OQLQuery oql = db.getOQLQuery( "SELECT asb FROM org.infoglue.cms.entities.management.impl.simple.AvailableServiceBindingImpl asb WHERE asb.siteNodeTypeDefinition.siteNodeTypeDefinitionId = $1");
306         oql.bind(siteNodeTypeDefinitionId);
307         
308         QueryResults results = oql.execute(Database.ReadOnly);
309         
310         while (results.hasMore())
311         {
312             AvailableServiceBinding availableServiceBinding = (AvailableServiceBinding)results.next();
313             availableServiceBindingVOList.add(availableServiceBinding.getValueObject());
314         }
315         */

316
317         SiteNodeTypeDefinition siteNodeTypeDefinition = getSiteNodeTypeDefinitionWithIdAsReadOnly(siteNodeTypeDefinitionId, db);
318         Collection JavaDoc availableServiceBindingList = siteNodeTypeDefinition.getAvailableServiceBindings();
319         availableServiceBindingVOList = toVOList(availableServiceBindingList);
320
321         return availableServiceBindingVOList;
322     }
323
324     /**
325      * This is a method that gives the user back an newly initialized ValueObject for this entity that the controller
326      * is handling.
327      */

328
329     public BaseEntityVO getNewVO()
330     {
331         return new SiteNodeTypeDefinitionVO();
332     }
333
334 }
335  
336
Popular Tags