KickJava   Java API By Example, From Geeks To Geeks.

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


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.CollectionManager;
19 import org.outerj.daisy.repository.DocumentCollection;
20 import org.outerj.daisy.repository.DocumentCollections;
21 import org.outerj.daisy.repository.RepositoryException;
22
23
24 public class CollectionManagerImpl implements CollectionManager {
25     private CommonCollectionManager delegate;
26     private AuthenticatedUser user;
27
28     public CollectionManagerImpl(CommonCollectionManager delegate, AuthenticatedUser user) {
29         this.delegate = delegate;
30         this.user = user;
31     }
32
33     public DocumentCollection createCollection(String JavaDoc name)
34         throws RepositoryException {
35         return delegate.createCollection(name, user);
36     }
37
38     public DocumentCollection getCollection(long collectionId, boolean updateable) throws RepositoryException {
39         return delegate.getCollection(collectionId, updateable, user);
40     }
41
42     public DocumentCollection getCollection(String JavaDoc collection, boolean updateable) throws RepositoryException {
43         if (collection == null)
44             throw new IllegalArgumentException JavaDoc("collection param can not be null");
45         if (collection.length() == 0)
46             throw new IllegalArgumentException JavaDoc("collection param cannot be an empty string");
47
48         if (Character.isDigit(collection.charAt(0))) {
49             long id;
50             try {
51                 id = Long.parseLong(collection);
52             } catch (NumberFormatException JavaDoc e) {
53                 throw new RepositoryException("Invalid collection specification: " + collection);
54             }
55             return getCollection(id, updateable);
56         } else {
57             return getCollectionByName(collection, updateable);
58         }
59     }
60
61     public DocumentCollection getCollectionByName(String JavaDoc name, boolean updateable) throws RepositoryException {
62         return delegate.getCollectionByName(name, updateable, user);
63     }
64
65     public DocumentCollections getCollections(boolean updateable) throws RepositoryException {
66         return delegate.getCollections(updateable, user);
67     }
68     
69     public void deleteCollection(long collectionId) throws RepositoryException {
70         delegate.deleteCollection(collectionId, user);
71     }
72
73 }
74
Popular Tags