View Javadoc

1   package cz.cuni.amis.utils.configuration.providers;
2   
3   import cz.cuni.amis.utils.configuration.PropertyProvider;
4   import java.io.IOException;
5   import java.io.InputStream;
6   import java.util.Properties;
7   
8   /**
9    * Wrapper of java.util.Properties class.
10   * @author ik
11   */
12  public abstract class AbstractPropertiesProvider extends PropertyProvider {
13  
14      Properties props = new Properties();
15      String sourceDescription;
16  
17      /**
18       * @param sourceDescription human readable decription of resource from which the properties were read
19       * @param is Reader from which the Properties can be loaded.
20       */
21      public AbstractPropertiesProvider(InputStream is, String sourceDescription) {
22          try {
23              props.load(is);
24              this.sourceDescription = sourceDescription;
25          } catch (Exception ex) {
26               throw new RuntimeException("Properties cannot be read from '" + sourceDescription +"'.", ex);
27          }
28      }
29  
30      @Override
31      public String getProperty(String key) {
32          return props.getProperty(key);
33      }
34  
35      @Override
36      public String toString() {
37          return "Properties from " + sourceDescription;
38      }
39  }