1 16 package org.directwebremoting.guice; 17 18 import com.google.inject.Injector; 19 20 import org.directwebremoting.extend.Creator; 21 import org.directwebremoting.create.NewCreator; 22 23 import static org.directwebremoting.guice.DwrGuiceUtil.getInjector; 24 25 29 public class GuiceCreator extends NewCreator implements Creator { 30 31 public GuiceCreator() 32 { 33 this.injector = getInjector(); 34 } 35 36 37 41 @Override public void setClass(String classname) 42 { 43 try 44 { 45 this.type = Class.forName(classname); 49 } 50 catch (ClassNotFoundException ex) 51 { 52 throw new IllegalArgumentException (String.format( 53 "GuiceCreator: class %s not found", classname)); 54 } 55 } 56 57 60 @Override public Class getType() 61 { 62 return type; 63 } 64 65 69 @Override public Object getInstance() 70 { 71 return injector.getInstance(type); 72 } 73 74 75 78 private volatile Class type; 79 80 83 private final Injector injector; 84 } 85 | Popular Tags |