]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e1621d062847da5d11a7e22aa1ec0dd4fc28dc72
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.common.config;
25
26 import java.io.File;
27 import org.collectionspace.services.common.*;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * ServicesConfigReader reads service layer specific configuration
33  *
34  * $LastChangedRevision: $
35  * $LastChangedDate: $
36  */
37 public class ServicesConfigReaderImpl
38         extends AbstractConfigReaderImpl<ServiceConfig> {
39
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;
45
46     public ServicesConfigReaderImpl(String serverRootDir) {
47         super(serverRootDir);
48     }
49
50     @Override
51     public String getFileName() {
52         return CONFIG_FILE_NAME;
53     }
54
55     @Override
56     public void read() throws Exception {
57         String configFileName = getAbsoluteFileName(CONFIG_FILE_NAME);
58         read(configFileName);
59     }
60
61     @Override
62     public void read(String configFileName) throws Exception {
63         if (logger.isDebugEnabled()) {
64             logger.debug("read() config file=" + configFileName);
65         }
66         File configFile = new File(configFileName);
67         if (!configFile.exists()) {
68             String msg = "Could not find configuration file " + configFileName;
69             logger.error(msg);
70             throw new RuntimeException(msg);
71         }
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>";
76             logger.error(msg);
77             throw new IllegalArgumentException(msg);
78         }
79         clientClassName = serviceConfig.getRepositoryClient().getClientClass();
80         if (clientClassName == null) {
81             String msg = "Missing <client-class> in <repository-client>";
82             logger.error(msg);
83             throw new IllegalArgumentException(msg);
84         }
85         if (logger.isDebugEnabled()) {
86             logger.debug("using client=" + clientType.toString() + " class=" + clientClassName);
87         }
88     }
89
90     @Override
91     public ServiceConfig getConfiguration() {
92         return serviceConfig;
93     }
94
95     public ClientType getClientType() {
96         return clientType;
97     }
98
99     public String getClientClass() {
100         return clientClassName;
101     }
102 }