/** * {@inheritDoc} * * @see org.xwiki.component.manager.ComponentManager#lookup(Class) */ @SuppressWarnings("unchecked") public <T> T lookup(Class<T> role) throws ComponentLookupException { T result; try { result = (T) this.plexusContainer.lookup(role.getName()); } catch (org.codehaus.plexus.component.repository.exception.ComponentLookupException e) { throw new ComponentLookupException("Failed to lookup component role [" + role + "]", e); } return result; }
/** * {@inheritDoc} * * @see org.xwiki.component.manager.ComponentManager#lookup(Class, String) */ @SuppressWarnings("unchecked") public <T> T lookup(Class<T> role, String roleHint) throws ComponentLookupException { T result; try { result = (T) this.plexusContainer.lookup(role.getName(), roleHint); } catch (org.codehaus.plexus.component.repository.exception.ComponentLookupException e) { throw new ComponentLookupException("Failed to lookup component role [" + role + "] for hint [" + roleHint + "]", e); } return result; }
/** * {@inheritDoc} * * @see org.xwiki.component.manager.ComponentManager#lookupMap(Class) */ @SuppressWarnings("unchecked") public <T> Map<String, T> lookupMap(Class<T> role) throws ComponentLookupException { Map<String, T> result; try { result = this.plexusContainer.lookupMap(role.getName()); } catch (org.codehaus.plexus.component.repository.exception.ComponentLookupException e) { throw new ComponentLookupException("Failed to lookup components for role [" + role + "]", e); } return result; }
/** * {@inheritDoc} * * @see org.xwiki.component.manager.ComponentManager#lookupList(Class) */ @SuppressWarnings("unchecked") public <T> List<T> lookupList(Class<T> role) throws ComponentLookupException { List<T> result; try { result = this.plexusContainer.lookupList(role.getName()); } catch (org.codehaus.plexus.component.repository.exception.ComponentLookupException e) { throw new ComponentLookupException("Failed to lookup components for role [" + role + "]", e); } return result; }
@Override @SuppressWarnings("unchecked") public <T> Map<String, T> getInstanceMap(Type roleType) throws ComponentLookupException { Map<String, T> components = new HashMap<>(); Map<String, ComponentEntry<?>> entries = this.componentEntries.get(roleType); // Add local components if (entries != null) { for (Map.Entry<String, ComponentEntry<?>> entry : entries.entrySet()) { try { components.put(entry.getKey(), getComponentInstance((ComponentEntry<T>) entry.getValue())); } catch (Exception e) { throw new ComponentLookupException( "Failed to lookup component with type [" + roleType + "] and hint [" + entry.getKey() + "]", e); } } } // Add parent components if (getParent() != null) { // If the hint already exists in the children Component Manager then don't add the one from the parent. for (Map.Entry<String, T> entry : getParent().<T>getInstanceMap(roleType).entrySet()) { if (!components.containsKey(entry.getKey())) { components.put(entry.getKey(), entry.getValue()); } } } return components; }
@Override public <T> T getInstance(Type roleType, String roleHint) throws ComponentLookupException { T instance; ComponentEntry<T> componentEntry = (ComponentEntry<T>) getComponentEntry(roleType, roleHint); if (componentEntry != null) { try { instance = getComponentInstance(componentEntry); } catch (Throwable e) { throw new ComponentLookupException( String.format("Failed to lookup component [%s] identified by type [%s] and hint [%s]", componentEntry.descriptor.getImplementation().getName(), roleType, roleHint), e); } } else { if (getParent() != null) { instance = getParent().getInstance(roleType, roleHint); } else { throw new ComponentLookupException( "Can't find descriptor for the component with type [" + roleType + "] and hint [" + roleHint + "]"); } } return instance; }