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 AbstractCollectionSpaceResourceImpl.
\r
43 * @param <IT> the generic type
\r
44 * @param <OT> the generic type
\r
46 public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
\r
47 implements CollectionSpaceResource<IT, OT> {
\r
49 // Fields for default client factory and client
\r
50 /** The repository client factory. */
\r
51 private RepositoryClientFactory repositoryClientFactory;
\r
53 /** The repository client. */
\r
54 private RepositoryClient repositoryClient;
\r
56 /** The storage client. */
\r
57 private StorageClient storageClient;
\r
60 * Instantiates a new abstract collection space resource.
\r
62 public AbstractCollectionSpaceResourceImpl() {
\r
63 repositoryClientFactory = RepositoryClientFactory.getInstance();
\r
67 * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceName()
\r
70 abstract public String getServiceName();
\r
74 * @see org.collectionspace.services.common.CollectionSpaceResource#getRepositoryClient(org.collectionspace.services.common.context.ServiceContext)
\r
77 synchronized public RepositoryClient getRepositoryClient(ServiceContext<IT, OT> ctx) {
\r
78 if(repositoryClient != null){
\r
79 return repositoryClient;
\r
81 repositoryClient = repositoryClientFactory.getClient(ctx.getRepositoryClientName());
\r
82 return repositoryClient;
\r
86 * @see org.collectionspace.services.common.CollectionSpaceResource#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
\r
89 synchronized public StorageClient getStorageClient(ServiceContext<IT, OT> ctx) {
\r
90 if(storageClient != null) {
\r
91 return storageClient;
\r
93 storageClient = new JpaStorageClientImpl();
\r
94 return storageClient;
\r
98 * @see org.collectionspace.services.common.CollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
\r
101 public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx) throws Exception {
\r
102 DocumentHandler docHandler = createDocumentHandler(ctx, ctx.getInput());
\r
107 * Creates the document handler.
\r
109 * @param ctx the ctx
\r
110 * @param commonPart the common part
\r
112 * @return the document handler
\r
114 * @throws Exception the exception
\r
116 public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx,
\r
117 Object commonPart) throws Exception {
\r
118 DocumentHandler docHandler = ctx.getDocumentHandler();
\r
119 docHandler.setCommonPart(commonPart);
\r
124 * Creates the service context.
\r
126 * @return the service context< i t, o t>
\r
128 * @throws Exception the exception
\r
130 protected ServiceContext<IT, OT> createServiceContext() throws Exception {
\r
131 ServiceContext<IT, OT> ctx = createServiceContext(this.getServiceName(),
\r
132 (IT)null, //inputType
\r
133 (MultivaluedMap<String, String>)null, /*queryParams*/
\r
134 this.getCommonPartClass());
\r
139 * Creates the service context.
\r
141 * @param serviceName the service name
\r
143 * @return the service context< i t, o t>
\r
145 * @throws Exception the exception
\r
147 protected ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception {
\r
148 ServiceContext<IT, OT> ctx = createServiceContext(
\r
150 (IT)null, /*input*/
\r
151 (MultivaluedMap<String, String>)null, /*queryParams*/
\r
152 (Class<?>)null /*input type's Class*/);
\r
157 * Creates the service context.
\r
159 * @param serviceName the service name
\r
160 * @param input the input
\r
162 * @return the service context< i t, o t>
\r
164 * @throws Exception the exception
\r
166 protected ServiceContext<IT, OT> createServiceContext(String serviceName,
\r
167 IT input) throws Exception {
\r
168 ServiceContext<IT, OT> ctx = createServiceContext(serviceName, input,
\r
169 (MultivaluedMap<String, String>)null, /*queryParams*/
\r
170 (Class<?>)null /*input type's Class*/);
\r
175 * Creates the service context.
\r
177 * @param serviceName the service name
\r
178 * @param input the input
\r
180 * @return the service context< i t, o t>
\r
182 * @throws Exception the exception
\r
184 protected ServiceContext<IT, OT> createServiceContext(String serviceName,
\r
185 MultivaluedMap<String, String> queryParams) throws Exception {
\r
186 ServiceContext<IT, OT> ctx = createServiceContext(serviceName,
\r
189 (Class<?>)null /*input type's Class*/);
\r
194 * Creates the service context.
\r
196 * @param queryParams the query params
\r
198 * @return the service context< i t, o t>
\r
200 * @throws Exception the exception
\r
202 protected ServiceContext<IT, OT> createServiceContext(MultivaluedMap<String, String> queryParams) throws Exception {
\r
203 ServiceContext<IT, OT> ctx = createServiceContext(
\r
204 (IT)null, /*input*/
\r
206 (Class<?>)null /*input type's Class*/);
\r
211 * Creates the service context.
\r
213 * @param input the input
\r
215 * @return the service context< i t, o t>
\r
217 * @throws Exception the exception
\r
219 protected ServiceContext<IT, OT> createServiceContext(IT input) throws Exception {
\r
220 ServiceContext<IT, OT> ctx = createServiceContext(
\r
222 (Class<?>)null /*input type's Class*/);
\r
227 * Creates the service context.
\r
229 * @param input the input
\r
230 * @param theClass the the class
\r
232 * @return the service context
\r
234 * @throws Exception the exception
\r
236 protected ServiceContext<IT, OT> createServiceContext(IT input, Class<?> theClass) throws Exception {
\r
237 ServiceContext<IT, OT> ctx = createServiceContext(
\r
239 (MultivaluedMap<String, String>)null, //queryParams,
\r
245 * Creates the service context.
\r
247 * @param input the input
\r
248 * @param queryParams the query params
\r
249 * @param theClass the the class
\r
251 * @return the service context< i t, o t>
\r
253 * @throws Exception the exception
\r
255 protected ServiceContext<IT, OT> createServiceContext(
\r
257 MultivaluedMap<String, String> queryParams,
\r
258 Class<?> theClass) throws Exception {
\r
259 return createServiceContext(this.getServiceName(),
\r
266 * Creates the service context.
\r
268 * @param serviceName the service name
\r
269 * @param input the input
\r
270 * @param queryParams the query params
\r
271 * @param theClass the the class
\r
273 * @return the service context< i t, o t>
\r
275 * @throws Exception the exception
\r
277 private ServiceContext<IT, OT> createServiceContext(
\r
278 String serviceName,
\r
280 MultivaluedMap<String, String> queryParams,
\r
281 Class<?> theClass) throws Exception {
\r
282 ServiceContext<IT, OT> ctx = getServiceContextFactory().createServiceContext(
\r
286 theClass != null ? theClass.getPackage().getName() : null,
\r
287 theClass != null ? theClass.getName() : null);
\r
292 * Gets the version string.
\r
294 * @return the version string
\r
296 abstract protected String getVersionString();
\r
299 * Gets the version.
\r
301 * @return the version
\r
305 @Produces("application/xml")
\r
306 public Version getVersion() {
\r
307 Version result = new Version();
\r
309 result.setVersionString(getVersionString());
\r