From 43ef9e45b428f76d976eb99bcfe26880af0e6c56 Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Thu, 27 Mar 2003 04:07:42 +0000 Subject: [PATCH] Rewrote create method to use Reflection. The primary purpose is to "simplify" building native executables. --- .../filters/imagehandlers/AppleImage.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/filters/imagehandlers/AppleImage.java b/src/com/webcodepro/applecommander/storage/filters/imagehandlers/AppleImage.java index 236b982..09638e1 100644 --- a/src/com/webcodepro/applecommander/storage/filters/imagehandlers/AppleImage.java +++ b/src/com/webcodepro/applecommander/storage/filters/imagehandlers/AppleImage.java @@ -21,6 +21,7 @@ package com.webcodepro.applecommander.storage.filters.imagehandlers; import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.Constructor; /** * AppleImage is an abstract class that represents a generic interface @@ -42,20 +43,31 @@ public abstract class AppleImage { */ private String[] availableExtensions; /** - * Create a specific instance of AppleImage. + * Create a specific instance of AppleImage. This has been coded + * using Reflection to ease native compilation for the most part. */ public static AppleImage create(int width, int height) { - try { - return new ImageIoImage(width, height); - } catch (ClassNotFoundException ignored) { - } - try { - return new SunJpegImage(width, height); - } catch (ClassNotFoundException ignored) { - } - try { - return new SwtImage(width, height); - } catch (ClassNotFoundException ignored) { + String[] classes = { + "ImageIoImage", "SunJpegImage", "SwtImage" }; + Class[] constructorArgClasses = new Class[] { + int.class, int.class }; + Object[] constructorArgs = new Object[] { + new Integer(width), new Integer(height) }; + for (int i=0; i