1 16 package org.directwebremoting.create; 17 18 import java.lang.reflect.Method ; 19 20 import org.directwebremoting.extend.Creator; 21 import org.directwebremoting.util.LocalUtil; 22 import org.directwebremoting.util.Messages; 23 24 33 public class SingletonCreator extends AbstractCreator implements Creator 34 { 35 39 public void setClass(String classname) 40 { 41 try 42 { 43 clazz = LocalUtil.classForName(classname); 44 System.out.println(clazz.getName()); 45 } 46 catch (ClassNotFoundException ex) 47 { 48 throw new IllegalArgumentException (Messages.getString("Creator.ClassNotFound", classname)); } 50 } 51 52 55 public Object getInstance() throws InstantiationException  56 { 57 try 58 { 59 Method method = clazz.getMethod(factoryMethod, null); 60 return method.invoke(new SingletonCreator(), null); 61 } 62 catch (Exception ex) 63 { 64 throw new InstantiationException (Messages.getString("Creator.IllegalAccess")); 66 } 67 } 68 69 72 public Class getType() 73 { 74 return clazz; 75 } 76 77 80 public String getFactoryMethod() 81 { 82 return factoryMethod; 83 } 84 85 88 public void setFactoryMethod(String functionToCall) 89 { 90 this.factoryMethod = functionToCall; 91 } 92 93 98 private String factoryMethod = "getInstance"; 99 100 103 private Class clazz; 104 } 105
| Popular Tags
|