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 org.collectionspace.services.common.*;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * ServicesConfigReader reads service layer specific configuration
34 * $LastChangedRevision: $
37 public class ServicesConfigReaderImpl
38 extends AbstractConfigReaderImpl<ServiceConfig> {
40 final private static String CONFIG_FILE_NAME = "service-config.xml";
41 final Logger logger = LoggerFactory.getLogger(ServicesConfigReaderImpl.class);
42 private ServiceConfig serviceConfig;
43 private ClientType clientType;
44 private String clientClassName;
46 public ServicesConfigReaderImpl(String serverRootDir) {
51 public String getFileName() {
52 return CONFIG_FILE_NAME;
56 public void read() throws Exception {
57 String configFileName = getAbsoluteFileName(CONFIG_FILE_NAME);
62 public void read(String configFileName) throws Exception {
63 if (logger.isDebugEnabled()) {
64 logger.debug("read() config file=" + configFileName);
66 File configFile = new File(configFileName);
67 if (!configFile.exists()) {
68 String msg = "Could not find configuration file " + configFileName;
70 throw new RuntimeException(msg);
72 serviceConfig = (ServiceConfig) parse(configFile, ServiceConfig.class);
73 clientType = serviceConfig.getRepositoryClient().getClientType();
74 if (clientType == null) {
75 String msg = "Missing <client-type> in <repository-client>";
77 throw new IllegalArgumentException(msg);
79 clientClassName = serviceConfig.getRepositoryClient().getClientClass();
80 if (clientClassName == null) {
81 String msg = "Missing <client-class> in <repository-client>";
83 throw new IllegalArgumentException(msg);
85 if (logger.isDebugEnabled()) {
86 logger.debug("using client=" + clientType.toString() + " class=" + clientClassName);
91 public ServiceConfig getConfiguration() {
95 public ClientType getClientType() {
99 public String getClientClass() {
100 return clientClassName;