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
6 * http://www.collectionspace.org
\r
7 * http://wiki.collectionspace.org
\r
9 * Copyright 2009 University of California at Berkeley
\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
14 * You may obtain a copy of the ECL 2.0 License at
\r
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
\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
24 package org.collectionspace.services.common;
\r
26 import javax.ws.rs.GET;
\r
27 import javax.ws.rs.Path;
\r
28 import javax.ws.rs.Produces;
\r
29 import javax.ws.rs.core.MultivaluedMap;
\r
31 import org.collectionspace.services.common.context.RemoteServiceContext;
\r
32 import org.collectionspace.services.common.context.ServiceContext;
\r
33 import org.collectionspace.services.common.context.ServiceContextFactory;
\r
34 import org.collectionspace.services.common.document.DocumentHandler;
\r
35 import org.collectionspace.services.common.repository.RepositoryClient;
\r
36 import org.collectionspace.services.common.repository.RepositoryClientFactory;
\r
37 import org.collectionspace.services.common.storage.StorageClient;
\r
38 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
\r
41 * The Class AbstractCollectionSpaceResource.
\r
43 public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
\r
44 implements CollectionSpaceResource<IT, OT> {
\r
46 // Fields for default client factory and client
\r
47 /** The repository client factory. */
\r
48 private RepositoryClientFactory repositoryClientFactory;
\r
50 /** The repository client. */
\r
51 private RepositoryClient repositoryClient;
\r
53 /** The storage client. */
\r
54 private StorageClient storageClient;
\r
57 * Instantiates a new abstract collection space resource.
\r
59 public AbstractCollectionSpaceResourceImpl() {
\r
60 repositoryClientFactory = RepositoryClientFactory.getInstance();
\r
64 * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceName()
\r
67 abstract public String getServiceName();
\r
71 * @see org.collectionspace.services.common.CollectionSpaceResource#getRepositoryClient(org.collectionspace.services.common.context.ServiceContext)
\r
74 synchronized public RepositoryClient getRepositoryClient(ServiceContext<IT, OT> ctx) {
\r
75 if(repositoryClient != null){
\r
76 return repositoryClient;
\r
78 repositoryClient = repositoryClientFactory.getClient(ctx.getRepositoryClientName());
\r
79 return repositoryClient;
\r
83 * @see org.collectionspace.services.common.CollectionSpaceResource#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
\r
86 synchronized public StorageClient getStorageClient(ServiceContext<IT, OT> ctx) {
\r
87 if(storageClient != null) {
\r
88 return storageClient;
\r
90 storageClient = new JpaStorageClientImpl();
\r
91 return storageClient;
\r
95 * @see org.collectionspace.services.common.CollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
\r
98 public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx) throws Exception {
\r
99 DocumentHandler docHandler = createDocumentHandler(ctx, ctx.getInput());
\r
104 * Creates the document handler.
\r
106 * @param ctx the ctx
\r
107 * @param commonPart the common part
\r
109 * @return the document handler
\r
111 * @throws Exception the exception
\r
113 public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx,
\r
114 Object commonPart) throws Exception {
\r
115 DocumentHandler docHandler = ctx.getDocumentHandler();
\r
116 docHandler.setCommonPart(commonPart);
\r
121 * Creates the service context.
\r
123 * @return the service context< i t, o t>
\r
125 * @throws Exception the exception
\r
127 protected ServiceContext<IT, OT> createServiceContext() throws Exception {
\r
128 ServiceContext<IT, OT> ctx = createServiceContext(this.getServiceName(),
\r
129 (IT)null, //inputType
\r
130 (MultivaluedMap<String, String>)null, /*queryParams*/
\r
131 this.getCommonPartClass());
\r
136 * Creates the service context.
\r
138 * @param serviceName the service name
\r
140 * @return the service context< i t, o t>
\r
142 * @throws Exception the exception
\r
144 protected ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception {
\r
145 ServiceContext<IT, OT> ctx = createServiceContext(
\r
147 (IT)null, /*input*/
\r
148 (MultivaluedMap<String, String>)null, /*queryParams*/
\r
149 (Class<?>)null /*input type's Class*/);
\r
154 * Creates the service context.
\r
156 * @param serviceName the service name
\r
157 * @param input the input
\r
159 * @return the service context< i t, o t>
\r
161 * @throws Exception the exception
\r
163 protected ServiceContext<IT, OT> createServiceContext(String serviceName,
\r
164 IT input) throws Exception {
\r
165 ServiceContext<IT, OT> ctx = createServiceContext(serviceName, input,
\r
166 (MultivaluedMap<String, String>)null, /*queryParams*/
\r
167 (Class<?>)null /*input type's Class*/);
\r
172 * Creates the service context.
\r
174 * @param serviceName the service name
\r
175 * @param input the input
\r
177 * @return the service context< i t, o t>
\r
179 * @throws Exception the exception
\r
181 protected ServiceContext<IT, OT> createServiceContext(String serviceName,
\r
182 MultivaluedMap<String, String> queryParams) throws Exception {
\r
183 ServiceContext<IT, OT> ctx = createServiceContext(serviceName,
\r
186 (Class<?>)null /*input type's Class*/);
\r
191 * Creates the service context.
\r
193 * @param queryParams the query params
\r
195 * @return the service context< i t, o t>
\r
197 * @throws Exception the exception
\r
199 protected ServiceContext<IT, OT> createServiceContext(MultivaluedMap<String, String> queryParams) throws Exception {
\r
200 ServiceContext<IT, OT> ctx = createServiceContext(
\r
201 (IT)null, /*input*/
\r
203 (Class<?>)null /*input type's Class*/);
\r
208 * Creates the service context.
\r
210 * @param input the input
\r
212 * @return the service context< i t, o t>
\r
214 * @throws Exception the exception
\r
216 protected ServiceContext<IT, OT> createServiceContext(IT input) throws Exception {
\r
217 ServiceContext<IT, OT> ctx = createServiceContext(
\r
219 (Class<?>)null /*input type's Class*/);
\r
224 * Creates the service context.
\r
226 * @param input the input
\r
227 * @param theClass the the class
\r
229 * @return the service context
\r
231 * @throws Exception the exception
\r
233 protected ServiceContext<IT, OT> createServiceContext(IT input, Class<?> theClass) throws Exception {
\r
234 ServiceContext<IT, OT> ctx = createServiceContext(
\r
236 (MultivaluedMap<String, String>)null, //queryParams,
\r
242 * Creates the service context.
\r
244 * @param input the input
\r
245 * @param queryParams the query params
\r
246 * @param theClass the the class
\r
248 * @return the service context< i t, o t>
\r
250 * @throws Exception the exception
\r
252 protected ServiceContext<IT, OT> createServiceContext(
\r
254 MultivaluedMap<String, String> queryParams,
\r
255 Class<?> theClass) throws Exception {
\r
256 return createServiceContext(this.getServiceName(),
\r
263 * Creates the service context.
\r
265 * @param serviceName the service name
\r
266 * @param input the input
\r
267 * @param queryParams the query params
\r
268 * @param theClass the the class
\r
270 * @return the service context< i t, o t>
\r
272 * @throws Exception the exception
\r
274 private ServiceContext<IT, OT> createServiceContext(
\r
275 String serviceName,
\r
277 MultivaluedMap<String, String> queryParams,
\r
278 Class<?> theClass) throws Exception {
\r
279 ServiceContext<IT, OT> ctx = getServiceContextFactory().createServiceContext(
\r
283 theClass != null ? theClass.getPackage().getName() : null,
\r
284 theClass != null ? theClass.getName() : null);
\r
289 * Gets the version string.
\r
291 * @return the version string
\r
293 abstract protected String getVersionString();
\r
296 * Gets the version.
\r
298 * @return the version
\r
302 @Produces("application/xml")
\r
303 public Version getVersion() {
\r
304 Version result = new Version();
\r
306 result.setVersionString(getVersionString());
\r