2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.common.document;
26 import java.util.HashMap;
29 import java.util.StringTokenizer;
30 import org.collectionspace.services.common.context.ServiceContext;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * AbstractDocumentHandler
38 * $LastChangedRevision: $
41 public abstract class AbstractDocumentHandler<T, TL>
42 implements DocumentHandler<T, TL> {
44 private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandler.class);
45 private Map<String, Object> properties = new HashMap<String, Object>();
46 private DocumentFilter docFilter = new DocumentFilter();
47 private ServiceContext serviceContext;
49 public AbstractDocumentHandler() {
53 public ServiceContext getServiceContext() {
54 return serviceContext;
58 public void setServiceContext(ServiceContext ctx) {
63 * @return the properties
66 public Map<String, Object> getProperties() {
71 * @param properties the properties to set
74 public void setProperties(Map<String, Object> properties) {
75 this.properties = properties;
79 * @return the DocumentFilter
82 public DocumentFilter getDocumentFilter() {
87 * @param properties the DocumentFilter to set
90 public void setDocumentFilter(DocumentFilter docFilter) {
91 this.docFilter = docFilter;
95 public void prepare(Action action) throws Exception {
96 //no specific action needed
100 public void handle(Action action, DocumentWrapper wrapDoc) throws Exception {
103 handleCreate(wrapDoc);
107 handleUpdate(wrapDoc);
115 handleGetAll(wrapDoc);
122 public abstract void handleCreate(DocumentWrapper wrapDoc) throws Exception;
125 public abstract void handleUpdate(DocumentWrapper wrapDoc) throws Exception;
128 public abstract void handleGet(DocumentWrapper wrapDoc) throws Exception;
131 public abstract void handleGetAll(DocumentWrapper wrapDoc) throws Exception;
134 public void complete(Action action, DocumentWrapper wrapDoc) throws Exception {
136 //TODO: add more actions if needed
138 completeUpdate(wrapDoc);
144 public void completeUpdate(DocumentWrapper wrapDoc) throws Exception {
145 //no specific action needed
149 public abstract void extractAllParts(DocumentWrapper wrapDoc)
153 public abstract void fillAllParts(DocumentWrapper wrapDoc)
157 public abstract T extractCommonPart(DocumentWrapper wrapDoc)
161 public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc)
165 public abstract TL extractCommonPartList(DocumentWrapper wrapDoc)
169 final public void fillCommonPartList(TL obj, DocumentWrapper wrapDoc) throws Exception {
170 throw new UnsupportedOperationException("bulk create/update not yet supported");
174 public abstract T getCommonPart();
177 public abstract void setCommonPart(T obj);
180 public abstract TL getCommonPartList();
183 public abstract void setCommonPartList(TL obj);
186 public abstract String getQProperty(String prop);
189 public String getUnQProperty(String qProp) {
190 StringTokenizer tkz = new StringTokenizer(qProp, ":");
191 if(tkz.countTokens() != 2){
192 String msg = "Property must be in the form xxx:yyy, " +
193 "e.g. collectionobjects_common:objectNumber";
195 throw new IllegalArgumentException(msg);
197 tkz.nextToken(); //skip
198 return tkz.nextToken();
202 public String getServiceContextPath() {
203 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";