public void addComponentDescriptor( ComponentDescriptor<?> componentDescriptor ) throws CycleDetectedInComponentGraphException { repository.addComponentDescriptor( componentDescriptor ); }
public <T> ComponentDescriptor<T> getComponentDescriptor( Class<T> type, String role, String roleHint ) { return repository.getComponentDescriptor( type, role, roleHint ); }
public <T> Map<String, ComponentDescriptor<T>> getComponentDescriptorMap( Class<T> type, String role ) { return repository.getComponentDescriptorMap( type, role ); }
public void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentRepository componentRepository = context.getContainerConfiguration().getComponentRepository(); componentRepository.configure( context.getContainerXmlConfiguration() ); componentRepository.setClassRealm( context.getContainer().getContainerRealm() ); try { componentRepository.initialize(); } catch ( ComponentRepositoryException e ) { throw new ContainerInitializationException( "Error initializing component repository.", e ); } context.getContainer().setComponentRepository( componentRepository ); } }
public void removeComponentRealm( ClassRealm classRealm ) throws PlexusContainerException repository.removeComponentRealm( classRealm );
public boolean hasComponent( String role, String roleHint, ClassRealm realm ) { return componentRepository.hasComponent( role, roleHint, realm ); }
public <T> List<ComponentDescriptor<T>> getComponentDescriptorList( Class<T> type, String role ) { return repository.getComponentDescriptorList( type, role ); }
public void removeComponentRealm( ClassRealm realm ) throws PlexusContainerException { if ( getContainerRealm().getId().equals( realm.getId() ) ) { throw new IllegalArgumentException( "Cannot remove container realm: " + realm.getId() + "\n(trying to remove container realm as if it were a component realm)." ); } componentRepository.removeComponentRealm( realm ); try { componentManagerManager.dissociateComponentRealm( realm ); } catch ( ComponentLifecycleException e ) { throw new PlexusContainerException( "Failed to dissociate component realm: " + realm.getId(), e ); } ClassRealm lookupRealm = getLookupRealm(); if ( ( lookupRealm != null ) && lookupRealm.getId().equals( realm.getId() ) ) { setLookupRealm( getContainerRealm() ); } }
public boolean hasComponent( String componentKey, ClassRealm realm ) { return componentRepository.hasComponent( componentKey, realm ); }
@Deprecated public ComponentDescriptor<?> getComponentDescriptor( String role, String roleHint, ClassRealm realm ) { return repository.getComponentDescriptor( role, roleHint, realm ); }
public void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws ComponentRepositoryException { componentRepository.addComponentDescriptor( componentDescriptor ); }
public Map getComponentDescriptorMap( String role, ClassRealm realm ) { Map result = new WeakHashMap(); if ( parentContainer != null ) { Map m = parentContainer.getComponentDescriptorMap( role, realm ); if ( m != null ) { result.putAll( m ); } } Map componentDescriptors = componentRepository.getComponentDescriptorMap( role, realm ); if ( componentDescriptors != null ) { result.putAll( componentDescriptors ); } return result; }
public ComponentDescriptor getComponentDescriptor( String role, String hint, ClassRealm classRealm ) { ComponentDescriptor result = componentRepository.getComponentDescriptor( role, hint, classRealm ); ClassRealm tmpRealm = classRealm.getParentRealm(); while ( ( result == null ) && ( tmpRealm != null ) ) { result = componentRepository.getComponentDescriptor( role, hint, classRealm ); tmpRealm = tmpRealm.getParentRealm(); } if ( ( result == null ) && ( parentContainer != null ) ) { result = parentContainer.getComponentDescriptor( role, hint, classRealm ); } return result; }
private ComponentRepository getComponentRepository( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentRepository repository = context.getContainerConfiguration().getComponentRepository(); // Add the components defined in the container xml configuration try { PlexusConfiguration configuration = context.getContainerXmlConfiguration(); PlexusConfiguration[] componentConfigurations = configuration.getChild( "components" ).getChildren( "component" ); for ( PlexusConfiguration componentConfiguration : componentConfigurations ) { ComponentDescriptor<?> componentDescriptor = PlexusTools.buildComponentDescriptor( componentConfiguration, context.getContainer().getContainerRealm() ); componentDescriptor.setRealm( context.getContainer().getContainerRealm() ); repository.addComponentDescriptor( componentDescriptor ); } } catch ( PlexusConfigurationException e ) { throw new ContainerInitializationException( "Error initializing component repository: " + "Cannot unmarshall component descriptor: ", e ); } catch ( CycleDetectedInComponentGraphException e ) { throw new ContainerInitializationException( "A cycle has been detected in the components of the system: ", e ); } return repository; }
public boolean canCreate(Type expectedType) { if (!autoMatch) { return true; } ClassRealm realm = (ClassRealm) Thread.currentThread().getContextClassLoader(); Class propertyType = toClass(expectedType); // Never auto match array, map or collection if (propertyType.isArray() || Map.class.isAssignableFrom(propertyType) || Collection.class.isAssignableFrom(propertyType) || requirement instanceof ComponentRequirementList) { return false; } // if the type to be created is an instance of the expceted type, return true try { ComponentDescriptor descriptor = ((MutablePlexusContainer) container).getComponentRepository().getComponentDescriptor(requirement.getRole(), requirement.getRoleHint(), realm); String typeName = descriptor.getImplementation(); Class actualClass = realm.loadClass(typeName); if (RecipeHelper.isAssignable(expectedType, actualClass)) { return true; } } catch (Exception e) { } return false; }
ComponentDescriptor descriptor = container.getComponentRepository().getComponentDescriptor( componentRole, roleHint, realm );