1 21 22 package org.opensubsystems.blog.logic.impl; 23 24 import java.util.List ; 25 26 import org.opensubsystems.blog.data.Blog; 27 import org.opensubsystems.blog.data.Entry; 28 import org.opensubsystems.blog.logic.BlogController; 29 import org.opensubsystems.blog.persist.BlogFactory; 30 import org.opensubsystems.blog.persist.EntryFactory; 31 import org.opensubsystems.core.data.DataObject; 32 import org.opensubsystems.core.data.ModifiableDataObject; 33 import org.opensubsystems.core.error.OSSException; 34 import org.opensubsystems.core.logic.impl.ModifiableDataControllerImpl; 35 import org.opensubsystems.core.persist.BasicDataFactory; 36 import org.opensubsystems.core.persist.DataFactory; 37 import org.opensubsystems.core.persist.DataFactoryManager; 38 import org.opensubsystems.core.util.CallContext; 39 import org.opensubsystems.core.util.GlobalConstants; 40 41 64 public class BlogControllerImpl extends ModifiableDataControllerImpl 65 implements BlogController 66 { 67 69 72 protected BlogFactory m_blogFactory = null; 73 74 77 protected EntryFactory m_entryFactory = null; 78 79 81 84 private static final long serialVersionUID = -4304971836362014336L; 85 86 88 91 public BlogControllerImpl( 92 ) 93 { 94 super(); 95 96 m_blogFactory = null; 99 m_entryFactory = null; 100 } 101 102 104 110 public Blog get( 111 String strFolder 112 ) throws OSSException 113 { 114 return m_blogFactory.get(strFolder); 115 } 116 117 123 public List getEntries( 124 int iBlogId 125 ) throws OSSException 126 { 127 List lstEntries; 128 129 lstEntries = m_entryFactory.getAll(iBlogId); 130 131 return lstEntries; 132 } 133 134 140 public Object [] getWithEntries( 141 String strFolder 142 ) throws OSSException 143 { 144 Object [] returnValue = {null, null}; 145 Blog blog; 146 List lstEntries; 147 148 blog = m_blogFactory.get(strFolder); 153 if (blog != null) 154 { 155 returnValue[0] = blog; 156 lstEntries = m_entryFactory.getAll(blog.getId()); 157 if (lstEntries != null) 158 { 159 returnValue[1] = lstEntries; 160 } 161 } 162 163 return returnValue; 164 } 165 166 172 public Object [] getWithEntry( 173 String strFolder, 174 int iEntryId 175 ) throws OSSException 176 { 177 Object [] returnValue = {null, null}; 178 Blog blog; 179 Entry entry; 180 181 186 191 entry = (Entry)m_entryFactory.get(iEntryId, 194 CallContext.getInstance().getCurrentDomainId()); 195 if (entry != null) 196 { 197 returnValue[1] = entry; 198 if (entry.getParentId() != DataObject.NEW_ID) 199 { 200 blog = (Blog)m_blogFactory.get(entry.getParentId(), 202 CallContext.getInstance().getCurrentDomainId()); 203 204 if (GlobalConstants.ERROR_CHECKING) 205 { 206 assert blog != null : "Blog cannot be null when entry was found"; 207 } 208 } 209 else 210 { 211 blog = m_blogFactory.get(strFolder); 213 } 214 } 215 else 216 { 217 blog = m_blogFactory.get(strFolder); 219 } 220 if (blog != null) 221 { 222 returnValue[0] = blog; 223 } 224 225 return returnValue; 226 } 227 228 234 public Object [] getWithEntry( 235 int iBlogId, 236 int iEntryId 237 ) throws OSSException 238 { 239 Object [] returnValue = {null, null}; 240 Blog blog; 241 Entry entry; 242 243 248 253 blog = (Blog)m_blogFactory.get(iBlogId, 254 CallContext.getInstance().getCurrentDomainId()); 255 if (blog != null) 256 { 257 returnValue[0] = blog; 258 entry = (Entry)m_entryFactory.get(iEntryId, 259 CallContext.getInstance().getCurrentDomainId()); 260 if (entry != null) 261 { 262 if (iEntryId == DataObject.NEW_ID) 263 { 264 entry.setParentId(iBlogId); 265 } 266 returnValue[1] = entry; 267 } 268 } 269 270 return returnValue; 271 } 272 273 279 public List getAll( 280 ) throws OSSException 281 { 282 return m_blogFactory.getAll(); 283 } 284 285 291 public void deleteEntry( 292 int iBlogEntryId 293 ) throws OSSException 294 { 295 m_entryFactory.delete(iBlogEntryId, 296 CallContext.getInstance().getCurrentDomainId()); 297 } 298 299 305 public void constructor( 306 ) throws OSSException 307 { 308 m_blogFactory = (BlogFactory)DataFactoryManager.getInstance(BlogFactory.class); 309 m_entryFactory = (EntryFactory)DataFactoryManager.getInstance(EntryFactory.class); 310 } 311 312 314 317 protected DataFactory getDataFactory( 318 ) 319 { 320 return m_blogFactory; 322 } 323 324 327 protected BasicDataFactory getDataFactory( 328 DataObject data 329 ) 330 { 331 BasicDataFactory factory = null; 332 333 if (GlobalConstants.ERROR_CHECKING) 334 { 335 assert data != null : "Cannot return factory for null data object"; 336 } 337 338 if (data instanceof Blog) 339 { 340 factory = m_blogFactory; 341 } 342 else if (data instanceof Entry) 343 { 344 factory = m_entryFactory; 345 } 346 else 347 { 348 if (GlobalConstants.ERROR_CHECKING) 349 { 350 assert false : "Cannot return factory for unrecognized data type " 351 + data.getClass().getName(); 352 } 353 } 354 355 return factory; 356 } 357 358 363 369 public ModifiableDataObject save(ModifiableDataObject data) throws OSSException 370 { 371 return super.save(data); 372 } 373 374 380 public DataObject create(DataObject data) throws OSSException 381 { 382 return super.create(data); 383 } 384 385 391 public void delete(int iId) throws OSSException 392 { 393 super.delete(iId); 394 } 395 396 402 public DataObject get(int iId) throws OSSException 403 { 404 return super.get(iId); 405 } 406 } 407 | Popular Tags |