View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.api.config.domain.key;
17  
18  import java.io.Serializable;
19  
20  
21  /**
22   * Helper to construct configuration keys.
23   */
24  public interface ConfigurationKeyHelper extends Serializable
25  {
26  
27    /**
28     * Loads the application identifier from the manifest file pointed at by the
29     * given {@code locator} class.
30     *
31     * @param locator the class to locate the manifest file to load. It is the
32     *          manifest file of the archive this class is part of.
33     * @return the application identifier.
34     * @throws IllegalStateException if the application identifier cannot be read
35     *           from the manifest.
36     * @see #load(EnvironmentId, Class)
37     */
38    ConfigurationKey<?> load(Class<?> locator)
39      throws IllegalStateException;
40  
41    /**
42     * Loads the application identifier from the manifest file pointed at by the
43     * given {@code locator} class.
44     *
45     * @param environmentName the name of the environment of use. May be
46     *          <code>null</code> if the value of the system property
47     *          {@link EnvAppConfigurationKeyHelper#SYSTEM_PROPERTY_ENVIRONMENT_NAME}
48     *          should be used (along with the node name defined by
49     *          {@link EnvAppConfigurationKeyHelper#SYSTEM_PROPERTY_ENVIRONMENT_NODE}).
50     *          If not specified, the name of the host of this runtime is determined.
51     * @param locator the class to locate the manifest file to load. It is the
52     *          manifest file of the archive this class is part of.
53     * @return the application identifier.
54     * @throws IllegalStateException if the application identifier cannot be read
55     *           from the manifest.
56     * @see #load(EnvironmentId, Class)
57     */
58    ConfigurationKey<?> load(String environmentName, Class<?> locator)
59      throws IllegalStateException;
60  
61    /**
62     * Loads the application identifier from the manifest file pointed at by the
63     * given {@code locator} class.
64     *
65     * @param environmentId the environment part of the configuration key to
66     *          construct.
67     * @param locator the class to locate the manifest file to load. It is the
68     *          manifest file of the archive this class is part of.
69     * @return the application identifier.
70     * @throws IllegalStateException if the application identifier cannot be read
71     *           from the manifest.
72     * @see #load(Class)
73     * @see #load(String, Class)
74     */
75    ConfigurationKey<?> load(EnvironmentId environmentId, Class<?> locator)
76      throws IllegalStateException;
77  
78    /**
79     * Loads the configuration key using the given applicationId and determines
80     * the environmentId through system properties or defaults (null for the
81     * environment and hostname for the node).
82     *
83     * @param applicationId the application part of the configuration key to
84     *          construct.
85     * @return the configuration key.
86     */
87    ConfigurationKey<?> load(ApplicationId applicationId);
88  }