]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0159fc0e8dc9ed763627b2a064bd9c2a5589a4b1
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.common.repository;
25
26 import java.lang.ClassLoader;
27 import java.util.Hashtable;
28 import org.collectionspace.services.common.RepositoryClientConfigType;
29 import org.collectionspace.services.common.ServiceMain;
30 import org.collectionspace.services.common.config.ServicesConfigReader;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * RepositoryClientFactory is a singleton factory that creates required repository
36  * clients. Repository clients are singletons.
37  *
38  * $LastChangedRevision: $
39  * $LastChangedDate: $
40  */
41 public class RepositoryClientFactory {
42
43     private static final RepositoryClientFactory self = new RepositoryClientFactory();
44     final Logger logger = LoggerFactory.getLogger(RepositoryClientFactory.class);
45     //clients key=client name, value=repository client
46     private Hashtable<String, RepositoryClient> clients = new Hashtable<String, RepositoryClient>();
47
48     private RepositoryClientFactory() {
49         try{
50             ServicesConfigReader scReader = ServiceMain.getInstance().getServicesConfigReader();
51             RepositoryClientConfigType repositoryClientConfig = scReader.getConfiguration().getRepositoryClient();
52             String clientClassName = repositoryClientConfig.getClientClass();
53             String clientName = repositoryClientConfig.getName();
54             ClassLoader cloader = Thread.currentThread().getContextClassLoader();
55
56             Class jclazz = cloader.loadClass(clientClassName);
57             Object jclient = jclazz.newInstance();
58             clients.put(clientName, (RepositoryClient) jclient);
59
60         }catch(Exception e){
61             throw new RuntimeException(e);
62         }
63     }
64
65     public static RepositoryClientFactory getInstance() {
66         return self;
67     }
68
69     /**
70      * get repository client
71      * @param clientName name of the client as found in service binding
72      * @return
73      */
74     public RepositoryClient getClient(String clientName) {
75         return clients.get(clientName);
76     }
77 }