use of com.mvp4g.rebind.config.element.Mvp4gWithServicesElement in project mvp4g by mvp4g.
the class AbstractMvp4gAnnotationsWithServiceLoaderTest method testServicesWithName.
@Test
public void testServicesWithName() throws Mvp4gAnnotationException {
List<JClassType> annotedClasses = new ArrayList<JClassType>();
JClassType type = oracle.addClass(getServiceWithName());
annotedClasses.add(type);
loader.load(annotedClasses, configuration);
Set<Mvp4gWithServicesElement> elements = getSet();
List<InjectedElement> injectedServices = elements.iterator().next().getInjectedServices();
InjectedElement injectedService = injectedServices.get(0);
assertEquals(injectedServices.size(), 1);
assertEquals(injectedService.getSetterName(), "setSthg");
assertEquals(injectedService.getElementName(), "name");
assertEquals(configuration.getServices().size(), 0);
}
use of com.mvp4g.rebind.config.element.Mvp4gWithServicesElement in project mvp4g by mvp4g.
the class AbstractMvp4gAnnotationsWithServiceLoaderTest method testServices.
@Test
public void testServices() throws Mvp4gAnnotationException {
List<JClassType> annotedClasses = new ArrayList<JClassType>();
JClassType type = oracle.addClass(getService());
annotedClasses.add(type);
loader.load(annotedClasses, configuration);
Set<Mvp4gWithServicesElement> elements = getSet();
String serviceClass = SimpleService.class.getCanonicalName();
String serviceName = serviceClass.replace('.', '_');
List<InjectedElement> injectedServices = elements.iterator().next().getInjectedServices();
InjectedElement injectedService = injectedServices.get(0);
assertEquals(injectedServices.size(), 1);
assertEquals(injectedService.getSetterName(), "setSthg");
assertEquals(injectedService.getElementName(), serviceName + "Async");
Set<ServiceElement> services = configuration.getServices();
assertEquals(services.size(), 1);
ServiceElement service = services.iterator().next();
assertEquals(service.getName(), serviceName + "Async");
assertEquals(service.getClassName(), serviceClass);
annotedClasses.clear();
type = oracle.addClass(getSameService());
annotedClasses.add(type);
loader.load(annotedClasses, configuration);
assertEquals(services.size(), 1);
ServiceElement service2 = services.iterator().next();
assertSame(service, service2);
}
use of com.mvp4g.rebind.config.element.Mvp4gWithServicesElement in project mvp4g by mvp4g.
the class Mvp4gAnnotationsWithServiceLoader method loadElement.
/*
* (non-Javadoc)
*
* @see com.mvp4g.rebind.config.loader.annotation.Mvp4gAnnotationsLoader#loadElement
* (com.google.gwt .core.ext.typeinfo.JClassType, java.lang.annotation.Annotation,
* com.mvp4g.rebind.config.Mvp4gConfiguration)
*/
@Override
protected void loadElement(JClassType c, T annotation, Mvp4gConfiguration configuration) throws Mvp4gAnnotationException {
Mvp4gWithServicesElement element = loadElementWithServices(c, annotation, configuration);
// check if any services need to be injected
JParameter[] params = null;
String className = null;
String serviceName = null;
InjectService serviceAnnotation = null;
for (JMethod m : c.getOverridableMethods()) {
serviceAnnotation = m.getAnnotation(InjectService.class);
if (serviceAnnotation != null) {
if (!m.isPublic()) {
String err = "Only public setter method can be used to inject a service.";
throw new Mvp4gAnnotationException(c.getQualifiedSourceName(), m.getName(), err);
}
params = m.getParameters();
if (params.length != 1) {
String err = "Only setter method with one parameter can be used to inject a service";
throw new Mvp4gAnnotationException(c.getQualifiedSourceName(), m.getName(), err);
}
serviceName = serviceAnnotation.serviceName();
if ((serviceName == null) || (serviceName.length() == 0)) {
className = params[0].getType().getQualifiedSourceName();
serviceName = getServiceName(configuration, className);
}
element.getInjectedServices().add(new InjectedElement(serviceName, m.getName()));
}
}
}
Aggregations