use of com.google.gwt.inject.client.GinModule in project gwt-test-utils by gwt-test-utils.
the class GInjectorCreateHandler method readGinModules.
private Class<? extends GinModule>[] readGinModules(Class<? extends Ginjector> classLiteral) {
LOGGER.debug("inspecting classLiteral " + classLiteral);
GinModules annotation = classLiteral.getAnnotation(GinModules.class);
if (annotation == null) {
// Throw an exception if we don't find this specific annotation.
throw new IllegalArgumentException(classLiteral.getName() + " doesn't have any @GinModules annotation present");
}
Class<? extends GinModule>[] ginModules = annotation.value();
if (ginModules == null || ginModules.length == 0) {
// there are no GinModules present in the Ginjector.
throw new IllegalArgumentException(classLiteral.getName() + " doesn't have any GinModules. " + "Runtime should not work.");
}
LOGGER.debug("discovered modules " + annotation);
return ginModules;
}
use of com.google.gwt.inject.client.GinModule in project gwt-test-utils by gwt-test-utils.
the class GInjectorCreateHandler method create.
public Object create(Class<?> classLiteral) throws Exception {
// Make sure this is a Ginjector
if (!Ginjector.class.isAssignableFrom(classLiteral)) {
return null;
}
@SuppressWarnings("unchecked") Class<? extends Ginjector> ginjectorClass = (Class<? extends Ginjector>) classLiteral;
if (injectors == null) {
injectors = new HashMap<Class<? extends Ginjector>, Object>();
}
Object guiceInjectorProxy = injectors.get(classLiteral);
if (guiceInjectorProxy != null) {
LOGGER.debug("Proxy for class '" + ginjectorClass.getName() + "'has been found in cache. It is returned");
return guiceInjectorProxy;
}
Class<? extends GinModule>[] ginModules = readGinModules(ginjectorClass);
// create a set of Guice Module bases on the GinModules
Set<Module> guiceModules = readGuiceModules(ginModules, ginjectorClass);
// Use Guice SPI to solve deferred binding dependencies
DeferredBindingModule deferredBindingModule = DeferredBindingModule.getDeferredBindingModule(ginjectorClass, guiceModules);
guiceModules.add(deferredBindingModule);
// Instantiate an injector, based on the modules read above + the
// deferredBindingModule
Injector injector = Guice.createInjector(guiceModules);
LOGGER.debug("creating new Proxy for class '" + ginjectorClass.getName() + "'");
guiceInjectorProxy = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { ginjectorClass }, new GinInjectorInvocationHandler(injector));
injectors.put(ginjectorClass, guiceInjectorProxy);
return guiceInjectorProxy;
}
use of com.google.gwt.inject.client.GinModule in project google-gin by gwtplus.
the class GinjectorGenerator method getPropertyModuleClasses.
// We check that the class is a GinModule before casting it.
@SuppressWarnings("unchecked")
private void getPropertyModuleClasses(Class<?> ginjectorType, Set<Class<? extends GinModule>> ginModules) throws UnableToCompleteException {
Set<String> propertyModuleNames = getPropertyModuleNames(ginjectorType);
for (String moduleName : propertyModuleNames) {
try {
// Gin modules must be initialized when loading since we will instantiate it. It is
// officially illegal to call any GWT-client code in a Gin module.
Class<?> ginModule = loadClass(moduleName, true);
if (!GinModule.class.isAssignableFrom(ginModule)) {
logger.log(TreeLogger.Type.ERROR, String.format("The gin module type [%s] does not " + "inherit from GinModule.", moduleName));
throw new UnableToCompleteException();
}
ginModules.add((Class<? extends GinModule>) ginModule);
} catch (ClassNotFoundException e) {
logger.log(TreeLogger.ERROR, String.format("Unable to load gin module type [%s], " + "maybe you haven't compiled your client java sources?", moduleName), e);
throw new UnableToCompleteException();
}
}
}
use of com.google.gwt.inject.client.GinModule in project gwt-test-utils by gwt-test-utils.
the class GInjectorCreateHandler method readGuiceModules.
private Set<Module> readGuiceModules(Class<? extends GinModule>[] classLiterals, Class<? extends Ginjector> ginectorClass) throws Exception {
Set<Module> modules = new HashSet<Module>();
for (Class<? extends GinModule> literal : classLiterals) {
LOGGER.debug("wrapping GinModule literal " + literal);
MemberCollector memberCollector = new MemberCollector(GwtTreeLogger.get());
GuiceUtil guiceUtil = new GuiceUtil(memberCollector);
modules.add(new GinModuleAdapter(literal.newInstance(), new GinjectorBindings(null, GwtTreeLogger.get(), guiceUtil, ginectorClass, null, memberCollector, null, null)));
}
return modules;
}
use of com.google.gwt.inject.client.GinModule in project google-gin by gwtplus.
the class BinderAdapter method install.
public void install(GinModule install) {
// Filtering out fake factory modules.
if (install instanceof FactoryModule) {
if (bindings != null) {
bindings.addFactoryModule((FactoryModule<?>) install);
}
} else {
// Here we need to take care to ensure that PrivateGinModule uses the appropriate
// type of adapter, and also get the corresponding Guice private binder.
final Module moduleAdapter;
if (install == null) {
moduleAdapter = null;
} else if (install instanceof PrivateGinModule) {
moduleAdapter = new PrivateGinModuleAdapter((PrivateGinModule) install, bindings);
} else {
moduleAdapter = new GinModuleAdapter(install, bindings);
}
binder.install(moduleAdapter);
}
}
Aggregations