Search in sources :

Example 1 with InjectService

use of com.mvp4g.client.annotation.InjectService 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()));
        }
    }
}
Also used : InjectedElement(com.mvp4g.rebind.config.element.InjectedElement) JParameter(com.google.gwt.core.ext.typeinfo.JParameter) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException) Mvp4gWithServicesElement(com.mvp4g.rebind.config.element.Mvp4gWithServicesElement) JMethod(com.google.gwt.core.ext.typeinfo.JMethod) InjectService(com.mvp4g.client.annotation.InjectService)

Aggregations

JMethod (com.google.gwt.core.ext.typeinfo.JMethod)1 JParameter (com.google.gwt.core.ext.typeinfo.JParameter)1 InjectService (com.mvp4g.client.annotation.InjectService)1 InjectedElement (com.mvp4g.rebind.config.element.InjectedElement)1 Mvp4gWithServicesElement (com.mvp4g.rebind.config.element.Mvp4gWithServicesElement)1 Mvp4gAnnotationException (com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException)1