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.util.Hashtable;
27 import org.collectionspace.services.common.ServiceMain;
28 import org.collectionspace.services.common.config.ServicesConfigReaderImpl;
29 import org.collectionspace.services.config.RepositoryClientConfigType;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * RepositoryClientFactory is a singleton factory that creates required repository
35 * clients. Repository clients are singletons.
37 * $LastChangedRevision: $
40 public class RepositoryClientFactory<IT, OT> {
42 private static final RepositoryClientFactory self = new RepositoryClientFactory();
43 final Logger logger = LoggerFactory.getLogger(RepositoryClientFactory.class);
44 //clients key=client name, value=repository client
45 private Hashtable<String, RepositoryClient<IT, OT>> clients = new Hashtable<String, RepositoryClient<IT, OT>>();
47 private RepositoryClientFactory() {
49 ServicesConfigReaderImpl scReader = ServiceMain.getInstance().getServicesConfigReader();
50 RepositoryClientConfigType repositoryClientConfig = scReader.getConfiguration().getRepositoryClient();
51 String clientClassName = repositoryClientConfig.getClientClass();
52 String clientName = repositoryClientConfig.getName();
53 ClassLoader cloader = Thread.currentThread().getContextClassLoader();
55 Class jclazz = cloader.loadClass(clientClassName);
56 RepositoryClient<IT, OT> jclient = (RepositoryClient<IT, OT>)jclazz.newInstance();
57 clients.put(clientName, jclient);
60 throw new RuntimeException(e);
64 public static RepositoryClientFactory getInstance() {
69 * get repository client
70 * @param clientName name of the client as found in service binding
73 public RepositoryClient<IT, OT> getClient(String clientName) {
74 return clients.get(clientName);