public <T> ComponentDescriptor<T> getComponentDescriptor( Class<T> type, String role, String roleHint ) { return repository.getComponentDescriptor( type, role, roleHint ); }
@Deprecated public ComponentDescriptor<?> getComponentDescriptor( String role, String roleHint, ClassRealm realm ) { return repository.getComponentDescriptor( role, roleHint, realm ); }
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; }
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 );