1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.apache.log4j.Logger; 31 import org.exolab.castor.jdo.Database; 32 import org.infoglue.cms.entities.kernel.BaseEntityVO; 33 import org.infoglue.cms.entities.management.InterceptionPoint; 34 import org.infoglue.cms.entities.management.Interceptor; 35 import org.infoglue.cms.entities.management.InterceptorVO; 36 import org.infoglue.cms.entities.management.impl.simple.InterceptorImpl; 37 import org.infoglue.cms.exception.Bug; 38 import org.infoglue.cms.exception.ConstraintException; 39 import org.infoglue.cms.exception.SystemException; 40 import org.infoglue.cms.util.ConstraintExceptionBuffer; 41 42 47 48 public class InterceptorController extends BaseController 49 { 50 private final static Logger logger = Logger.getLogger(InterceptorController.class.getName()); 51 52 55 56 public static InterceptorController getController() 57 { 58 return new InterceptorController(); 59 } 60 61 public Interceptor getInterceptorWithId(Integer interceptorId, Database db) throws SystemException, Bug 62 { 63 return (Interceptor) getObjectWithId(InterceptorImpl.class, interceptorId, db); 64 } 65 66 public InterceptorVO getInterceptorVOWithId(Integer interceptorId) throws SystemException, Bug 67 { 68 return (InterceptorVO) getVOWithId(InterceptorImpl.class, interceptorId); 69 } 70 71 public List getInterceptorVOList() throws SystemException, Bug 72 { 73 return getAllVOObjects(InterceptorImpl.class, "interceptorId"); 74 } 75 76 public List getInterceptionPointVOList(Integer interceptorId) throws SystemException, Bug 77 { 78 List interceptionPointVOList = null; 79 80 Database db = CastorDatabaseService.getDatabase(); 81 82 try 83 { 84 beginTransaction(db); 85 86 interceptionPointVOList = getInterceptionPointVOList(interceptorId, db); 87 88 commitTransaction(db); 89 } 90 catch (Exception e) 91 { 92 logger.info("An error occurred so we should not complete the transaction:" + e); 93 rollbackTransaction(db); 94 throw new SystemException(e.getMessage()); 95 } 96 97 return interceptionPointVOList; 98 } 99 100 public List getInterceptionPointVOList(Integer interceptorId, Database db) throws SystemException, Bug 101 { 102 Interceptor interceptor = this.getInterceptorWithId(interceptorId, db); 103 104 Collection interceptionPoints = interceptor.getInterceptionPoints(); 105 106 return toVOList(interceptionPoints); 107 } 108 109 117 118 public InterceptorVO create(InterceptorVO interceptorVO) throws ConstraintException, SystemException 119 { 120 InterceptorVO newinterceptorVO = null; 121 122 Database db = CastorDatabaseService.getDatabase(); 123 124 try 125 { 126 beginTransaction(db); 127 128 newinterceptorVO = create(interceptorVO, db); 129 130 commitTransaction(db); 131 } 132 catch (Exception e) 133 { 134 logger.info("An error occurred so we should not complete the transaction:" + e); 135 rollbackTransaction(db); 136 throw new SystemException(e.getMessage()); 137 } 138 139 return newinterceptorVO; 140 } 141 142 150 151 public InterceptorVO create(InterceptorVO interceptorVO, Database db) throws SystemException, Exception 152 { 153 Interceptor interceptor = new InterceptorImpl(); 154 interceptor.setValueObject(interceptorVO); 155 156 db.create(interceptor); 157 158 return interceptor.getValueObject(); 159 } 160 161 162 public InterceptorVO update(InterceptorVO interceptorVO) throws ConstraintException, SystemException 163 { 164 return (InterceptorVO) updateEntity(InterceptorImpl.class, (BaseEntityVO)interceptorVO); 165 } 166 167 public void update(InterceptorVO interceptorVO, String [] values) throws ConstraintException, SystemException 168 { 169 Database db = CastorDatabaseService.getDatabase(); 170 171 try 172 { 173 beginTransaction(db); 174 175 ConstraintExceptionBuffer ceb = interceptorVO.validate(); 176 ceb.throwIfNotEmpty(); 177 178 logger.info("InterceptorId:" + interceptorVO.getInterceptorId()); 179 Interceptor interceptor = this.getInterceptorWithId(interceptorVO.getInterceptorId(), db); 180 181 interceptor.setValueObject(interceptorVO); 182 183 Collection interceptionPoints = interceptor.getInterceptionPoints(); 184 Iterator interceptionPointsIterator = interceptionPoints.iterator(); 185 while(interceptionPointsIterator.hasNext()) 186 { 187 InterceptionPoint interceptionPoint = (InterceptionPoint)interceptionPointsIterator.next(); 188 interceptionPoint.getInterceptors().remove(interceptor); 189 } 190 191 interceptor.getInterceptionPoints().clear(); 192 193 if(values != null) 194 { 195 for(int i=0; i<values.length; i++) 196 { 197 String interceptionPointId = values[i]; 198 InterceptionPoint interceptionPoint = InterceptionPointController.getController().getInterceptionPointWithId(new Integer (interceptionPointId), db); 199 interceptor.getInterceptionPoints().add(interceptionPoint); 200 interceptionPoint.getInterceptors().add(interceptor); 201 } 202 } 203 204 commitTransaction(db); 205 } 206 catch (Exception e) 207 { 208 e.printStackTrace(); 209 logger.info("An error occurred so we should not complete the transaction:" + e); 210 rollbackTransaction(db); 211 throw new SystemException(e.getMessage()); 212 } 213 } 214 215 public void delete(InterceptorVO interceptorVO) throws ConstraintException, SystemException 216 { 217 deleteEntity(InterceptorImpl.class, interceptorVO.getInterceptorId()); 218 } 219 220 233 234 238 239 public BaseEntityVO getNewVO() 240 { 241 return new InterceptorVO(); 242 } 243 244 } 245 | Popular Tags |