private <R extends Service> void applyInjections(R service) { try { for ( Method method : service.getClass().getMethods() ) { InjectService injectService = method.getAnnotation( InjectService.class ); if ( injectService == null ) { continue; } processInjection( service, method, injectService ); } } catch (NullPointerException e) { log.error( "NPE injecting service deps : " + service.getClass().getName() ); } }
@SuppressWarnings({ "unchecked" }) private <T extends Service> void processInjection(T service, Method injectionMethod, InjectService injectService) { if ( injectionMethod.getParameterTypes() == null || injectionMethod.getParameterTypes().length != 1 ) { throw new ServiceDependencyException( "Encountered @InjectService on method with unexpected number of parameters" ); } Class dependentServiceRole = injectService.serviceRole(); if ( dependentServiceRole == null || dependentServiceRole.equals( Void.class ) ) { dependentServiceRole = injectionMethod.getParameterTypes()[0]; } // todo : because of the use of proxies, this is no longer returning null here... final Service dependantService = getService( dependentServiceRole ); if ( dependantService == null ) { if ( injectService.required() ) { throw new ServiceDependencyException( "Dependency [" + dependentServiceRole + "] declared by service [" + service + "] not found" ); } } else { try { injectionMethod.invoke( service, dependantService ); } catch ( Exception e ) { throw new ServiceDependencyException( "Cannot inject dependency service", e ); } } }
@InjectService( required = false ) @SuppressWarnings("UnusedDeclaration") public void setJndiService(JndiService jndiService) { this.jndiService = jndiService; }
/** * Hook for service registry to be able to inject JdbcServices * * @param jdbcServices The JdbcServices service */ @InjectService @SuppressWarnings("UnusedDeclaration") public void injectJdbcServices(JdbcServices jdbcServices) { this.jdbcServices = jdbcServices; }
@InjectService @Override public void setEntityManagerFactory(EntityManagerFactoryRef entityManagerFactoryRef) { this.entityManagerFactory = entityManagerFactoryRef.getEntityManagerFactory(); }
@InjectService @Override public void setMetadata(MetadataRef metadataRef) { this.metadata = metadataRef.getMetadata(); }
@InjectService @Override public void setSearchIntegrator(SearchFactoryReference searchFactoryRef) { this.searchIntegrator = searchFactoryRef.getSearchIntegrator(); }