private void addNewKeyToComponent ( String key , Component component ) throws ProviderConflictException { Component root = getRootComponent ( ) ; if ( componentLocator . keySet ( ) . contains ( key ) ) { String msg = String . format ( "Type %s has already been registered " + "in this component(%s)." , key , getComponentId ( ) ) ; throw new ProviderConflictException ( msg ) ; } if ( root != this && root . componentLocator . keySet ( ) . contains ( key ) ) { String msg = String . format ( "\nClass type %s cannot be registered to component(%s)\nsince it's " + "already been registered in its root component(%s).\n\nYou can prepare a child " + "component and register providers to it first. Then attach the child component\nto the " + "component tree with allowOverridden flag set true" , key , getComponentId ( ) , getRootComponent ( ) . getComponentId ( ) ) ; throw new ProviderConflictException ( msg ) ; } //Only put it to root component's locator root . componentLocator . put ( key , component ) ; }
Add key to the component locator of the component . This component and the the component tree root s component locator will both be updated .