]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7a15ab37498c681baa84a0898e531e262040e9a5
[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         File configFile = new File(configFileName);
59         if(!configFile.exists()){
60             String msg = "Could not find configuration file " + configFileName;
61             logger.error(msg);
62             throw new RuntimeException(msg);
63         }
64         serviceConfig = (ServiceConfig) parse(configFile, ServiceConfig.class);
65         clientType = serviceConfig.getRepositoryClient().getClientType();
66         if(clientType == null){
67             String msg = "Missing <client-type> in <repository-client>";
68             logger.error(msg);
69             throw new IllegalArgumentException(msg);
70         }
71         clientClassName = serviceConfig.getRepositoryClient().getClientClass();
72         if(clientClassName == null){
73             String msg = "Missing <client-class> in <repository-client>";
74             logger.error(msg);
75             throw new IllegalArgumentException(msg);
76         }
77         if(logger.isDebugEnabled()){
78             logger.debug("using client=" + clientType.toString() + " class=" + clientClassName);
79         }
80     }
81
82     @Override
83     public ServiceConfig getConfiguration() {
84         return serviceConfig;
85     }
86
87     public ClientType getClientType() {
88         return clientType;
89     }
90
91     public String getClientClass() {
92         return clientClassName;
93     }
94 }