1 //======================================================================== 2 //$Id: FileConfigurationManager.java 1096 2006-10-12 20:59:46Z janb $ 3 //Copyright 2006 Mort Bay Consulting Pty. Ltd. 4 //------------------------------------------------------------------------ 5 //Licensed under the Apache License, Version 2.0 (the "License"); 6 //you may not use this file except in compliance with the License. 7 //You may obtain a copy of the License at 8 //http://www.apache.org/licenses/LICENSE-2.0 9 //Unless required by applicable law or agreed to in writing, software 10 //distributed under the License is distributed on an "AS IS" BASIS, 11 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 //See the License for the specific language governing permissions and 13 //limitations under the License. 14 //======================================================================== 15 16 package org.mortbay.jetty.deployer; 17 18 import java.io.FileNotFoundException; 19 import java.io.IOException; 20 import java.net.MalformedURLException; 21 import java.util.Map; 22 import java.util.Properties; 23 24 import org.mortbay.resource.Resource; 25 26 /** 27 * FileConfigurationManager 28 * 29 * Supplies properties defined in a file. 30 */ 31 public class FileConfigurationManager implements ConfigurationManager 32 { 33 private Resource _file; 34 private Properties _properties = new Properties(); 35 36 public FileConfigurationManager() 37 { 38 } 39 40 41 public void setFile (String filename) 42 throws MalformedURLException, IOException 43 { 44 _file = Resource.newResource(filename); 45 } 46 47 48 /** 49 * @see org.mortbay.jetty.deployer.ConfigurationManager#getProperties() 50 */ 51 public Map getProperties() 52 { 53 try 54 { 55 loadProperties(); 56 return _properties; 57 } 58 catch (Exception e) 59 { 60 throw new RuntimeException(e); 61 } 62 } 63 64 65 private void loadProperties () 66 throws FileNotFoundException, IOException 67 { 68 if (_properties.isEmpty()) 69 _properties.load(_file.getInputStream()); 70 } 71 }