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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.common.repository;
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;
35 * RepositoryClientFactory is a singleton factory that creates required repository
36 * clients. Repository clients are singletons.
38 * $LastChangedRevision: $
41 public class RepositoryClientFactory {
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>();
48 private RepositoryClientFactory() {
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();
56 Class jclazz = cloader.loadClass(clientClassName);
57 Object jclient = jclazz.newInstance();
58 clients.put(clientName, (RepositoryClient) jclient);
61 throw new RuntimeException(e);
65 public static RepositoryClientFactory getInstance() {
70 * get repository client
71 * @param clientName name of the client as found in service binding
74 public RepositoryClient getClient(String clientName) {
75 return clients.get(clientName);