1 11 package org.eclipse.core.runtime.adaptor; 12 13 import java.util.*; 14 import org.eclipse.osgi.service.environment.Constants; 15 16 19 public class EnvironmentInfo implements org.eclipse.osgi.service.environment.EnvironmentInfo { 20 private static EnvironmentInfo singleton; 21 private static String nl; 22 private static String os; 23 private static String ws; 24 private static String arch; 25 static String [] allArgs; 26 static String [] frameworkArgs; 27 static String [] appArgs; 28 29 private static final String INTERNAL_OS_SUNOS = "SunOS"; private static final String INTERNAL_ARCH_I386 = "i386"; 36 private EnvironmentInfo() { 37 super(); 38 setupSystemContext(); 39 } 40 41 public static EnvironmentInfo getDefault() { 42 if (singleton == null) 43 singleton = new EnvironmentInfo(); 44 return singleton; 45 } 46 47 public boolean inDevelopmentMode() { 48 return System.getProperty("osgi.dev") != null; } 50 51 public boolean inDebugMode() { 52 return System.getProperty("osgi.debug") != null; } 54 55 public String [] getCommandLineArgs() { 56 return allArgs; 57 } 58 59 public String [] getFrameworkArgs() { 60 return frameworkArgs; 61 } 62 63 public String [] getNonFrameworkArgs() { 64 return appArgs; 65 } 66 67 public String getOSArch() { 68 return arch; 69 } 70 71 public String getNL() { 72 return nl; 73 } 74 75 public String getOS() { 76 return os; 77 } 78 79 public String getWS() { 80 return ws; 81 } 82 83 91 private void setupSystemContext() { 92 nl = System.getProperty("osgi.nl"); if (nl != null) { 96 StringTokenizer tokenizer = new StringTokenizer(nl, "_"); int segments = tokenizer.countTokens(); 98 try { 99 Locale userLocale = null; 100 switch (segments) { 101 case 1: 102 userLocale = new Locale(tokenizer.nextToken(), ""); break; 105 case 2: 106 userLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken()); 107 break; 108 case 3: 109 userLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken()); 110 break; 111 default: 112 System.err.println(EclipseAdaptorMsg.formatter.getString("error.badNL", nl)); userLocale = Locale.getDefault(); 115 break; 116 } 117 Locale.setDefault(userLocale); 118 } catch (NoSuchElementException e) { 119 } 121 } 122 nl = Locale.getDefault().toString(); 123 System.getProperties().put("osgi.nl", nl); 125 os = System.getProperty("osgi.os"); if (os == null) { 129 String name = System.getProperty("os.name"); if (name.regionMatches(true, 0, Constants.OS_WIN32, 0, 3)) 133 os = Constants.OS_WIN32; 134 if (os == null) 136 os = name.equalsIgnoreCase(INTERNAL_OS_SUNOS) ? Constants.OS_SOLARIS : Constants.OS_UNKNOWN; 137 } 138 System.getProperties().put("osgi.os", os); 140 ws = System.getProperty("osgi.ws"); if (ws == null) { 144 if (os.equals(Constants.OS_WIN32)) 146 ws = Constants.WS_WIN32; 147 else if (os.equals(Constants.OS_LINUX)) 148 ws = Constants.WS_MOTIF; 149 else if (os.equals(Constants.OS_MACOSX)) 150 ws = Constants.WS_CARBON; 151 else if (os.equals(Constants.OS_HPUX)) 152 ws = Constants.WS_MOTIF; 153 else if (os.equals(Constants.OS_AIX)) 154 ws = Constants.WS_MOTIF; 155 else if (os.equals(Constants.OS_SOLARIS)) 156 ws = Constants.WS_MOTIF; 157 else 158 ws = Constants.WS_UNKNOWN; 159 } 160 System.getProperties().put("osgi.ws", ws); 162 arch = System.getProperty("osgi.arch"); if (arch == null) { 166 String name = System.getProperty("os.arch"); arch = name.equalsIgnoreCase(INTERNAL_ARCH_I386) ? Constants.ARCH_X86 : name; 169 } 170 System.getProperties().put("osgi.arch", arch); } 172 173 } | Popular Tags |