Search in sources :

Example 1 with ContainerException

use of org.exoplatform.container.spi.ContainerException in project kernel by exoplatform.

the class ConcurrentContainer method getComponentAdapterOfType.

public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration) {
    // See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115
    ComponentAdapter<T> adapterByKey = (ComponentAdapter<T>) getComponentAdapter(componentType, componentType, autoRegistration);
    if (adapterByKey != null) {
        return adapterByKey;
    }
    List<ComponentAdapter<T>> found = getComponentAdaptersOfType(componentType);
    if (found.size() == 1) {
        return found.get(0);
    } else if (found.size() == 0) {
        if (parent != null) {
            return parent.getComponentAdapterOfType(componentType, autoRegistration);
        } else {
            return null;
        }
    } else {
        Class<?>[] foundClasses = new Class<?>[found.size()];
        for (int i = 0; i < foundClasses.length; i++) {
            ComponentAdapter<T> componentAdapter = found.get(i);
            foundClasses[i] = componentAdapter.getComponentImplementation();
        }
        throw new ContainerException("Several ComponentAdapter found for " + componentType);
    }
}
Also used : ContainerException(org.exoplatform.container.spi.ContainerException) ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter)

Aggregations

ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)1 ContainerException (org.exoplatform.container.spi.ContainerException)1