KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > commonimpl > CommonCollectionManager


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
24  * This class contains the same methods as the specific
25  * CollectionManager implementations, but has extra
26  * User arguments.
27  */

28 public class CommonCollectionManager {
29     private CollectionStrategy collectionStrategy;
30     private CollectionCache cache;
31
32     /**
33      * create a CommonCollectionManager with a
34      * specified collectionStrategy.
35      */

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 JavaDoc 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 JavaDoc 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