]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ad2fef0dcc03b24405d155c036c6698dec327cce
[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.context.ServiceContextImpl;\r
28 import org.collectionspace.services.common.repository.DocumentHandler;\r
29 import org.collectionspace.services.common.repository.RepositoryClient;\r
30 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
31 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\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 \r
40     public AbstractCollectionSpaceResource() {\r
41         repositoryClientFactory = RepositoryClientFactory.getInstance();\r
42     }\r
43 \r
44     @Override\r
45     abstract public String getServiceName();\r
46 \r
47     @Override\r
48     public RepositoryClientFactory getRepositoryClientFactory() {\r
49         return repositoryClientFactory;\r
50     }\r
51 \r
52     @Override\r
53     synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
54         if(repositoryClient != null){\r
55             return repositoryClient;\r
56         }\r
57         repositoryClient = repositoryClientFactory.getClient(ctx.getRepositoryClientName());\r
58         return repositoryClient;\r
59     }\r
60 \r
61     @Override\r
62     public ServiceContext createServiceContext(MultipartInput input) throws Exception {\r
63         ServiceContext ctx = new ServiceContextImpl(getServiceName());\r
64         ctx.setInput(input);\r
65         return ctx;\r
66     }\r
67 \r
68     @Override\r
69     abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
70 }\r