KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > GuestRepositoryProviderImpl


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.frontend;
17
18 import org.outerj.daisy.repository.Repository;
19 import org.outerj.daisy.repository.RepositoryManager;
20 import org.outerj.daisy.repository.Credentials;
21 import org.outerj.daisy.repository.clientimpl.RemoteRepositoryImpl;
22 import org.apache.avalon.framework.service.Serviceable;
23 import org.apache.avalon.framework.service.ServiceManager;
24 import org.apache.avalon.framework.service.ServiceException;
25 import org.apache.avalon.framework.activity.Initializable;
26 import org.apache.avalon.framework.thread.ThreadSafe;
27
28 /**
29  * This component serves as a quick factory for guest repository objects.
30  * The Guest Repository object is requested only once from the RepositoryManager,
31  * after which it is cloned each time needed.
32  */

33 public class GuestRepositoryProviderImpl implements GuestRepositoryProvider, Serviceable, Initializable, ThreadSafe {
34     private ServiceManager serviceManager;
35     private Repository templateRepository;
36
37     public void service(ServiceManager serviceManager) throws ServiceException {
38         this.serviceManager = serviceManager;
39     }
40
41     public void initialize() throws Exception JavaDoc {
42         RepositoryManager repositoryManager = (RepositoryManager)serviceManager.lookup("daisy-repository-manager");
43         try {
44             templateRepository = repositoryManager.getRepository(new Credentials("guest", "guest"));
45         } finally {
46             serviceManager.release(repositoryManager);
47         }
48     }
49
50     public Repository getGuestRepository() {
51         return (Repository)((RemoteRepositoryImpl)templateRepository).clone();
52     }
53 }
54
Popular Tags