View Javadoc

1   /*
2   * #%L
3    * * Bitrepository Protocol
4    * 
5    * * $Id$
6    * * $HeadURL$
7    * *
8    * %%
9    * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
10   * *
11   * %%
12   * This program is free software: you can redistribute it and/or modify
13   * it under the terms of the GNU Lesser General Public License as 
14   * published by the Free Software Foundation, either version 2.1 of the 
15   * License, or (at your option) any later version.
16   * 
17   * This program is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Lesser Public License for more details.
21   * 
22   * You should have received a copy of the GNU General Lesser Public 
23   * License along with this program.  If not, see
24   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
25   * #L%
26  */
27  
28  package org.bitrepository.service;
29  
30  import org.bitrepository.common.settings.SettingsLoader;
31  import org.bitrepository.common.settings.SettingsProvider;
32  import org.bitrepository.settings.referencesettings.ReferenceSettings;
33  import org.bitrepository.settings.referencesettings.ServiceType;
34  
35  public class ServiceSettingsProvider extends SettingsProvider {
36      private final ServiceType serviceType;
37  
38      /**
39       * Creates a <code>SettingsProvider</code> which will use the provided <code>SettingsLoader</code> for loading the
40       * settings.
41       *
42       * @param settingsReader Use for loading the settings.
43       * @param serviceType Will be used to load a componentID for the service based on the type.
44       */
45      public ServiceSettingsProvider(SettingsLoader settingsReader, ServiceType serviceType) {
46          super(settingsReader, null);
47          this.serviceType = serviceType;
48      }
49  
50      protected String getComponentID(ReferenceSettings referenceSettings) {
51          switch (serviceType) {
52              case ALARM_SERVICE:
53                  return referenceSettings.getAlarmServiceSettings().getID();
54              case AUDIT_TRAIL_SERVICE:
55                  return referenceSettings.getAuditTrailServiceSettings().getID();
56              case INTEGRITY_SERVICE:
57                  return referenceSettings.getIntegrityServiceSettings().getID();
58              case MONITORING_SERVICE:
59                  return referenceSettings.getMonitoringServiceSettings().getID();
60              default:
61                  throw new IllegalArgumentException("Unknown service type");
62          }
63      }
64  }