1 16 package org.outerj.daisy.repository.commonimpl; 17 18 import org.outerj.daisy.repository.DocumentCollection; 19 import org.outerj.daisy.repository.DocumentCollections; 20 import org.outerj.daisy.repository.RepositoryException; 21 import org.outerj.daisy.repository.RepositoryListener; 22 23 28 public class CommonCollectionManager { 29 private CollectionStrategy collectionStrategy; 30 private CollectionCache cache; 31 32 36 public CommonCollectionManager(CollectionStrategy collectionStrategy, CollectionCache cache) { 37 this.collectionStrategy = collectionStrategy; 38 this.cache = cache; 39 } 40 41 public RepositoryListener getCacheListener() { 42 return cache; 43 } 44 45 public CollectionCache getCache() { 46 return cache; 47 } 48 49 public DocumentCollection createCollection(String name, AuthenticatedUser user) throws RepositoryException { 50 if (!user.isInAdministratorRole()) 51 throw new RepositoryException("The current user is not allowed to create collections."); 52 return new DocumentCollectionImpl(collectionStrategy, name, user); 53 } 54 55 public DocumentCollectionImpl getCollection(long collectionId, boolean updateable, AuthenticatedUser user) throws RepositoryException { 56 if (updateable) 57 return collectionStrategy.loadCollection(collectionId, user); 58 else 59 return cache.getCollection(collectionId); 60 } 61 62 public DocumentCollectionImpl getCollectionByName(String name, boolean updateable, AuthenticatedUser user) throws RepositoryException { 63 if (updateable) 64 return collectionStrategy.loadCollectionByName(name, user); 65 else 66 return cache.getCollectionByName(name); 67 } 68 69 public DocumentCollections getCollections(boolean updateable, AuthenticatedUser user) throws RepositoryException { 70 if (updateable) 71 return new DocumentCollectionsImpl((DocumentCollection[])collectionStrategy.loadCollections(user).toArray(new DocumentCollection[0])); 72 else 73 return cache.getCollections(); 74 } 75 76 public void deleteCollection(long collectionId, AuthenticatedUser user) throws RepositoryException{ 77 collectionStrategy.deleteCollection(collectionId, user); 78 } 79 80 } 81 | Popular Tags |