01: /*
02: * imapWeb
03: *
04: * Enhydra super-servlet specification object
05: *
06: */
07: package scioworks.imap.spec.beans;
08:
09: import java.lang.reflect.Constructor;
10:
11: public class FileRecordFactory {
12:
13: /**
14: * Constructor can't be used.
15: */
16: private FileRecordFactory() {
17: }
18:
19: /**
20: * Create a FileRecord as state object/value object/data transfer object
21: */
22: public static FileRecord getFileRecord(String fullClassName,
23: String tmpFilename, String filename, int size,
24: String contentType) {
25:
26: FileRecord result = null;
27:
28: Class objectClass = null;
29:
30: try {
31: // Create the value object
32:
33: objectClass = Class.forName(fullClassName);
34:
35: Class[] parameterTypes = new Class[4];
36:
37: parameterTypes[0] = String.class;
38: parameterTypes[1] = String.class;
39: parameterTypes[2] = int.class;
40: parameterTypes[3] = String.class;
41:
42: Constructor constr = objectClass
43: .getConstructor(parameterTypes);
44:
45: Object[] objects = new Object[4];
46: objects[0] = tmpFilename;
47: objects[1] = filename;
48: objects[2] = new Integer(size);
49: objects[3] = contentType;
50:
51: Object obj = constr.newInstance(objects);
52:
53: return (FileRecord) obj;
54:
55: } catch (Exception ex) {
56: System.out.println("Error on creating the object" + ex);
57: }
58:
59: return result;
60: }
61: }
|