1 11 package org.eclipse.osgi.framework.internal.core; 12 13 import java.io.*; 14 import java.util.Hashtable ; 15 import java.util.Vector ; 16 import org.eclipse.osgi.framework.debug.Debug; 17 18 21 public class AliasMapper { 22 private static Hashtable processorAliasTable; 23 private static Hashtable osnameAliasTable; 24 25 29 public AliasMapper() { 30 } 31 32 38 public String aliasProcessor(String processor) { 39 processor = processor.toLowerCase(); 40 if (processorAliasTable == null) { 41 InputStream in = getClass().getResourceAsStream(Constants.OSGI_PROCESSOR_ALIASES); 42 if (in != null) { 43 try { 44 processorAliasTable = initAliases(in); 45 } finally { 46 try { 47 in.close(); 48 } catch (IOException ee) { 49 } 50 } 51 } 52 } 53 if (processorAliasTable != null) { 54 String alias = (String ) processorAliasTable.get(processor); 55 if (alias != null) { 56 processor = alias; 57 } 58 } 59 return (processor); 60 } 61 62 68 public Object aliasOSName(String osname) { 69 osname = osname.toLowerCase(); 70 if (osnameAliasTable == null) { 71 InputStream in = getClass().getResourceAsStream(Constants.OSGI_OSNAME_ALIASES); 72 if (in != null) { 73 try { 74 osnameAliasTable = initAliases(in); 75 } finally { 76 try { 77 in.close(); 78 } catch (IOException ee) { 79 } 80 } 81 } 82 } 83 if (osnameAliasTable != null) { 84 Object aliasObject = osnameAliasTable.get(osname); 85 if (aliasObject != null) 87 if (aliasObject instanceof String ) { 88 osname = (String ) aliasObject; 89 } else { 90 return (Vector ) aliasObject; 91 } 92 } 93 return (osname); 94 } 95 96 102 protected static Hashtable initAliases(InputStream in) { 103 Hashtable aliases = new Hashtable (37); 104 try { 105 BufferedReader br; 106 try { 107 br = new BufferedReader(new InputStreamReader(in, "UTF8")); } catch (UnsupportedEncodingException e) { 109 br = new BufferedReader(new InputStreamReader(in)); 110 } 111 while (true) { 112 String line = br.readLine(); 113 if (line == null) { 114 break; 115 } 116 Tokenizer tokenizer = new Tokenizer(line); 117 String master = tokenizer.getString("# \t"); if (master != null) { 119 aliases.put(master.toLowerCase(), master); 120 parseloop: while (true) { 121 String alias = tokenizer.getString("# \t"); if (alias == null) { 123 break parseloop; 124 } 125 String lowerCaseAlias = alias.toLowerCase(); 126 Object storedMaster = aliases.get(lowerCaseAlias); 127 if (storedMaster == null) { 128 aliases.put(lowerCaseAlias, master); 129 } else if (storedMaster instanceof String ) { 130 Vector newMaster = new Vector (); 131 newMaster.add(storedMaster); 132 newMaster.add(master); 133 aliases.put(lowerCaseAlias, newMaster); 134 } else { 135 ((Vector ) storedMaster).add(master); 136 aliases.put(lowerCaseAlias, storedMaster); 137 } 138 } 139 } 140 } 141 } catch (IOException e) { 142 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 143 Debug.printStackTrace(e); 144 } 145 } 146 return (aliases); 147 } 148 } 149 | Popular Tags |