]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
21ba6ed4df6ab661a654d518ce64bd7bf4422b01
[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 javax.ws.rs.GET;\r
27 import javax.ws.rs.Path;\r
28 import javax.ws.rs.Produces;\r
29 \r
30 import org.collectionspace.services.common.context.ServiceContext;\r
31 import org.collectionspace.services.common.document.DocumentHandler;\r
32 import org.collectionspace.services.common.repository.RepositoryClient;\r
33 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
34 import org.collectionspace.services.common.storage.StorageClient;\r
35 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;\r
36 \r
37 /**\r
38  * The Class AbstractCollectionSpaceResource.\r
39  */\r
40 public abstract class AbstractCollectionSpaceResourceImpl\r
41         implements CollectionSpaceResource {\r
42 \r
43     // Fields for default client factory and client\r
44     /** The repository client factory. */\r
45     private RepositoryClientFactory repositoryClientFactory;\r
46     \r
47     /** The repository client. */\r
48     private RepositoryClient repositoryClient;\r
49     \r
50     /** The storage client. */\r
51     private StorageClient storageClient;\r
52 \r
53     /**\r
54      * Instantiates a new abstract collection space resource.\r
55      */\r
56     public AbstractCollectionSpaceResourceImpl() {\r
57         repositoryClientFactory = RepositoryClientFactory.getInstance();\r
58     }\r
59 \r
60     /* (non-Javadoc)\r
61      * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceName()\r
62      */\r
63     @Override\r
64     abstract public String getServiceName();\r
65 \r
66 \r
67     /* (non-Javadoc)\r
68      * @see org.collectionspace.services.common.CollectionSpaceResource#getRepositoryClient(org.collectionspace.services.common.context.ServiceContext)\r
69      */\r
70     @Override\r
71     synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
72         if(repositoryClient != null){\r
73             return repositoryClient;\r
74         }\r
75         repositoryClient = repositoryClientFactory.getClient(ctx.getRepositoryClientName());\r
76         return repositoryClient;\r
77     }\r
78 \r
79     /* (non-Javadoc)\r
80      * @see org.collectionspace.services.common.CollectionSpaceResource#getStorageClient(org.collectionspace.services.common.context.ServiceContext)\r
81      */\r
82     @Override\r
83     synchronized public StorageClient getStorageClient(ServiceContext ctx) {\r
84         if(storageClient != null) {\r
85             return storageClient;\r
86         }\r
87         storageClient = new JpaStorageClientImpl();\r
88         return storageClient;\r
89     }\r
90 \r
91     /* (non-Javadoc)\r
92      * @see org.collectionspace.services.common.CollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)\r
93      */\r
94     @Override\r
95     abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
96     \r
97     /**\r
98      * Gets the version string.\r
99      * \r
100      * @return the version string\r
101      */\r
102     abstract protected String getVersionString();\r
103     \r
104     /**\r
105      * Gets the version.\r
106      * \r
107      * @return the version\r
108      */\r
109     @GET\r
110     @Path("/version")    \r
111     @Produces("application/xml")\r
112     public Version getVersion() {\r
113         Version result = new Version();\r
114         \r
115         result.setVersionString(getVersionString());\r
116         \r
117         return result;\r
118     }\r
119     \r
120 }\r