public < T extends IComponent > T createAndRegisterComponent ( Class < T > componentType ) throws ComponentNotFoundException { try { synchronized ( components ) { Class < ? extends T > componentClass = engineConfig . getComponentClass ( componentType , pluginRegistry ) ; Map < String , String > componentConfig = engineConfig . getComponentConfig ( componentType ) ; T component = create ( componentClass , componentConfig ) ; components . put ( componentType , component ) ; // Because components are lazily created, we need to initialize them here // if necessary. DependsOnComponents annotation = componentClass . getAnnotation ( DependsOnComponents . class ) ; if ( annotation != null ) { Class < ? extends IComponent > [ ] value = annotation . value ( ) ; for ( Class < ? extends IComponent > theC : value ) { Method setter = ReflectionUtils . findSetter ( componentClass , theC ) ; if ( setter != null ) { IComponent injectedComponent = getComponent ( theC ) ; try { setter . invoke ( component , new Object [ ] { injectedComponent } ) ; } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { throw new RuntimeException ( e ) ; } } } } if ( component instanceof IRequiresInitialization ) { ( ( IRequiresInitialization ) component ) . initialize ( ) ; } return component ; } } catch ( Exception e ) { throw new ComponentNotFoundException ( componentType . getName ( ) ) ; } }
Creates the component and registers it in the registry .