]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d92a96adc77e9a08c52b193500db10a1ab157693
[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
28 import org.collectionspace.services.config.ClientType;
29 import org.collectionspace.services.config.ServiceConfig;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * ServicesConfigReader reads service layer specific configuration
35  *
36  * $LastChangedRevision: $
37  * $LastChangedDate: $
38  */
39 public class ServicesConfigReaderImpl
40         extends AbstractConfigReaderImpl<ServiceConfig> {
41
42     final private static String CONFIG_FILE_NAME = "service-config.xml";
43     final Logger logger = LoggerFactory.getLogger(ServicesConfigReaderImpl.class);
44     private ServiceConfig serviceConfig;
45     private ClientType clientType;
46     private String clientClassName;
47
48     public ServicesConfigReaderImpl(String serverRootDir) {
49         super(serverRootDir);
50     }
51
52     @Override
53     public String getFileName() {
54         return CONFIG_FILE_NAME;
55     }
56
57     @Override
58     public void read(boolean useAppGeneratedBindings) throws Exception {
59         String configFileName = getAbsoluteFileName(CONFIG_FILE_NAME);
60         read(configFileName, useAppGeneratedBindings);
61     }
62
63     @Override
64     public void read(String configFileName, boolean useAppGeneratedBindings) throws Exception {
65         if (logger.isDebugEnabled()) {
66             logger.debug("read() config file=" + configFileName);
67         }
68         File configFile = new File(configFileName);
69         if (!configFile.exists()) {
70             String msg = "Could not find configuration file " + configFile.getAbsolutePath(); //configFileName;
71             logger.error(msg);
72             throw new RuntimeException(msg);
73         }
74         serviceConfig = (ServiceConfig) parse(configFile, ServiceConfig.class);
75         clientType = serviceConfig.getRepositoryClient().getClientType();
76         if (clientType == null) {
77             String msg = "Missing <client-type> in <repository-client>";
78             logger.error(msg);
79             throw new IllegalArgumentException(msg);
80         }
81         clientClassName = serviceConfig.getRepositoryClient().getClientClass();
82         if (clientClassName == null) {
83             String msg = "Missing <client-class> in <repository-client>";
84             logger.error(msg);
85             throw new IllegalArgumentException(msg);
86         }
87         if (logger.isDebugEnabled()) {
88             logger.debug("using client=" + clientType.toString() + " class=" + clientClassName);
89         }
90     }
91
92     @Override
93     public ServiceConfig getConfiguration() {
94         return serviceConfig;
95     }
96
97     public ClientType getClientType() {
98         return clientType;
99     }
100
101     public String getClientClass() {
102         return clientClassName;
103     }
104 }