Media helper to modularize the invocation and getting of handlers. all the reflection...
authormh <mh>
Thu, 7 Feb 2002 10:04:02 +0000 (10:04 +0000)
committermh <mh>
Thu, 7 Feb 2002 10:04:02 +0000 (10:04 +0000)
source/mir/media/MediaHelper.java [new file with mode: 0755]

diff --git a/source/mir/media/MediaHelper.java b/source/mir/media/MediaHelper.java
new file mode 100755 (executable)
index 0000000..a9d3127
--- /dev/null
@@ -0,0 +1,52 @@
+package mir.media;
+
+import java.lang.reflect.*;
+import java.lang.*;
+
+import mir.entity.Entity;
+import mir.storage.Database;
+
+/**
+ * helper class to resolve media handlers using reflection
+ *
+ * @author mh
+ * @version 2002
+ */
+
+public final class MediaHelper {
+  static String _classPrefix = "mir.media.MediaHandler";
+
+  public static MirMedia getHandler( Entity mediaType )
+    throws MirMediaException {
+
+    MirMedia mediaHandler;
+    String handlerName = mediaType.getValue("classname");
+    try {
+      Class handlerClass = Class.forName(_classPrefix+handlerName);
+      return mediaHandler = (MirMedia)handlerClass.newInstance();
+    } catch (Exception e) {
+      throw new MirMediaException ("getHandler -- error in reflection "
+                                    +e.toString());
+    }
+  } 
+
+  public static Database getStorage(Entity mediaType, String classPrefix)
+    throws MirMediaException {
+
+    Database mediaStorage;
+    String storageName =  mediaType.getValue("tablename");
+    try {
+      Class storageClass = Class.forName(classPrefix+storageName);
+      Method m = storageClass.getMethod("getInstance", null);
+      return mediaStorage = (Database)m.invoke(null, null);
+    } catch (Exception e) {
+      throw new MirMediaException ("getStorage -- error in reflection "
+                                    +e.toString());
+    }
+  }
+
+}
+
+    
+