1 package org.openejb.cli; 2 3 import java.io.BufferedInputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.util.Collections ; 7 import java.util.Enumeration ; 8 import java.util.HashMap ; 9 import java.util.Map ; 10 import java.util.Properties ; 11 12 public class CommandFinder { 13 private String path; 14 private Map classMap = Collections.synchronizedMap(new HashMap ()); 15 16 public CommandFinder(String path) { 17 this.path = path; 18 } 19 20 public Properties doFindCommandProperies(String key) throws IOException { 21 String uri = path + key; 22 23 InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri); 25 if (in == null) { 26 in = CommandFinder.class.getClassLoader().getResourceAsStream(uri); 27 if (in == null) { 28 throw new IOException ("Could not find command in : " + uri); 29 } 30 } 31 32 BufferedInputStream reader = null; 34 try { 35 reader = new BufferedInputStream (in); 36 Properties properties = new Properties (); 37 properties.load(reader); 38 39 return properties; 40 } finally { 41 try { 42 reader.close(); 43 } catch (Exception e) { 44 } 45 } 46 } 47 48 public Enumeration doFindCommands() throws IOException { 49 return Thread.currentThread().getContextClassLoader().getResources(path); 50 } 51 } | Popular Tags |