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.config;
27 import javax.xml.bind.JAXBContext;
28 import javax.xml.bind.Unmarshaller;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * AbstractConfigReader
35 * $LastChangedRevision: $
38 public abstract class AbstractConfigReaderImpl<T>
39 implements ConfigReader<T> {
41 private final Logger logger = LoggerFactory.getLogger(AbstractConfigReaderImpl.class);
42 private String serverRootDir;
44 AbstractConfigReaderImpl(String serverRootDir) {
45 this.serverRootDir = serverRootDir;
49 abstract public String getFileName();
52 abstract public void read() throws Exception;
55 abstract public T getConfiguration();
59 * parse parses given configuration file from the disk based on given class
63 * @return A JAXB object
66 protected Object parse(File configFile, Class clazz) throws Exception {
67 JAXBContext jc = JAXBContext.newInstance(clazz);
68 Unmarshaller um = jc.createUnmarshaller();
69 Object readObject = um.unmarshal(configFile);
70 if(logger.isDebugEnabled()){
71 logger.debug("read() read file " + configFile.getAbsolutePath());
76 protected String getAbsoluteFileName(String configFileName) {
77 return serverRootDir +
78 File.separator + CSPACE_DIR_NAME +
79 File.separator + CONFIG_DIR_NAME +
80 File.separator + configFileName;
83 protected String getServerRootDir() {