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.repository;
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 ServiceContext serviceContext;
48 public AbstractDocumentHandler() {
52 public ServiceContext getServiceContext() {
53 return serviceContext;
57 public void setServiceContext(ServiceContext ctx) {
62 * @return the properties
65 public Map<String, Object> getProperties() {
70 * @param properties the properties to set
73 public void setProperties(Map<String, Object> properties) {
74 this.properties = properties;
78 public void prepare(Action action) throws Exception {
79 //no specific action needed
83 public void handle(Action action, DocumentWrapper wrapDoc) throws Exception {
86 handleCreate(wrapDoc);
90 handleUpdate(wrapDoc);
98 handleGetAll(wrapDoc);
105 public abstract void handleCreate(DocumentWrapper wrapDoc) throws Exception;
108 public abstract void handleUpdate(DocumentWrapper wrapDoc) throws Exception;
111 public abstract void handleGet(DocumentWrapper wrapDoc) throws Exception;
114 public abstract void handleGetAll(DocumentWrapper wrapDoc) throws Exception;
117 public void complete(Action action, DocumentWrapper wrapDoc) throws Exception {
119 //TODO: add more actions if needed
121 completeUpdate(wrapDoc);
127 public void completeUpdate(DocumentWrapper wrapDoc) throws Exception {
128 //no specific action needed
132 public abstract void extractAllParts(DocumentWrapper wrapDoc)
136 public abstract void fillAllParts(DocumentWrapper wrapDoc)
140 public abstract T extractCommonPart(DocumentWrapper wrapDoc)
144 public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc)
148 public abstract TL extractCommonPartList(DocumentWrapper wrapDoc)
152 final public void fillCommonPartList(TL obj, DocumentWrapper wrapDoc) throws Exception {
153 throw new UnsupportedOperationException("bulk create/update not yet supported");
157 public abstract T getCommonPart();
160 public abstract void setCommonPart(T obj);
163 public abstract TL getCommonPartList();
166 public abstract void setCommonPartList(TL obj);
169 public abstract String getQProperty(String prop);
172 public String getUnQProperty(String qProp) {
173 StringTokenizer tkz = new StringTokenizer(qProp, ":");
174 if(tkz.countTokens() != 2){
175 String msg = "Property must be in the form xxx:yyy, " +
176 "e.g. collectionobjects_common:objectNumber";
178 throw new IllegalArgumentException(msg);
180 tkz.nextToken(); //skip
181 return tkz.nextToken();
185 public String getServiceContextPath() {
186 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";