]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
bac653c5f6976df87def9958d6b6de52c9b4305b
[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.RemoteServiceContext;\r
27 import org.collectionspace.services.common.context.ServiceContext;\r
28 import org.collectionspace.services.common.context.RemoteServiceContextImpl;\r
29 import org.collectionspace.services.common.repository.DocumentHandler;\r
30 import org.collectionspace.services.common.repository.RepositoryClient;\r
31 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
32 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
33 \r
34 public abstract class AbstractCollectionSpaceResource\r
35         implements CollectionSpaceResource {\r
36 \r
37     // Fields for default client factory and client\r
38     private RepositoryClientFactory repositoryClientFactory;\r
39     private RepositoryClient repositoryClient;\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     @Override\r
49     public RepositoryClientFactory getRepositoryClientFactory() {\r
50         return repositoryClientFactory;\r
51     }\r
52 \r
53     @Override\r
54     synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
55         if(repositoryClient != null){\r
56             return repositoryClient;\r
57         }\r
58         repositoryClient = repositoryClientFactory.getClient(ctx.getRepositoryClientName());\r
59         return repositoryClient;\r
60     }\r
61 \r
62     @Override\r
63     public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception {\r
64         return createServiceContext(input,getServiceName());\r
65     }\r
66 \r
67     @Override\r
68     public RemoteServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception {\r
69         RemoteServiceContext ctx = new RemoteServiceContextImpl(serviceName);\r
70         ctx.setInput(input);\r
71         return ctx;\r
72     }\r
73 \r
74     @Override\r
75     abstract public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;\r
76 }\r