View Javadoc

1   // ========================================================================
2   // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.deploy;
15  
16  import java.io.FileNotFoundException;
17  import java.io.IOException;
18  import java.net.MalformedURLException;
19  import java.util.Map;
20  import java.util.Properties;
21  
22  import org.eclipse.jetty.util.resource.Resource;
23  
24  /**
25   * FileConfigurationManager
26   *
27   * Supplies properties defined in a file.
28   */
29  public class FileConfigurationManager implements ConfigurationManager
30  {
31      private Resource _file;
32      private Properties _properties = new Properties();
33  
34      public FileConfigurationManager()
35      {        
36      }
37      
38      
39      public void setFile (String filename) 
40      throws MalformedURLException, IOException
41      {
42          _file = Resource.newResource(filename);
43      }
44      
45      
46      /** 
47       * @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties()
48       */
49      public Map getProperties()
50      {
51          try
52          {
53              loadProperties();
54              return _properties;
55          }
56          catch (Exception e)
57          {
58              throw new RuntimeException(e);
59          }
60      }
61  
62      
63      private void loadProperties () 
64      throws FileNotFoundException, IOException
65      {
66          if (_properties.isEmpty())
67              _properties.load(_file.getInputStream());
68      }
69  }