1 23 24 package com.sun.enterprise.admin.util; 25 import java.io.IOException ; 26 import java.io.File ; 27 import java.io.InputStream ; 28 import java.io.FileInputStream ; 29 import java.util.Properties ; 30 31 41 public class PropertiesStringSource implements IStringSource 42 { 43 46 public PropertiesStringSource(Properties p) 47 { 48 initialize(p); 49 } 50 51 public PropertiesStringSource(InputStream is) throws IOException 52 { 53 initialize(is); 54 } 55 56 60 public PropertiesStringSource(File f) throws IOException 61 { 62 initialize(f); 63 } 64 65 66 70 public PropertiesStringSource(String filename) throws IOException 71 { 72 initialize(filename); 73 } 74 75 76 81 public String getString(String key) 82 { 83 Assert.assertit((mProperties!=null), "invalid state: mProperties is null"); 84 85 87 return mProperties.getProperty(key); 88 } 89 90 91 99 100 105 protected PropertiesStringSource() 106 { 107 111 } 112 113 114 117 protected void initialize(Properties properties) 118 { 119 mProperties = properties; 121 } 122 123 124 128 protected void initialize(File file) throws IOException 129 { 130 133 136 FileInputStream fis = new FileInputStream (file); 139 initialize(fis); 140 } 141 142 143 146 protected void initialize(String filename) throws IOException 147 { 148 initialize(new File (filename)); 150 } 151 152 155 protected void initialize(InputStream is) throws IOException 156 { 157 mProperties = new Properties (); 159 mProperties.load(is); 160 } 161 162 private Properties mProperties; 163 } 164 165 | Popular Tags |