Coverage Report - org.webmacro.resource.ConfigProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigProvider
61%
8/13
50%
2/4
1.8
 
 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  6
 public class ConfigProvider implements Provider
 37  
 {
 38  
 
 39  
     private Settings _config;
 40  
 
 41  
     public String getType ()
 42  
     {
 43  6
         return "config";
 44  
     }
 45  
 
 46  
     public void init (Broker b, Settings config) throws InitException
 47  
     {
 48  6
         _config = config;
 49  6
         if (_config == null)
 50  
         {
 51  0
             throw new InitException("Attempt to init with no configuration");
 52  
         }
 53  6
     }
 54  
 
 55  
     public void flush ()
 56  
     {
 57  0
     }
 58  
 
 59  
     public void destroy ()
 60  
     {
 61  0
         _config = null;
 62  0
     }
 63  
 
 64  
     public Object get (String key) throws NotFoundException
 65  
     {
 66  228
         Object o = _config.getSetting(key);
 67  228
         if (o == null)
 68  
         {
 69  0
             throw new NotFoundException("No config information for: " + key);
 70  
         }
 71  228
         return o;
 72  
     }
 73  
 }