View Javadoc

1   /*
2    * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3    *
4    * Redistribution and use in source and binary forms, with or without
5    * modification, are permitted under the terms of either of the following
6    * Open Source licenses:
7    *
8    * The GNU General Public License, version 2, or any later version, as
9    * published by the Free Software Foundation
10   * (http://www.fsf.org/copyleft/gpl.html);
11   *
12   *  or
13   *
14   * The Semiotek Public License (http://webmacro.org/LICENSE.)
15   *
16   * This software is provided "as is", with NO WARRANTY, not even the
17   * implied warranties of fitness to purpose, or merchantability. You
18   * assume all risks and liabilities associated with its use.
19   *
20   * See www.webmacro.org for more information on the WebMacro project.
21   */
22  
23  
24  package org.webmacro.resource;
25  
26  import org.webmacro.Broker;
27  import org.webmacro.InitException;
28  import org.webmacro.NotFoundException;
29  import org.webmacro.Provider;
30  import org.webmacro.util.Settings;
31  
32  /***
33   * A very simple provider which simply takes the config information
34   * passed to it by the broker and returns it.
35   */
36  public class ConfigProvider implements Provider
37  {
38  
39      private Settings _config;
40  
41      public String getType ()
42      {
43          return "config";
44      }
45  
46      public void init (Broker b, Settings config) throws InitException
47      {
48          _config = config;
49          if (_config == null)
50          {
51              throw new InitException("Attempt to init with no configuration");
52          }
53      }
54  
55      public void flush ()
56      {
57      }
58  
59      public void destroy ()
60      {
61          _config = null;
62      }
63  
64      public Object get (String key) throws NotFoundException
65      {
66          Object o = _config.getSetting(key);
67          if (o == null)
68          {
69              throw new NotFoundException("No config information for: " + key);
70          }
71          return o;
72      }
73  }