Moved creation of integrations to Platform.

This commit is contained in:
Adam Murdoch
2012-08-12 07:45:10 +10:00
parent 97038bbf6e
commit 2e5f9cb546
2 changed files with 50 additions and 44 deletions

View File

@@ -59,40 +59,11 @@ public class Native {
static <T extends NativeIntegration> T get(Class<T> type) {
init(null);
Platform platform = Platform.current();
if (platform.isPosix()) {
if (type.equals(PosixFile.class)) {
return type.cast(new DefaultPosixFile());
}
if (type.equals(Process.class)) {
return type.cast(new DefaultProcess());
}
if (type.equals(TerminalAccess.class)) {
return type.cast(new TerminfoTerminalAccess());
}
if (type.equals(SystemInfo.class)) {
MutableSystemInfo systemInfo = new MutableSystemInfo();
FunctionResult result = new FunctionResult();
NativeLibraryFunctions.getSystemInfo(systemInfo, result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not fetch system information: %s",
result.getMessage()));
}
System.out.println("=> CHARACTER ENCODING: " + systemInfo.characterEncoding);
return type.cast(systemInfo);
}
} else if (platform.isWindows()) {
if (type.equals(Process.class)) {
return type.cast(new DefaultProcess());
}
if (type.equals(TerminalAccess.class)) {
return type.cast(new WindowsTerminalAccess());
}
}
if (platform.isOsX()) {
if (type.equals(FileSystems.class)) {
return type.cast(new PosixFileSystems());
}
T integration = platform.get(type);
if (integration != null) {
return integration;
}
throw new UnsupportedOperationException(String.format("Cannot load unsupported native integration %s.",
type.getName()));
}