]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
c14549322e22e38870e0cfb20d226f9387d5cd2c
[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.util.Hashtable;
27 import org.collectionspace.services.common.NuxeoClientType;
28
29 /**
30  * RepositoryClientFactory is a singleton factory that provides required Nuxeo client
31  * it does not create clients as the clients are singletons
32  *
33  * $LastChangedRevision: $
34  * $LastChangedDate: $
35  */
36 public class RepositoryClientFactory {
37
38     
39     private static final RepositoryClientFactory self = new RepositoryClientFactory();
40     private Hashtable<String, RepositoryClient> clients = new Hashtable<String, RepositoryClient>();
41
42     private RepositoryClientFactory() {
43         try{
44             ClassLoader cloader = Thread.currentThread().getContextClassLoader();
45
46             Class jclazz = cloader.loadClass("org.collectionspace.services.nuxeo.client.java.RepositoryJavaClient");
47             Object jclient = jclazz.newInstance();
48             clients.put(NuxeoClientType.JAVA.toString(), (RepositoryClient) jclient);
49
50             Class rclazz = cloader.loadClass("org.collectionspace.services.nuxeo.client.rest.RepositoryRESTClient");
51             Object rclient = rclazz.newInstance();
52             clients.put(NuxeoClientType.REST.toString(), (RepositoryClient) rclient);
53
54         }catch(Exception e){
55             throw new RuntimeException(e);
56         }
57     }
58
59     public static RepositoryClientFactory getInstance() {
60         return self;
61     }
62
63     public RepositoryClient getClient(String clientType) {
64         return clients.get(clientType);
65     }
66 }