1 7 package scioworks.imap.spec.beans; 8 9 import java.lang.reflect.Constructor ; 10 11 public class FileRecordFactory { 12 13 14 17 private FileRecordFactory() { 18 } 19 20 23 public static FileRecord getFileRecord(String fullClassName,String tmpFilename,String filename,int size,String contentType) { 24 25 FileRecord result = null; 26 27 Class objectClass = null; 28 29 try { 30 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.getConstructor(parameterTypes); 43 44 45 46 Object [] objects = new Object [4]; 47 objects[0]=tmpFilename; 48 objects[1]=filename; 49 objects[2]=new Integer (size); 50 objects[3]=contentType; 51 52 Object obj = constr.newInstance(objects); 53 54 return (FileRecord)obj; 55 56 57 } catch (Exception ex) { 58 System.out.println("Error on creating the object" + ex); 59 } 60 61 return result; 62 } 63 } | Popular Tags |