]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
67b916489a4feb5680b2b8c5c3055ef729877fb1
[tmp/jakarta-migration.git] /
1 /**\r
2  *  This document is a part of the source code and related artifacts\r
3  *  for CollectionSpace, an open source collections management system\r
4  *  for museums and related institutions:\r
5 \r
6  *  http://www.collectionspace.org\r
7  *  http://wiki.collectionspace.org\r
8 \r
9  *  Copyright 2009 University of California at Berkeley\r
10 \r
11  *  Licensed under the Educational Community License (ECL), Version 2.0.\r
12  *  You may not use this file except in compliance with this License.\r
13 \r
14  *  You may obtain a copy of the ECL 2.0 License at\r
15 \r
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
17 \r
18  *  Unless required by applicable law or agreed to in writing, software\r
19  *  distributed under the License is distributed on an "AS IS" BASIS,\r
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
21  *  See the License for the specific language governing permissions and\r
22  *  limitations under the License.\r
23  */\r
24 package org.collectionspace.services.common;\r
25 \r
26 import org.collectionspace.services.common.context.ServiceContext;\r
27 import org.collectionspace.services.common.document.DocumentHandler;\r
28 import org.collectionspace.services.common.repository.RepositoryClient;\r
29 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
30 import org.collectionspace.services.common.storage.StorageClient;\r
31 import org.collectionspace.services.common.storage.jpa.JpaStorageClient;\r
32 \r
33 public abstract class AbstractCollectionSpaceResource\r
34         implements CollectionSpaceResource {\r
35 \r
36     // Fields for default client factory and client\r
37     private RepositoryClientFactory repositoryClientFactory;\r
38     private RepositoryClient repositoryClient;\r
39     private StorageClient storageClient;\r
40 \r
41     public AbstractCollectionSpaceResource() {\r
42         repositoryClientFactory = RepositoryClientFactory.getInstance();\r
43     }\r
44 \r
45     @Override\r
46     abstract public String getServiceName();\r
47 \r
48 \r
49     @Override\r
50     synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
51         if(repositoryClient != null){\r
52             return repositoryClient;\r
53         }\r
54         repositoryClient = repositoryClientFactory.getClient(ctx.getRepositoryClientName());\r
55         return repositoryClient;\r
56     }\r
57 \r
58     @Override\r
59     synchronized public StorageClient getStorageClient(ServiceContext ctx) {\r
60         if(storageClient != null) {\r
61             return storageClient;\r
62         }\r
63         storageClient = new JpaStorageClient();\r
64         return storageClient;\r
65     }\r
66 \r
67     @Override\r
68     abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
69 }\r